예제 #1
0
파일: poker.py 프로젝트: xiniuniu/DeepPoker
 def on_message(self, message):
     js = tornado.escape.json_decode(message)
     message_type = js['type']
     if 'action_new_member' == message_type:
         global_game_manager.join_human_player(js['name'], self.uuid)
         MM.broadcast_config_update(self, global_game_manager, self.sockets)
     elif 'action_start_game' == message_type:
         if global_game_manager.is_playing_poker:
             MM.alert_server_restart(self, self.uuid, self.sockets)
         else:
             global_game_manager.start_game()
             MM.broadcast_start_game(self, global_game_manager,
                                     self.sockets)
             MM.broadcast_update_game(self, global_game_manager,
                                      self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     elif 'action_declare_action' == message_type:
         if self.uuid == global_game_manager.next_player_uuid:
             action, amount = self._correct_action(js)
             global_game_manager.update_game(action, amount)
             MM.broadcast_update_game(self, global_game_manager,
                                      self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     else:
         raise Exception("Unexpected message [ %r ] received" % message)
예제 #2
0
 def test_broadcast_config_update(self):
     uuids = ["hoge", "fuga"]
     sockets = [gen_mock_socket(uuid) for uuid in uuids]
     with patch(
             'pypokergui.server.message_manager._gen_config_update_message',
             side_effect=lambda x, y, uuid: "config_update:%s" % uuid):
         MM.broadcast_config_update("handler", GameManager(), sockets)
     for soc, uuid in zip(sockets, uuids):
         expected = "config_update:%s" % uuid
         self.eq(expected, soc.write_message.call_args_list[0][0][0])
예제 #3
0
 def on_message(self, message):
     global global_game_manager
     js = tornado.escape.json_decode(message)
     message_type = js['type']
     if 'action_new_member' == message_type:
         player_type = js['player_type']
         if player_type == 'human':
             print('HUMAN_JOINED')
             global_game_manager.join_human_player(js['name'], self.uuid)
         else:
             print('AI_JOINED')
             global_game_manager.join_ai_player(js['name'], './setup_gui_ai.py', '../model.h5')
         MM.broadcast_config_update(self, global_game_manager, self.sockets)
     elif 'update_config' == message_type:
         print('Walla')
         global_game_manager.define_rule(
             int(js['max_round']), int(js['initial_stack']), int(js['small_blind']),
             int(js['ante']), None
         )
         for i in range(1, int(js['ai_players']) - 1):
             global_game_manager.join_ai_player('Player_' + str(i), './setup_gui_ai.py', '../model.h5')
     elif 'action_start_game' == message_type:
         if global_game_manager.is_playing_poker:
             MM.alert_server_restart(self, self.uuid, self.sockets)
         else:
             global_game_manager.start_game()
             MM.broadcast_start_game(self, global_game_manager, self.sockets)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     elif 'action_restart_game' == message_type:
         print("ACTION RESTART GAME")
         global_game_manager.stop_game()
         print("Is playing poker", global_game_manager.is_playing_poker)
         
         global_game_manager = GM.GameManager()
         tornado.options.parse_command_line()
         with open('config.yaml', "rb") as f:
             config = yaml.load(f)
         setup_config(config)
         print("Is playing poker after Config", global_game_manager.is_playing_poker)
         # tornado.options.parse_command_line()
         # start_server(options.config, options.port, options.speed)
     elif 'action_declare_action' == message_type:
         if self.uuid == global_game_manager.next_player_uuid:
             action, amount = self._correct_action(js)
             global_game_manager.update_game(action, amount)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     else:
         raise Exception("Unexpected message [ %r ] received" % message)
예제 #4
0
 def on_message(self, message):
     global global_game_manager
     js = tornado.escape.json_decode(message)
     message_type = js['type']
     if 'action_new_member' == message_type:
         global_game_manager.join_human_player(js['name'], self.uuid)
         MM.broadcast_config_update(self, global_game_manager, self.sockets)
     elif 'action_start_game' == message_type:
         if global_game_manager.is_playing_poker:
             MM.alert_server_restart(self, self.uuid, self.sockets)
         else:
             global_game_manager.start_game()
             MM.broadcast_start_game(self, global_game_manager, self.sockets)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     elif 'action_restart_game' == message_type:
         print("ACTION RESTART GAME")
         global_game_manager.stop_game()
         print("Is playing poker", global_game_manager.is_playing_poker)
         
         global_game_manager = GM.GameManager()
         tornado.options.parse_command_line()
         with open('config.yaml', "rb") as f:
             config = yaml.load(f)
         setup_config(config)
         print("Is playing poker after Config", global_game_manager.is_playing_poker)
         # tornado.options.parse_command_line()
         # start_server(options.config, options.port, options.speed)
     elif 'action_declare_action' == message_type:
         if self.uuid == global_game_manager.next_player_uuid:
             action, amount = self._correct_action(js)
             global_game_manager.update_game(action, amount)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     else:
         raise Exception("Unexpected message [ %r ] received" % message)
예제 #5
0
파일: poker.py 프로젝트: nn-simon/PokerAI
 def on_message(self, message):
     js = tornado.escape.json_decode(message)
     message_type = js['type']
     if 'action_new_member' == message_type:
         global_game_manager.join_human_player(js['name'], self.uuid)
         MM.broadcast_config_update(self, global_game_manager, self.sockets)
     elif 'action_start_game' == message_type:
         if global_game_manager.is_playing_poker:
             MM.alert_server_restart(self, self.uuid, self.sockets)
         else:
             global_game_manager.start_game()
             MM.broadcast_start_game(self, global_game_manager, self.sockets)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     elif 'action_declare_action' == message_type:
         if self.uuid == global_game_manager.next_player_uuid:
             action, amount = self._correct_action(js)
             global_game_manager.update_game(action, amount)
             MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
             if self._is_next_player_ai(global_game_manager):
                 self._progress_the_game_till_human()
     else:
         raise Exception("Unexpected message [ %r ] received" % message)
예제 #6
0
 def on_close(self):
     PokerWebSocketHandler.sockets.remove(self)
     if global_game_manager.get_human_player_info(self.uuid):
         global_game_manager.remove_human_player_info(self.uuid)
         MM.broadcast_config_update(self, global_game_manager, self.sockets)
예제 #7
0
파일: poker.py 프로젝트: nn-simon/PokerAI
 def on_close(self):
     PokerWebSocketHandler.sockets.remove(self)
     if global_game_manager.get_human_player_info(self.uuid):
         global_game_manager.remove_human_player_info(self.uuid)
         MM.broadcast_config_update(self, global_game_manager, self.sockets)