From fdc1e441051989bf9fe21abea1cc7f8817271802 Mon Sep 17 00:00:00 2001 From: Juraj Paluba Date: Mon, 21 Oct 2024 20:50:49 +0200 Subject: [PATCH] feat(generalsio): read agent index Will be usefull with map generation as player indexes are used to mark who ones given tile. --- generals/remote/generalsio_client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/generals/remote/generalsio_client.py b/generals/remote/generalsio_client.py index 9acca5e..7e195b7 100644 --- a/generals/remote/generalsio_client.py +++ b/generals/remote/generalsio_client.py @@ -79,17 +79,21 @@ def join_game(self, force_start: bool = True) -> None: if force_start: self.emit("set_force_start", (self.queue_id, True)) + agent_index = None while True: - event = self.receive()[0] + event, *data = self.receive() if event == "game_start": + game_data = data[0] + agent_index = game_data["playerIndex"] break - self._start_game() + self._play_game(agent_index) - def _start_game(self) -> None: + def _play_game(self, agent_index: int) -> None: """ Triggered after server starts the game. TODO: spawn a new thread in which Agent will calculate its moves + :param agent_index: The index of agent in the game """ winner = False while True: