Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def optimal_move(board)
- # Needs to return a space that will return an optimal move using minimax
- player = current_player(board)
- possible_moves = open_squares(board)
- best_move = nil
- best_score = nil
- possible_moves.each do |square_num|
- new_board = board.slice(0..-1)
- new_board[square_num - 1] = player
- score = minimax(new_board)
- if best_score.nil? || score > best_score
- best_score = score
- best_move = square_num
- end
- end
- best_move
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement