This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| class Board | |
| LIVE = "X" | |
| DEAD = "O" | |
| attr_reader :board | |
| def initialize(board_array) | |
| @board = parse_in(board_array) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| #Need something like spots/adjacency | |
| class Board | |
| attr_reader :cell_count | |
| def initialize | |
| @cells = [] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert(actual, expected) | |
| if actual == expected | |
| puts "#{actual.inspect} equals #{expected.inspect}" | |
| else | |
| raise "Expected #{actual.inspect} to equal #{expected.inspect}" | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert(actual, expected) | |
| if actual == expected | |
| puts "#{actual.inspect} equals #{expected.inspect}" | |
| else | |
| raise "Expected #{actual.inspect} to equal #{expected.inspect}" | |
| end | |
| end | |
| LIVE = 'X' | |
| DEAD = 'O' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert(actual, expected) | |
| if actual == expected | |
| puts "#{actual.inspect} equals #{expected.inspect}" | |
| else | |
| raise "Expected #{actual.inspect} to equal #{expected.inspect}" | |
| end | |
| end | |
| LIVE = 'X' | |
| DEAD = 'O' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert(actual, expected) | |
| raise "Expected #{actual.inspect} to equal #{expected.inspect}" unless actual == expected | |
| end | |
| LIVE = 'X' | |
| DEAD = 'O' | |
| def evolve(board) | |
| board.map.with_index do |row, x| | |
| row.map.with_index do |p, y| | |
| if p == LIVE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get '/' do | |
| erb :index | |
| end | |
| get '/offense_board' do | |
| build_offense_board | |
| end | |
| get '/defense_board' do | |
| build_defense_board |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get '/' do | |
| erb :index | |
| end | |
| get '/offense_board' do | |
| build_offense_board | |
| end | |
| get '/defense_board' do | |
| build_defense_board |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| helpers do | |
| def parse_shot(shot) | |
| if shot.at_already_shot_coordinate? | |
| {success: false, reason: "already shot there"} | |
| else | |
| {success: true, result: { | |
| coordinate: shot.coordinate, | |
| hit: shot.result.hit?, | |
| sunk: shot.result.sunk_ship?, | |
| name: ship.result.sunk_ship_name |
