Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e67a169

Browse files
committed
Minor style fixes
1 parent 68d84a8 commit e67a169

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

‎Chapter8/board.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
class Piece:
2424
@property
25-
@abstractmethod
2625
def opposite(self) -> Piece:
27-
...
26+
raiseNotImplementedError("Should be implemented by subclasses.")
2827

2928

3029
class Board(ABC):

‎Chapter8/connectfour.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def copy(self) -> C4Board.Column:
102102
temp._container = self._container.copy()
103103
return temp
104104

105-
106105
def __init__(self, position: Optional[List[C4Board.Column]] = None, turn: C4Piece = C4Piece.B) -> None:
107106
if position is None:
108107
self.position: List[C4Board.Column] = [C4Board.Column() for _ in range(C4Board.NUM_COLUMNS)]

‎Chapter8/minimax.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# Find the best possible outcome for original player
2121
def 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

4141
def 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /