Last active
April 24, 2019 09:00
-
-
Save ellehallal/c923296b20f6511f3c0bbd61563ac23c to your computer and use it in GitHub Desktop.
This file contains 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
class Minimax | |
def choose_move(board, current_player, opponent) | |
copy_board = board.copy_board | |
find_best_move(copy_board, current_player, opponent) | |
end | |
private | |
def find_best_move(board, depth=0, current_player, opponent) | |
best_score = {} | |
available_squares = board.available_squares | |
return score_move(board, depth, current_player, opponent) if | |
board.stop_playing?(current_player, opponent) | |
available_squares.each do |square| | |
board.player_make_move(current_player, square) | |
best_score[square] = | |
-1 * find_best_move(board, depth + 1, opponent, current_player) | |
board.reset_square(square) | |
end | |
evaluate_move(depth, best_score) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment