Skip to content

Instantly share code, notes, and snippets.

@craine
Created Oct 14, 2017
Embed
What would you like to do?
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