1919
2020# Find the best possible outcome for original player
2121def minimax (board : Board , maximizing : bool , original_player : Piece , max_depth : int = 8 ) -> float :
22- # Base case - evaluate the position if it is a win or a draw
22+ # Base case – terminal position or maximum depth reached
2323 if board .is_win or board .is_draw or max_depth == 0 :
2424 return board .evaluate (original_player )
2525
@@ -28,18 +28,18 @@ def minimax(board: Board, maximizing: bool, original_player: Piece, max_depth: i
2828 best_eval : float = float ("-inf" ) # arbitrarily low starting point
2929 for move in board .legal_moves :
3030 result : float = minimax (board .move (move ), False , original_player , max_depth - 1 )
31- best_eval = max (result , best_eval )
31+ best_eval = max (result , best_eval )# we want the move with the highest evaluation
3232 return best_eval
3333 else : # minimizing
3434 worst_eval : float = float ("inf" )
3535 for move in board .legal_moves :
3636 result = minimax (board .move (move ), True , original_player , max_depth - 1 )
37- worst_eval = min (result , worst_eval )
37+ worst_eval = min (result , worst_eval )# we want the move with the lowest evaluation
3838 return worst_eval
3939
4040
4141def alphabeta (board : Board , maximizing : bool , original_player : Piece , max_depth : int = 8 , alpha : float = float ("-inf" ), beta : float = float ("inf" )) -> float :
42- # Base case - evaluate the position if it is a win or a draw
42+ # Base case – terminal position or maximum depth reached
4343 if board .is_win or board .is_draw or max_depth == 0 :
4444 return board .evaluate (original_player )
4545
0 commit comments