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
parent
add05bc761
commit
4b072e7a29
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue