예제 #1
0
 def test_ask_message(self):
     state = self.__setup_state()
     table = state["table"]
     message = MessageBuilder.build_ask_message(1, state)
     msg = message["message"]
     self.eq("ask", message["type"])
     self.eq(MessageBuilder.ASK_MESSAGE, msg["message_type"])
     self.eq(["CA", "C2"], msg["hole_card"])
     self.eq(3, len(msg["valid_actions"]))
     self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
     self.eq(DataEncoder.encode_action_histories(table), msg["action_histories"])
예제 #2
0
 def test_ask_message(self):
     state = self.__setup_state()
     table = state['table']
     message = MessageBuilder.build_ask_message(1, state)
     msg = message['message']
     self.eq('ask', message['type'])
     self.eq(MessageBuilder.ASK_MESSAGE, msg['message_type'])
     self.eq(['2d', '3d'], msg['hole_card'])
     self.eq(3, len(msg['valid_actions']))
     self.eq(DataEncoder.encode_round_state(state), msg['round_state'])
     self.eq(DataEncoder.encode_action_histories(table), msg['action_histories'])
 def test_ask_message(self):
   state = self.__setup_state()
   table = state["table"]
   message = MessageBuilder.build_ask_message(1, state)
   msg = message["message"]
   self.eq("ask", message["type"])
   self.eq(MessageBuilder.ASK_MESSAGE, msg["message_type"])
   self.eq(["CA", "C2"], msg["hole_card"])
   self.eq(3, len(msg["valid_actions"]))
   self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
   self.eq(DataEncoder.encode_action_histories(table), msg["action_histories"])
예제 #4
0
 def __forward_street(self, state):
   table = state["table"]
   street_start_msg = [(-1, MessageBuilder.build_street_start_message(state))]
   if table.seats.count_active_players() == 1: street_start_msg = []
   if table.seats.count_ask_wait_players() <= 1:
     state["street"] += 1
     state, messages = self.__start_street(state)
     return state, street_start_msg + messages
   else:
     next_player_pos = state["next_player"]
     next_player = table.seats.players[next_player_pos]
     ask_message = [(next_player.uuid, MessageBuilder.build_ask_message(next_player_pos, state))]
     return state, street_start_msg + ask_message
예제 #5
0
 def apply_action(self, original_state, action, bet_amount, bot_info=None):
   state = self.__deep_copy_state(original_state)
   state = self.__update_state_by_action(state, action, bet_amount, bot_info=bot_info)
   update_msg = self.__update_message(state, action, bet_amount)
   if self.__is_everyone_agreed(state):
     [player.save_street_action_histories(state["street"]) for player in state["table"].seats.players]
     state["street"] += 1
     state, street_msgs = self.__start_street(state)
     return state, [update_msg] + street_msgs
   else:
     state["next_player"] = state["table"].next_ask_waiting_player_pos(state["next_player"])
     next_player_pos = state["next_player"]
     next_player = state["table"].seats.players[next_player_pos]
     ask_message = (next_player.uuid, MessageBuilder.build_ask_message(next_player_pos, state))
     return state, [update_msg, ask_message]
예제 #6
0
 def run_until_round_finish(self, game_state):
     mailbox = []
     while game_state["street"] != Const.Street.FINISHED:
         next_player_pos = game_state["next_player"]
         next_player_uuid = game_state["table"].seats.players[next_player_pos].uuid
         next_player_algorithm = self.fetch_player(next_player_uuid)
         msg = MessageBuilder.build_ask_message(next_player_pos, game_state)["message"]
         action, amount = next_player_algorithm.declare_action(\
                 msg["valid_actions"], msg["hole_card"], msg["round_state"])
         game_state, messages = RoundManager.apply_action(game_state, action, amount)
         mailbox += messages
     events = [self.create_event(message[1]["message"]) for message in mailbox]
     events = [e for e in events if e]
     if self._is_last_round(game_state, self.game_rule):
         events += self._generate_game_result_event(game_state)
     return game_state, events
 def __ask_message(self):
   state = self.__setup_state()
   return MessageBuilder.build_ask_message(1, state)