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.
main
Bram van den Heuvel 2026-06-07 10:53:45 +02:00
parent add05bc761
commit 4b072e7a29
2 changed files with 12 additions and 1 deletions

View File

@ -60,7 +60,7 @@ class PyClient:
agent = agents[player-1] agent = agents[player-1]
payload = agent.poll( payload = agent.poll(
game=current_state.action_name(), game=current_state.action_name(),
payload=current_state.to_dict(), payload=current_state.as_seen_by(player),
timeout=timeout, timeout=timeout,
) )

View File

@ -171,6 +171,17 @@ class TicTacToe:
def action_name(self): def action_name(self):
return "/tic-tac-toe" 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: def count_o(self) -> int:
""" """