Skip to content

Commit

Permalink
add alpha-beta pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
whlapinel committed Oct 4, 2024
1 parent 9f37a37 commit 85540ab
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cpu_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, board: IBoard, player_no: int, opponent: int) -> None:
self.__player_no = player_no
self.__opponent = opponent
self.__curr_player = player_no
self.depth = 1
self.depth = 3
self.players = [self.__opponent, self.__player_no]
self._recurse_count = 0
self._total_nodes_explored = 0
Expand Down Expand Up @@ -105,19 +105,19 @@ def minimax(
for child in children:
eval = self.minimax(child, depth - 1, False, alpha, beta)
max_eval = max(max_eval, eval)
# alpha = max(alpha, eval)
# if beta <= alpha:
# break # Beta cut-off
alpha = max(alpha, eval)
if beta <= alpha:
break # Beta cut-off
return max_eval
else:
min_eval = math.inf
children = game_state.generate_children()
for child in children:
eval = self.minimax(child, depth - 1, True, alpha, beta)
min_eval = min(min_eval, eval)
# beta = min(beta, eval)
# if beta <= alpha:
# break # Alpha cut-off
beta = min(beta, eval)
if beta <= alpha:
break # Alpha cut-off
return min_eval

def evaluate_board(self, board: IBoard) -> float:
Expand Down

0 comments on commit 85540ab

Please sign in to comment.