Beispiel #1
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
Beispiel #2
0
 def __notify_game_start(self, max_round):
     config = self.__gen_config(max_round)
     start_msg = MessageBuilder.build_game_start_message(
         config, self.table.seats)
     self.message_handler.process_message(-1, start_msg)
     self.message_summarizer.summarize(start_msg)
     self.game_summarizer.summarize(start_msg)
Beispiel #3
0
 def __generate_game_result(self, max_round, seats):
     config = self.__gen_config(max_round)
     result_message = MessageBuilder.build_game_result_message(
         config, seats)
     self.message_summarizer.summarize(result_message)
     self.game_summarizer.summarize(result_message)
     return result_message
Beispiel #4
0
 def __showdown(self, state):
   winners, hand_info, prize_map = GameEvaluator.judge(state["table"])
   self.__prize_to_winners(state["table"].seats.players, prize_map)
   result_message = MessageBuilder.build_round_result_message(state["round_count"], winners, hand_info, state)
   state["table"].reset()
   state["street"] += 1
   return state, [(-1, result_message)]
 def __round_start_message(self, round_count, table):
     players = table.seats.players
     gen_msg = lambda idx: (players[idx].uuid,
                            MessageBuilder.build_round_start_message(
                                round_count, idx, table.seats))
     return reduce(lambda acc, idx: acc + [gen_msg(idx)],
                   range(len(players)), [])
Beispiel #6
0
 def test_street_start_message(self):
     state = self.__setup_state()
     message = MessageBuilder.build_street_start_message(state)
     msg = message['message']
     self.eq(MessageBuilder.STREET_START_MESSAGE, msg['message_type'])
     self.eq('notification', message['type'])
     self.eq('flop', msg['street'])
     self.eq(DataEncoder.encode_round_state(state), msg['round_state'])
 def test_street_start_message(self):
   state = self.__setup_state()
   message = MessageBuilder.build_street_start_message(state)
   msg = message["message"]
   self.eq(MessageBuilder.STREET_START_MESSAGE, msg["message_type"])
   self.eq("notification", message["type"])
   self.eq("flop", msg["street"])
   self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
Beispiel #8
0
 def test_street_start_message(self):
     state = self.__setup_state()
     message = MessageBuilder.build_street_start_message(state)
     msg = message["message"]
     self.eq(MessageBuilder.STREET_START_MESSAGE, msg["message_type"])
     self.eq("notification", message["type"])
     self.eq("flop", msg["street"])
     self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
Beispiel #9
0
 def test_round_start_message(self):
     seats = self.__setup_seats()
     message = MessageBuilder.build_round_start_message(7, 1, seats)
     msg = message['message']
     self.eq('notification', message['type'])
     self.eq(MessageBuilder.ROUND_START_MESSAGE, msg['message_type'])
     self.eq(7, msg['round_count'])
     self.eq(DataEncoder.encode_seats(seats)['seats'], msg['seats'])
     self.eq(['2d', '3d'], msg['hole_card'])
Beispiel #10
0
 def test_game_start_message(self):
     config = self.__setup_config()
     seats = self.__setup_seats()
     message = MessageBuilder.build_game_start_message(config, seats)
     msg = message['message']
     self.eq('notification', message['type'])
     self.eq(MessageBuilder.GAME_START_MESSAGE, msg['message_type'])
     self.eq(MessageBuilder.GAME_START_MESSAGE, msg['message_type'])
     self.eq(DataEncoder.encode_game_information(config, seats), msg['game_information'])
 def test_game_result_message(self):
   config = self.__setup_config()
   seats = self.__setup_seats()
   state = self.__setup_state()
   message = MessageBuilder.build_game_result_message(config, seats)
   msg = message["message"]
   self.eq("notification", message["type"])
   self.eq(MessageBuilder.GAME_RESULT_MESSAGE, msg["message_type"])
   self.eq(DataEncoder.encode_game_information(config, seats), msg["game_information"])
 def test_round_start_message(self):
   seats = self.__setup_seats()
   message = MessageBuilder.build_round_start_message(7, 1, seats)
   msg = message["message"]
   self.eq("notification", message["type"])
   self.eq(MessageBuilder.ROUND_START_MESSAGE, msg["message_type"])
   self.eq(7, msg["round_count"])
   self.eq(DataEncoder.encode_seats(seats)["seats"], msg["seats"])
   self.eq(["CA", "C2"], msg["hole_card"])
