Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. def alphabeta(game_state):
  2. """
  3. Find the best move for our AI agent by applying the minimax algorithm
  4. with alpha beta pruning.
  5. :param game_state: GameState object
  6. :return: a tuple representing the row column of the best move
  7. """
  8.  
  9. moves = game_state.possible_moves()
  10. best_successor = game_state.successor(moves[0], 'AI')
  11. best_value = abvalue(best_successor, 'user', -sys.maxsize, sys.maxsize)
  12. for i in range(1, len(moves)):
  13. successor = game_state.successor(moves[i], 'AI')
  14. val = abvalue(successor, 'user', -sys.maxsize, sys.maxsize)
  15. if val>best_value:
  16. best_successor = successor
  17. best_value = val
  18. return best_successor.last_move
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement