Skip to content

Instantly share code, notes, and snippets.

@craine
Created October 14, 2017 20:32
Show Gist options
  • Save craine/0807851ef1a1de08411a7fae8aec7d4c to your computer and use it in GitHub Desktop.
Save craine/0807851ef1a1de08411a7fae8aec7d4c to your computer and use it in GitHub Desktop.
Minimax and Alpha get moves
'''MINIMAX GET MOVES:'''
self.time_left = time_left
# Initialize the best move so that this function returns something
# in case the search fails due to timeout
'''best_move = (1, 1)'''
legal_moves = game.get_legal_moves()
if legal_moves == []:
return 1, 1
else:
best_move = legal_moves[0]
try:
# The try/except block will automatically catch the exception
# raised when the timer is about to expire.
return self.minimax(game, self.search_depth)
except SearchTimeout:
pass # Handle any actions required after timeout as needed
# Return the best move from the last completed search iteration
return best_move
'''ALPHABETA GET MOVES:'''
self.time_left = time_left
'''legal_moves = game.get_legal_moves()'''
best_move = 1, 1
try:
for depth in range(1, 200):
best_move = self.alphabeta(game, depth)
except SearchTimeout:
pass
# Return the best move from the last completed search iteration
return best_move
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment