Created
October 14, 2017 20:32
-
-
Save craine/0807851ef1a1de08411a7fae8aec7d4c to your computer and use it in GitHub Desktop.
Minimax and Alpha get moves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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