Created
March 5, 2020 19:30
-
-
Save obakanue/429109f4497c686f3341252fbc994993 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) | |
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