Пример #1
0
 def _progress_the_game_till_human(self):
     while self._is_next_player_ai(global_game_manager):
         if GM.has_game_finished(global_game_manager.latest_messages): break
         action, amount = global_game_manager.ask_action_to_ai_player(
                 global_game_manager.next_player_uuid)
         global_game_manager.update_game(action, amount)
         MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
Пример #2
0
 def _progress_the_game_till_human(self):
     while self._is_next_player_ai(global_game_manager):
         if GM.has_game_finished(global_game_manager.latest_messages): break
         action, amount = global_game_manager.ask_action_to_ai_player(
                 global_game_manager.next_player_uuid)
         global_game_manager.update_game(action, amount)
         MM.broadcast_update_game(self, global_game_manager, self.sockets, MODE_SPEED)
Пример #3
0
 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)
Пример #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:
         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)
Пример #5
0
 def test_broadcast_update_game(self):
     uuids = ["hoge", "fuga"]
     sockets = [gen_mock_socket(uuid) for uuid in uuids]
     gm = setup_game_manager(uuids)
     list(gm.ai_players.values())[0].debug_message = None
     gm.update_game("fold", 0)
     with patch(
             'pypokergui.server.message_manager._gen_game_update_message',
             return_value="update_game"),\
         patch(
             'pypokergui.server.message_manager._broadcast_message_to_ai',
             side_effect=self._append_log_on_player):
         MM.broadcast_update_game("handler", gm, sockets, mode="dev")
     for soc, uuid in zip(sockets, uuids):
         expected = "update_game"
         self.eq(expected, soc.write_message.call_args_list[0][0][0])
     for player in gm.ai_players.values():
         self.assertIsNotNone(player.debug_message)
Пример #6
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)
Пример #7
0
 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)