Skip to content
Snippets Groups Projects

Resolve "Too large number of selected players does not break the gui and environment"

4 files
+ 55
43
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -21,7 +21,11 @@ from websockets.sync.client import connect
@@ -21,7 +21,11 @@ from websockets.sync.client import connect
from cooperative_cuisine import ROOT_DIR
from cooperative_cuisine import ROOT_DIR
from cooperative_cuisine.action import ActionType, InterActionData, Action
from cooperative_cuisine.action import ActionType, InterActionData, Action
from cooperative_cuisine.game_server import CreateEnvironmentConfig
from cooperative_cuisine.game_server import (
 
CreateEnvironmentConfig,
 
WebsocketMessage,
 
PlayerRequestType,
 
)
from cooperative_cuisine.pygame_2d_vis.drawing import Visualizer
from cooperative_cuisine.pygame_2d_vis.drawing import Visualizer
from cooperative_cuisine.pygame_2d_vis.game_colors import colors
from cooperative_cuisine.pygame_2d_vis.game_colors import colors
from cooperative_cuisine.state_representation import StateRepresentation
from cooperative_cuisine.state_representation import StateRepresentation
@@ -1366,12 +1370,11 @@ class PyGameGUI:
@@ -1366,12 +1370,11 @@ class PyGameGUI:
if p < self.number_humans_to_be_added:
if p < self.number_humans_to_be_added:
# add player websockets
# add player websockets
websocket = connect(self.websocket_url + player_info["client_id"])
websocket = connect(self.websocket_url + player_info["client_id"])
ws_message = WebsocketMessage(
websocket.send(
type=PlayerRequestType.READY.value,
json.dumps(
player_hash=player_info["player_hash"],
{"type": "ready", "player_hash": player_info["player_hash"]}
)
)
)
 
websocket.send(json.dumps(ws_message))
assert (
assert (
json.loads(websocket.recv())["status"] == 200
json.loads(websocket.recv())["status"] == 200
), "not accepted player"
), "not accepted player"
@@ -1486,30 +1489,20 @@ class PyGameGUI:
@@ -1486,30 +1489,20 @@ class PyGameGUI:
float(action.action_data[1]),
float(action.action_data[1]),
]
]
self.websockets[action.player].send(
ws_message = WebsocketMessage(
json.dumps(
type=PlayerRequestType.ACTION.value,
{
action=dataclasses.asdict(action, dict_factory=custom_asdict_factory),
"type": "action",
player_hash=self.player_info[action.player]["player_hash"],
"action": dataclasses.asdict(
action, dict_factory=custom_asdict_factory
),
"player_hash": self.player_info[action.player]["player_hash"],
}
)
)
)
 
self.websockets[action.player].send(json.dumps(ws_message))
self.websockets[action.player].recv()
self.websockets[action.player].recv()
def request_state(self):
def request_state(self):
self.websockets[self.state_player_id].send(
ws_message = WebsocketMessage(
json.dumps(
type=PlayerRequestType.GET_STATE.value,
{
player_hash=self.player_info[self.state_player_id]["player_hash"],
"type": "get_state",
"player_hash": self.player_info[self.state_player_id][
"player_hash"
],
}
)
)
)
 
self.websockets[self.state_player_id].send(json.dumps(ws_message))
state = json.loads(self.websockets[self.state_player_id].recv())
state = json.loads(self.websockets[self.state_player_id].recv())
return state
return state
Loading