Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def alphabeta(game_state):
- """
- Find the best move for our AI agent by applying the minimax algorithm
- with alpha beta pruning.
- :param game_state: GameState object
- :return: a tuple representing the row column of the best move
- """
- moves = game_state.possible_moves()
- best_successor = game_state.successor(moves[0], 'AI')
- best_value = abvalue(best_successor, 'user', -sys.maxsize, sys.maxsize)
- for i in range(1, len(moves)):
- successor = game_state.successor(moves[i], 'AI')
- val = abvalue(successor, 'user', -sys.maxsize, sys.maxsize)
- if val>best_value:
- best_successor = successor
- best_value = val
- return best_successor.last_move
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement