aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--board.rb4
-rw-r--r--player.rb6
-rw-r--r--spec/board_spec.rb8
-rw-r--r--spec/player_spec.rb14
4 files changed, 29 insertions, 3 deletions
diff --git a/board.rb b/board.rb
index c990218..fe81bba 100644
--- a/board.rb
+++ b/board.rb
@@ -23,4 +23,8 @@ class Board
rescue
end
end
+
+ def update_cell(row_index, column_index, value)
+ @board[row_index][column_index] = value
+ end
end
diff --git a/player.rb b/player.rb
index d19ee36..8146220 100644
--- a/player.rb
+++ b/player.rb
@@ -8,4 +8,10 @@ class Player
@insignia = insignia
@board = board
end
+
+ def move(coordinates)
+ raise ArgumentError if coordinates.nil?
+
+ @board.update_cell(coordinates[0], coordinates[1], @insignia)
+ end
end
diff --git a/spec/board_spec.rb b/spec/board_spec.rb
index 3e04210..a5c45ef 100644
--- a/spec/board_spec.rb
+++ b/spec/board_spec.rb
@@ -36,4 +36,12 @@ EOF
@board.transform_coordinates('booya,kacha').must_be_nil
end
end
+
+ describe '#update_cell' do
+ it 'updates a given cell with a given value' do
+ value = 'X'
+ @board.update_cell(1, 2, value)
+ @board.instance_variable_get(:@board)[1][2].must_equal value
+ end
+ end
end
diff --git a/spec/player_spec.rb b/spec/player_spec.rb
index 4dee7e7..d33ac05 100644
--- a/spec/player_spec.rb
+++ b/spec/player_spec.rb
@@ -15,17 +15,25 @@ describe Player do
describe '#move' do
before do
- board = Board.new
- @player = Player.new(Player::INSIGNIAS[:x], board)
+ @board = Board.new
+ @player = Player.new(Player::INSIGNIAS[:x], @board)
end
- it 'raises an ArgumentError given invalid coordinates' do
+ it 'raises an ArgumentError given nil coordinates' do
+ -> { @player.move(nil) }.must_raise ArgumentError
end
it 'adds a piece to the correct coordinates on `board`' do
+ @player.move([1, 2])
+ @board.instance_variable_get(:@board)[1][2].must_equal \
+ @player.instance_variable_get(:@insignia)
end
it 'uses the correct insignia for the move' do
+ insignia = Player::INSIGNIAS[:o]
+ player = Player.new(insignia, @board)
+ player.move([0, 1])
+ @board.instance_variable_get(:@board)[0][1].must_equal insignia
end
end
end