Skip to content

Instantly share code, notes, and snippets.

@obakanue
Created March 5, 2020 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obakanue/429109f4497c686f3341252fbc994993 to your computer and use it in GitHub Desktop.
Save obakanue/429109f4497c686f3341252fbc994993 to your computer and use it in GitHub Desktop.
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