From 4b072e7a296d07adac695b4c6a73eb88f8885acb Mon Sep 17 00:00:00 2001 From: Bram van den Heuvel Date: Sun, 7 Jun 2026 10:53:45 +0200 Subject: [PATCH] Add perspective to PyClient Instead of giving players the exact same perspective, the PyClient can now give personal information to each server. For example, they can now specify which player they are. Previously, a server had to guess whether it was placing X's or O's. --- pyclient/__init__.py | 2 +- pyclient/games/tic_tac_toe.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pyclient/__init__.py b/pyclient/__init__.py index b80fe32..0bed8f7 100644 --- a/pyclient/__init__.py +++ b/pyclient/__init__.py @@ -60,7 +60,7 @@ class PyClient: agent = agents[player-1] payload = agent.poll( game=current_state.action_name(), - payload=current_state.to_dict(), + payload=current_state.as_seen_by(player), timeout=timeout, ) diff --git a/pyclient/games/tic_tac_toe.py b/pyclient/games/tic_tac_toe.py index 8e109ae..a720287 100644 --- a/pyclient/games/tic_tac_toe.py +++ b/pyclient/games/tic_tac_toe.py @@ -171,6 +171,17 @@ class TicTacToe: def action_name(self): return "/tic-tac-toe" + + def as_seen_by(self, player : int) -> Dict[str, Any]: + """ + Return the view of the game from the perspective of a given player. + + :param player: The perspective on the board. + :type player: int + """ + out = self.to_dict() + out["your_token"] = str(Field.X) if player == 1 else str(Field.O) + return out def count_o(self) -> int: """