Skip to content

Commit cc3d988

Browse files
committed
Print out how many turns it took to win or lose
1 parent 6144522 commit cc3d988

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

computer_players/machine_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RemoteState(Component, metaclass=ABCMeta):
3535
turn.
3636
"""
3737

38-
__slots__ = ("state", "pieces", "has_initial", "playing_as")
38+
__slots__ = ("state", "pieces", "has_initial", "playing_as", "moves")
3939

4040
def __init__(self) -> None:
4141
"""Initialize remote state."""
@@ -46,6 +46,7 @@ def __init__(self) -> None:
4646
self.pieces: dict[Pos, int] = {}
4747

4848
self.playing_as = 1
49+
self.moves = 0
4950

5051
def bind_handlers(self) -> None:
5152
"""Register game event handlers."""
@@ -78,8 +79,12 @@ async def preform_turn(self) -> Action:
7879

7980
async def base_preform_turn(self) -> None:
8081
"""Perform turn."""
81-
if self.state.check_for_win() is not None:
82+
self.moves += 1
83+
winner = self.state.check_for_win()
84+
if winner is not None:
8285
print("Terminal state, not performing turn")
86+
value = ("Lost", "Won")[winner == self.playing_as]
87+
print(f"{value} after {self.moves}")
8388
return
8489
action = await self.preform_turn()
8590
await self.preform_action(action)

0 commit comments

Comments
 (0)