|
5 | 5 | from typing import Collection, Iterator |
6 | 6 |
|
7 | 7 | from codenames.classic.board import ClassicBoard |
8 | | -from codenames.classic.color import ClassicColor, ClassicTeam |
9 | | -from codenames.classic.score import Score, TeamScore |
| 8 | +from codenames.classic.color import ClassicTeam |
10 | 9 | from codenames.classic.state import ClassicGameState |
11 | 10 | from codenames.classic.winner import Winner |
12 | 11 | from codenames.generic.exceptions import InvalidGuess |
|
19 | 18 | TeamPlayers, |
20 | 19 | ) |
21 | 20 | from codenames.utils.formatting import wrap |
22 | | -from codenames.utils.vocabulary.languages import get_vocabulary |
23 | 21 |
|
24 | 22 | log = logging.getLogger(__name__) |
25 | 23 |
|
@@ -64,9 +62,11 @@ def __init__( |
64 | 62 | self, players: ClassicGamePlayers, state: ClassicGameState | None = None, board: ClassicBoard | None = None |
65 | 63 | ): |
66 | 64 | self.players = players |
67 | | - if (not state and not board) or (state and board): |
68 | | - raise ValueError("Exactly one of state or board must be provided.") |
69 | | - self.state = state or new_game_state(board=board) |
| 65 | + if not state: |
| 66 | + if not board: |
| 67 | + raise ValueError("Exactly one of state or board must be provided.") |
| 68 | + state = ClassicGameState.from_board(board=board) |
| 69 | + self.state = state |
70 | 70 | self.clue_given_subscribers: list[ClueGivenSubscriber] = [] |
71 | 71 | self.guess_given_subscribers: list[GuessGivenSubscriber] = [] |
72 | 72 |
|
@@ -144,42 +144,6 @@ def _get_guess_until_valid(self, operative: Operative) -> GivenGuess | None: |
144 | 144 | pass |
145 | 145 |
|
146 | 146 |
|
147 | | -def new_game_state(board: ClassicBoard | None = None, language: str | None = None) -> ClassicGameState: |
148 | | - board = _get_board(board=board, language=language) |
149 | | - if not board.is_clean: |
150 | | - raise ValueError("Board must be clean.") |
151 | | - first_team = _determine_first_team(board) |
152 | | - score = build_score(board) |
153 | | - return ClassicGameState( |
154 | | - board=board, |
155 | | - score=score, |
156 | | - current_team=first_team, |
157 | | - current_player_role=PlayerRole.SPYMASTER, |
158 | | - ) |
159 | | - |
160 | | - |
161 | | -def _get_board(board: ClassicBoard | None, language: str | None) -> ClassicBoard: |
162 | | - if board is not None: |
163 | | - return board |
164 | | - if language is None: |
165 | | - raise ValueError("Either board or language must be provided.") |
166 | | - vocabulary = get_vocabulary(language=language) |
167 | | - return ClassicBoard.from_vocabulary(vocabulary=vocabulary) |
168 | | - |
169 | | - |
170 | | -def build_score(board: ClassicBoard) -> Score: |
171 | | - blue_score = TeamScore(total=len(board.blue_cards), revealed=len(board.revealed_cards_for_color(ClassicColor.BLUE))) |
172 | | - red_score = TeamScore(total=len(board.red_cards), revealed=len(board.revealed_cards_for_color(ClassicColor.RED))) |
173 | | - score = Score(blue=blue_score, red=red_score) |
174 | | - return score |
175 | | - |
176 | | - |
177 | | -def _determine_first_team(board: ClassicBoard) -> ClassicTeam: |
178 | | - if len(board.blue_cards) >= len(board.red_cards): |
179 | | - return ClassicTeam.BLUE |
180 | | - return ClassicTeam.RED |
181 | | - |
182 | | - |
183 | 147 | def find_team(players: Collection[Player], team: ClassicTeam) -> TeamPlayers: |
184 | 148 | spymaster = operative = None |
185 | 149 | for player in players: |
|
0 commit comments