Skip to content

Commit

Permalink
Add additional logging #33
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorbayless committed Nov 29, 2024
1 parent 0051ccb commit b5aef9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/cli_chess/core/game/offline_game/offline_game_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ def _report_game_over(self) -> None:
self.game_metadata.game_status.winner = COLOR_NAMES[outcome.winner]

log.info(f"Game over (status={outcome.termination} winner={COLOR_NAMES[outcome.winner]})")
log.debug(f"Ending fen: {self.board_model.board.fen()}")
log.debug(f"Final move stack: {self.board_model.get_move_stack(as_string=True)}")

self._notify_game_model_updated(EventTopics.GAME_END)
14 changes: 12 additions & 2 deletions src/cli_chess/modules/board/board_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from cli_chess.utils.event import EventManager, EventTopics
from cli_chess.utils.logging import log
import chess
Expand Down Expand Up @@ -155,6 +157,8 @@ def takeback(self, caller_color: chess.Color):
self.board.pop()

self.highlight_move = self.board.peek() if len(self.board.move_stack) > 0 else chess.Move.null()

log.debug(f"Takeback issued. New fen: {self.board.fen()}")
self._notify_board_model_updated(EventTopics.MOVE_MADE)

except Exception as e:
Expand All @@ -164,9 +168,15 @@ def takeback(self, caller_color: chess.Color):
log.error(e)
raise

def get_move_stack(self) -> List[chess.Move]:
def get_move_stack(self, as_string: bool = False) -> List[chess.Move] | str:
"""Returns the boards move stack"""
return self.board.move_stack
if as_string:
moves = ""
for move in self.board.move_stack:
moves += f"{move.uci()} "
return moves.strip()
else:
return self.board.move_stack

def get_variant_name(self) -> str:
"""Returns a string holding the board variant name"""
Expand Down
2 changes: 2 additions & 0 deletions src/cli_chess/tests/modules/board/test_board_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def test_get_move_stack(model: BoardModel):
model.takeback(chess.WHITE)
assert model.get_move_stack() == model.board.move_stack

assert model.get_move_stack(as_string=True) == "e2e4 d7d6 d2d4 g8f6"


def test_get_variant_name():
# Test chess960
Expand Down

0 comments on commit b5aef9b

Please sign in to comment.