Skip to content

Commit

Permalink
fix appropriate_player tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDCarroll committed Jul 5, 2017
1 parent 4a97691 commit 460a763
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions lib/ai/minimax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ def optimum_choice(spaces = @spaces, depth = @depth, choices = {})

@board.available_spaces.each { |space| choices = space }
choices

end

def available_spaces
@board.available_spaces
end

def appropriate_player
@depth.odd? ? @const.players[1] : @const.players[0]
@depth.odd? ? @const.players[0] : @const.players[1]
end
end
10 changes: 4 additions & 6 deletions spec/ai/minimax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@
context 'when depth is at the root level' do
Given(:const) { GameConstants.new }
Given(:minimax) { Minimax.new(Board.new) }
When { minimax.depth += 1 }
Then { const.players[1] = minimax.appropriate_player }
Then { const.players[1] == minimax.appropriate_player }
end

context 'when recurstion_depth is an even number' do
context 'when depth is an odd number' do
Given(:const) { GameConstants.new }
Given(:minimax) { Minimax.new(Board.new) }
When { minimax.depth += 1
minimax.depth += 1 }
Then { const.players[0] = minimax.appropriate_player }
When { minimax.depth += 1 }
Then { const.players[0] == minimax.appropriate_player }
end
end

Expand Down

0 comments on commit 460a763

Please sign in to comment.