Beispiel #13
0
 def test_round_start_message(self):
     seats = self.__setup_seats()
     message = MessageBuilder.build_round_start_message(7, 1, seats)
     msg = message["message"]
     self.eq("notification", message["type"])
     self.eq(MessageBuilder.ROUND_START_MESSAGE, msg["message_type"])
     self.eq(7, msg["round_count"])
     self.eq(DataEncoder.encode_seats(seats)["seats"], msg["seats"])
     self.eq(["CA", "C2"], msg["hole_card"])
Beispiel #14
0
 def test_game_result_message(self):
     config = self.__setup_config()
     seats = self.__setup_seats()
     state = self.__setup_state()
     message = MessageBuilder.build_game_result_message(config, seats)
     msg = message["message"]
     self.eq("notification", message["type"])
     self.eq(MessageBuilder.GAME_RESULT_MESSAGE, msg["message_type"])
     self.eq(DataEncoder.encode_game_information(config, seats), msg["game_information"])
 def _generate_game_result_event(self, game_state):
     dummy_config = {
             "initial_stack": None,
             "max_round": None,
             "small_blind_amount": None,
             "ante": None,
             "blind_structure": None
             }
     message = MessageBuilder.build_game_result_message(dummy_config, game_state["table"].seats)["message"]
     return [self.create_event(message)]
Beispiel #16
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"])
Beispiel #17
0
 def test_game_update_message(self):
     state = self.__setup_state()
     table = state["table"]
     player = table.seats.players[1]
     message = MessageBuilder.build_game_update_message(1, "call", 10, state)
     msg = message["message"]
     self.eq("notification", message["type"])
     self.eq(MessageBuilder.GAME_UPDATE_MESSAGE, msg["message_type"])
     self.eq(DataEncoder.encode_action(player, "call", 10), msg["action"])
     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"])
 def test_game_update_message(self):
   state = self.__setup_state()
   table = state["table"]
   player = table.seats.players[1]
   message = MessageBuilder.build_game_update_message(1, "call", 10, state)
   msg = message["message"]
   self.eq("notification", message["type"])
   self.eq(MessageBuilder.GAME_UPDATE_MESSAGE, msg["message_type"])
   self.eq(DataEncoder.encode_action(player, "call", 10), msg["action"])
   self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
   self.eq(DataEncoder.encode_action_histories(table), msg["action_histories"])
Beispiel #20
0
def _gen_game_result_message(table, config):
    compat_config = {
        'initial_stack': config['initial_stack'],
        'max_round': config['max_round'],
        'small_blind_amount': config['small_blind'],  # fill an interface gap
        'ante': config['ante'],
        'blind_structure': config['blind_structure']
    }
    msg = MessageBuilder.build_game_result_message(compat_config, table.seats)
    destination = -1
    return (destination, msg)
Beispiel #21
0
def _gen_game_result_message(table, config):
    compat_config = {
            'initial_stack': config['initial_stack'],
            'max_round': config['max_round'],
            'small_blind_amount': config['small_blind'],  # fill an interface gap
            'ante': config['ante'],
            'blind_structure': config['blind_structure']
            }
    msg = MessageBuilder.build_game_result_message(compat_config, table.seats)
    destination = -1
    return (destination, msg)
Beispiel #22
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'])
Beispiel #23
0
 def test_game_update_message(self):
     state = self.__setup_state()
     table = state['table']
     player = table.seats.players[1]
     message = MessageBuilder.build_game_update_message(1, 'call', 10, state)
     msg = message['message']
     self.eq('notification', message['type'])
     self.eq(MessageBuilder.GAME_UPDATE_MESSAGE, msg['message_type'])
     self.eq(DataEncoder.encode_action(player, 'call', 10), msg['action'])
     self.eq(DataEncoder.encode_round_state(state), msg['round_state'])
     self.eq(DataEncoder.encode_action_histories(table), msg['action_histories'])
Beispiel #24
0
 def test_round_result_message(self):
     state = self.__setup_state()
     winners = state["table"].seats.players[1:2]
     hand_info = ["dummy", "info"]
     message = MessageBuilder.build_round_result_message(7, winners, hand_info, state)
     msg = message["message"]
     self.eq("notification", message["type"])
     self.eq(MessageBuilder.ROUND_RESULT_MESSAGE, msg["message_type"])
     self.eq(7, msg["round_count"])
     self.eq(hand_info, msg["hand_info"])
     self.eq(DataEncoder.encode_winners(winners)["winners"], msg["winners"])
     self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
Beispiel #25
0
 def test_round_result_message(self):
     state = self.__setup_state()
     winners = state['table'].seats.players[1:2]
     hand_info = ['dummy', 'info']
     message = MessageBuilder.build_round_result_message(7, winners, hand_info, state)
     msg = message['message']
     self.eq('notification', message['type'])
     self.eq(MessageBuilder.ROUND_RESULT_MESSAGE, msg['message_type'])
     self.eq(7, msg['round_count'])
     self.eq(hand_info, msg['hand_info'])
     self.eq(DataEncoder.encode_winners(winners)['winners'], msg['winners'])
     self.eq(DataEncoder.encode_round_state(state), msg['round_state'])
 def test_round_result_message(self):
   state = self.__setup_state()
   winners = state["table"].seats.players[1:2]
   hand_info = ["dummy", "info"]
   message = MessageBuilder.build_round_result_message(7, winners, hand_info, state)
   msg = message["message"]
   self.eq("notification", message["type"])
   self.eq(MessageBuilder.ROUND_RESULT_MESSAGE, msg["message_type"])
   self.eq(7, msg["round_count"])
   self.eq(hand_info, msg["hand_info"])
   self.eq(DataEncoder.encode_winners(winners)["winners"], msg["winners"])
   self.eq(DataEncoder.encode_round_state(state), msg["round_state"])
Beispiel #27
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]
 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 __game_update_message(self):
   state = self.__setup_state()
   return MessageBuilder.build_game_update_message(1, "call", 10, state)
 def __ask_message(self):
   state = self.__setup_state()
   return MessageBuilder.build_ask_message(1, state)
 def __street_start_message(self):
   state = self.__setup_state()
   return MessageBuilder.build_street_start_message(state)
 def __round_start_message(self):
   seats = self.__setup_seats()
   return MessageBuilder.build_round_start_message(7, 1, seats)
Beispiel #33
0
 def __update_message(self, state, action, bet_amount):
   return (-1, MessageBuilder.build_game_update_message(
     state["next_player"], action, bet_amount, state))
 def __round_result_message(self):
   hand_info = ["dummy", "info"]
   state = self.__setup_state()
   winners = state["table"].seats.players[1:2]
   return MessageBuilder.build_round_result_message(7, winners, hand_info, state)
Beispiel #35
0
 def __notify_game_start(self, max_round):
   config = self.__gen_config(max_round)
   start_msg = MessageBuilder.build_game_start_message(config, self.table.seats)
   self.message_handler.process_message(-1, start_msg)
   self.message_summarizer.summarize(start_msg)
Beispiel #36
0
 def gen_msg(idx):
     return (players[idx].uuid,
             MessageBuilder.build_round_start_message(
                 round_count, idx, table.seats))
 def __round_result_message(self):
     hand_info = ['dummy', 'info']
     state = self.__setup_state()
     winners = state['table'].seats.players[1:2]
     return MessageBuilder.build_round_result_message(
         7, winners, hand_info, state)
 def __game_result_message(self):
   config = self.__setup_config()
   seats = self.__setup_seats()
   return MessageBuilder.build_game_result_message(config, seats)
Beispiel #39
0
 def __generate_game_result(self, max_round, seats):
   config = self.__gen_config(max_round)
   result_message = MessageBuilder.build_game_result_message(config, seats)
   self.message_summarizer.summarize(result_message)
   return result_message