Skip to content

Commit a0d726d

Browse files
committed
ref(Game): remove number_of_unfilled_cells
1 parent cd76b0f commit a0d726d

File tree

2 files changed

+1
-19
lines changed
  • src/ttt

2 files changed

+1
-19
lines changed

src/ttt/entities/core/game/game.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ class OnlyAiGameError(Exception): ...
8383
class NotAiCurrentMoveError(Exception): ...
8484

8585

86-
def number_of_unfilled_cells(board: Matrix[Cell]) -> int:
87-
return sum(int(not cell.is_filled()) for cell in chain.from_iterable(board))
88-
89-
9086
@dataclass
9187
class Game:
9288
"""
@@ -104,7 +100,6 @@ class Game:
104100
player2: Player
105101
player2_emoji: Emoji
106102
board: Board
107-
number_of_unfilled_cells: int
108103
result: GameResult | None
109104
state: GameState
110105

@@ -127,12 +122,6 @@ def __post_init__(self) -> None:
127122
)
128123
assert_(is_cell_order_ok, else_=InvalidCellOrderError)
129124

130-
board = self.board
131-
assert_(
132-
number_of_unfilled_cells(board) == self.number_of_unfilled_cells,
133-
else_=InvalidNumberOfUnfilledCellsError,
134-
)
135-
136125
def is_against_ai(self) -> bool:
137126
return isinstance(self.player1, Ai) or isinstance(self.player2, Ai)
138127

@@ -215,7 +204,6 @@ def make_user_move( # noqa: C901
215204
raise NoCellError from error
216205

217206
cell.fill_as_user(user_id, tracking)
218-
self.number_of_unfilled_cells -= 1
219207
tracking.register_mutated(self)
220208

221209
if self._is_player_winner(current_player, cell.board_position):
@@ -339,7 +327,6 @@ def make_ai_move(
339327
tracking,
340328
)
341329

342-
self.number_of_unfilled_cells -= 1
343330
tracking.register_mutated(self)
344331

345332
if self._is_player_winner(current_player, cell_position):
@@ -392,7 +379,6 @@ def _make_random_ai_move(
392379
) -> AiMove:
393380
cell = choice(self._free_cells(), random=free_cell_random)
394381
cell.fill_as_ai(current_player.id, tracking)
395-
self.number_of_unfilled_cells -= 1
396382
tracking.register_mutated(self)
397383

398384
if self._is_player_winner(current_player, cell.board_position):
@@ -419,7 +405,7 @@ def _can_continue(self) -> bool:
419405
return not self._is_board_filled()
420406

421407
def _is_board_filled(self) -> bool:
422-
return self.number_of_unfilled_cells <= 0
408+
return all(cell.is_filled() for cell in chain.from_iterable(self.board))
423409

424410
def _is_player_winner(self, player: Player, cell_position: Vector) -> bool:
425411
cell_x, cell_y = cell_position
@@ -545,7 +531,6 @@ def start_game( # noqa: PLR0913, PLR0917
545531
player2,
546532
player2_emoji,
547533
board,
548-
number_of_unfilled_cells(board),
549534
None,
550535
GameState.wait_player1,
551536
)
@@ -622,7 +607,6 @@ def start_game_with_ai( # noqa: PLR0913, PLR0917
622607
player2,
623608
player2_emoji,
624609
board,
625-
number_of_unfilled_cells(board),
626610
None,
627611
GameState.wait_player1,
628612
)

src/ttt/infrastructure/sqlalchemy/tables/game.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Game,
1616
GameAtomic,
1717
GameState,
18-
number_of_unfilled_cells,
1918
)
2019
from ttt.entities.core.game.game_result import (
2120
CancelledGameResult,
@@ -284,7 +283,6 @@ def __entity__(self) -> Game:
284283
self._player2(),
285284
Emoji(self.player2_emoji_str),
286285
board,
287-
number_of_unfilled_cells(board),
288286
self._result(),
289287
self.state.entity(),
290288
)

0 commit comments

Comments
 (0)