Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def optimal_move(board)
  2. # Needs to return a space that will return an optimal move using minimax
  3. player = current_player(board)
  4. possible_moves = open_squares(board)
  5. best_move = nil
  6. best_score = nil
  7. possible_moves.each do |square_num|
  8. new_board = board.slice(0..-1)
  9. new_board[square_num - 1] = player
  10. score = minimax(new_board)
  11. if best_score.nil? || score > best_score
  12. best_score = score
  13. best_move = square_num
  14. end
  15. end
  16. best_move
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement