Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.