Skip to content

Commit d2f9131

Browse files
committed
fix: missing import for doctest and rename create_game_board to create_empty_game_board
1 parent 604ed6f commit d2f9131

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/mastermind/core/models/game.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_new_game(game_configuration: GameConfiguration) -> Game:
4848
>>> isinstance(game.game_entities, GameEntities)
4949
True
5050
>>> game.game_state
51-
GameState(game_started=False, game_over=False, winner=None)
51+
GameState(game_started=False, winner=None)
5252
"""
5353

5454
return Game(

src/mastermind/core/models/gameboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create_empty_game_board() -> GameBoard:
7575
GameBoard: A new empty game board.
7676
7777
Examples:
78-
>>> game_board = create_game_board()
78+
>>> game_board = create_empty_game_board()
7979
>>> len(game_board)
8080
0
8181
>>> game_board.game_rounds

src/mastermind/core/services/game_service.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ def add_round(self, guess: tuple[int, ...], feedback: tuple[int, int]) -> None:
3636
feedback (tuple[int, int]): A tuple containing the number of correct and misplaced pegs.
3737
3838
Examples:
39+
>>> from mastermind.core.models.game import create_new_game
40+
>>> from mastermind.core.models.game_configuration import GameConfiguration
41+
>>> from mastermind.core.models.game_mode import GameMode
3942
>>> game = create_new_game(GameConfiguration(NUMBER_OF_COLORS=3, NUMBER_OF_DOTS=4, ATTEMPTS_ALLOWED=5, GAME_MODE=GameMode.PVP))
4043
>>> service = GameService(game)
4144
>>> service.add_round((1, 2, 3, 4), (1, 0))
42-
>>> service.game_rounds
43-
[GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))]
45+
>>> game.game_board.game_rounds
46+
deque([GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))])
4447
4548
Raises:
4649
GameEndedException: When trying to add a round to a game that has ended.
@@ -62,14 +65,17 @@ def undo(self) -> None:
6265
"""Undo the most recent game round.
6366
6467
Examples:
68+
>>> from mastermind.core.models.game import create_new_game
69+
>>> from mastermind.core.models.game_configuration import GameConfiguration
70+
>>> from mastermind.core.models.game_mode import GameMode
6571
>>> game = create_new_game(GameConfiguration(NUMBER_OF_COLORS=3, NUMBER_OF_DOTS=4, ATTEMPTS_ALLOWED=5, GAME_MODE=GameMode.PVP))
6672
>>> service = GameService(game)
6773
>>> service.add_round((1, 2, 3, 4), (1, 0))
6874
>>> game.game_board.game_rounds
69-
[GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))]
75+
deque([GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))])
7076
>>> service.undo()
7177
>>> game.game_board.game_rounds
72-
[]
78+
deque([])
7379
7480
Raises:
7581
GameNotStartedException: When trying to undo game rounds before the game has started.
@@ -81,7 +87,7 @@ def undo(self) -> None:
8187
"Cannot undo game rounds before game has started."
8288
)
8389

84-
if not self._game_state.game_over:
90+
if self._game_state.game_over:
8591
raise GameEndedException("Cannot undo game rounds after game has ended.")
8692

8793
self._gameboard_service.undo()
@@ -90,13 +96,16 @@ def redo(self) -> None:
9096
"""Restores the most recently undone game round.
9197
9298
Examples:
99+
>>> from mastermind.core.models.game import create_new_game
100+
>>> from mastermind.core.models.game_configuration import GameConfiguration
101+
>>> from mastermind.core.models.game_mode import GameMode
93102
>>> game = create_new_game(GameConfiguration(NUMBER_OF_COLORS=3, NUMBER_OF_DOTS=4, ATTEMPTS_ALLOWED=5, GAME_MODE=GameMode.PVP))
94103
>>> service = GameService(game)
95104
>>> service.add_round((1, 2, 3, 4), (1, 0))
96105
>>> service.undo()
97106
>>> service.redo()
98-
>>> service.game_rounds
99-
[GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))]
107+
>>> game.game_board.game_rounds
108+
deque([GameRound(GUESS=(1, 2, 3, 4), FEEDBACK=(1, 0))])
100109
101110
Raises:
102111
GameNotStartedException: When trying to redo game rounds before the game has started.

0 commit comments

Comments
 (0)