def test_disconnect(data): sem.acquire() game_id = str(data["game_id"]) player_id = str(data["player_id"]) message = controller.delete_ai(GameInfo(game_id, player_id)) if message != AiManager.get_succsess_delete_message(): # TODO(7kis) not check work the code emit("can_not_leave", str({"error": message}), room=AiManager.generate_ai_address(game_id, player_id)) else: game_id = data["game_id"] player_id = data["player_id"] address = AiManager.generate_ai_address(game_id, player_id) leave_room(address) emit("disconnect") sem.release()
def create_test_ai_and_logger(cls, ai_manager: AiManager): game_id: int = 0 player_id: int = 1 game_info = GameInfo( game_id, player_id, AiOptionExtractor.extract({"troopType": "motorized"})) ai_data = AiData( cls.generate_mock_location_info(), "Russia", { "graphDensity": [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ] }) ai_manager.create_ai( ai_info=ai_info, game_info=game_info, ai_data=ai_data, )
def set_unit_count(data): sem.acquire() room_info = data['channel_info'] game_id = str(room_info["game_id"]) player_id = str(room_info["player_id"]) unit_positions = controller.generate_ai_unit_positions( game_id, player_id, data['message']) print(unit_positions) print("place_units") emit("place_units", unit_positions, room=AiManager.generate_ai_address(game_id, player_id)) sem.release()
def handle_json(data): sem.acquire() print(f"sendGame {data}") room_info = data['channel_info'] game_id = room_info["game_id"] player_id = room_info["player_id"] commands = controller.update_ai(data['gameState'], game_info=GameInfo(game_id, player_id)) # print('received json: ' + str(commands)) address = AiManager.generate_ai_address(game_id, player_id) print("accept_command address={0}".format(address)) emit("accept_command", commands, room=address) sem.release()
def test_connect(data): # sem.acquire() print("join") controller.create_ai(data) room_info = data['channel_info'] game_id = str(room_info["game_id"]) player_id = str(room_info["player_id"]) address = AiManager.generate_ai_address(game_id, player_id) join_room(address) print('Open socket {0} socket info={1}'.format( address, controller.ai_manager.get_ai_socket_connection_info( game_id, player_id))) print('Location={0}'.format( controller.ai_manager.get_ai(game_id, player_id).get_location())) print("get_unit_count room={0}".format(address)) emit("get_unit_count", "", room=address)
def setUp(self) -> None: self._ai_manager = AiManager() self.create_test_ai_and_logger(self._ai_manager) self._log_data()