Last active
March 5, 2020 19:38
-
-
Save obakanue/24a6d3f678087c8416d04a1744540daf to your computer and use it in GitHub Desktop.
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
def min_max(board, depth, maximizingPlayer): | |
validMoves = get_valid_moves(board) | |
bestMove = [-1,-1] | |
if depth == 0 or validMoves == []: | |
return evaluate_score(board) | |
# no indent here | |
if maximizingPlayer: | |
maxEval = -sys.maxsize | |
for move in validMoves: | |
child = get_board_copy(board) | |
make_move(child, computerTile, move[0], move[1]) | |
eval_, _ = min_max(child, depth-1, False) | |
temp = max(maxEval, eval_) | |
if temp == eval_: bestMove = move | |
maxEval = temp | |
return maxEval, bestMove | |
else: | |
minEval = +sys.maxsize | |
for move in validMoves: | |
child = get_board_copy(board) | |
make_move(child, computerTile, move[0], move[1]) | |
eval_, _ = min_max(child, depth - 1, True) | |
temp = min(minEval, eval_) | |
if temp == eval_: bestMove = move | |
minEval = temp | |
return minEval, bestMove |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment