lib/games/tictactoe/minimax.rb in games_bfox-0.4.0 vs lib/games/tictactoe/minimax.rb in games_bfox-0.6.0
- old
+ new
@@ -19,10 +19,11 @@
board_full = board.full?
if board_won || board_full
#rewind one player to see which player took last turn and therefore won the game
self.number_of_turns_taken -= 1
+ # note: need return statement here so that method stops here if board is won or full
return score(board_won)
end
# @logger.debug "avaliable choices collection: #{available_choices}"
@@ -36,15 +37,15 @@
if computer_current_player?
#https://stackoverflow.com/questions/2149802/in-ruby-what-is-the-cleanest-way-of-obtaining-the-index-of-the-largest-value-in
max_score_index = scores.each_with_index.max[1]
self.choice = choices[max_score_index]
- return scores[max_score_index]
+ scores[max_score_index]
else
# This is the min calculation
min_score_index = scores.each_with_index.min[1]
self.choice = choices[min_score_index]
- return scores[min_score_index]
+ scores[min_score_index]
end
end
private