예제 #1
0
 def build_game_update_message(self, player_pos, action, amount, state):
   player = state["table"].seats.players[player_pos]
   message = {
       "message_type": self.GAME_UPDATE_MESSAGE,
       "action": DataEncoder.encode_action(player, action, amount),
       "round_state": DataEncoder.encode_round_state(state),
       "action_histories": DataEncoder.encode_action_histories(state["table"])
   }
   return self.__build_notification_message(message)
예제 #2
0
 def build_game_update_message(self, player_pos, action, amount, state):
     player = state['table'].seats.players[player_pos]
     message = {
         'message_type': self.GAME_UPDATE_MESSAGE,
         'action': DataEncoder.encode_action(player, action, amount),
         'round_state': DataEncoder.encode_round_state(state),
         'action_histories':
         DataEncoder.encode_action_histories(state['table'])
     }
     return self.__build_notification_message(message)
예제 #3
0
 def build_game_update_message(self, player_pos, action, amount, state):
     player = state["table"].seats.players[player_pos]
     message = {
         "message_type": self.GAME_UPDATE_MESSAGE,
         "action": DataEncoder.encode_action(player, action, amount),
         "round_state": DataEncoder.encode_round_state(state),
         "action_histories":
         DataEncoder.encode_action_histories(state["table"])
     }
     return self.__build_notification_message(message)
예제 #4
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'])
예제 #5
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"])
예제 #7
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"])
예제 #8
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"])
 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"])
예제 #10
0
 def build_ask_message(self, player_pos, state):
   players = state["table"].seats.players
   player = players[player_pos]
   hole_card = DataEncoder.encode_player(player, holecard=True)["hole_card"]
   valid_actions = ActionChecker.legal_actions(players, player_pos, state["small_blind_amount"])
   message = {
       "message_type" : self.ASK_MESSAGE,
       "hole_card": hole_card,
       "valid_actions": valid_actions,
       "round_state": DataEncoder.encode_round_state(state),
       "action_histories": DataEncoder.encode_action_histories(state["table"])
   }
   return self.__build_ask_message(message)
예제 #11
0
 def test_encode_round_state(self):
     state = setup_round_state()
     state["table"].set_blind_pos(1, 3)
     hsh = DataEncoder.encode_round_state(state)
     self.eq("flop", hsh["street"])
     self.eq(DataEncoder.encode_pot(state["table"].seats.players), hsh["pot"])
     self.eq(DataEncoder.encode_seats(state["table"].seats)["seats"], hsh["seats"])
     self.eq(["CA"], hsh["community_card"])
     self.eq(state["table"].dealer_btn, hsh["dealer_btn"])
     self.eq(state["next_player"], hsh["next_player"])
     self.eq(1, hsh["small_blind_pos"])
     self.eq(3, hsh["big_blind_pos"])
     self.eq(DataEncoder.encode_action_histories(state["table"])["action_histories"], hsh["action_histories"])
     self.eq(state["round_count"], hsh["round_count"])
     self.eq(state["small_blind_amount"], hsh["small_blind_amount"])
예제 #12
0
 def test_encode_action_histories(self):
     table = setup_table()
     p1, p2, p3 = table.seats.players
     hsh = DataEncoder.encode_action_histories(table)
     hsty = hsh["action_histories"]
     self.eq(4, len(hsty["preflop"]))
     fetch_info = lambda info: (info["action"], info["amount"])
     self.eq(("RAISE", 10), fetch_info(hsty["preflop"][0]))
     self.eq("FOLD", hsty["preflop"][1]["action"])
     self.eq(("RAISE", 20), fetch_info(hsty["preflop"][2]))
     self.eq(("CALL", 20), fetch_info(hsty["preflop"][3]))
     self.eq(2, len(hsty["flop"]))
     self.eq(("CALL", 5), fetch_info(hsty["flop"][0]))
     self.eq(("RAISE", 5), fetch_info(hsty["flop"][1]))
     self.assertFalse("turn" in hsty)
     self.assertFalse("river" in hsty)
예제 #13
0
 def build_ask_message(self, player_pos, state):
     players = state["table"].seats.players
     player = players[player_pos]
     hole_card = DataEncoder.encode_player(player,
                                           holecard=True)["hole_card"]
     valid_actions = ActionChecker.legal_actions(
         players, player_pos, state["small_blind_amount"])
     message = {
         "message_type": self.ASK_MESSAGE,
         "hole_card": hole_card,
         "valid_actions": valid_actions,
         "round_state": DataEncoder.encode_round_state(state),
         "action_histories":
         DataEncoder.encode_action_histories(state["table"])
     }
     return self.__build_ask_message(message)
예제 #14
0
 def build_ask_message(self, player_pos, state):
     players = state['table'].seats.players
     player = players[player_pos]
     hole_card = DataEncoder.encode_player(player,
                                           holecard=True)['hole_card']
     valid_actions = ActionChecker.legal_actions(
         players, player_pos, state['small_blind_amount'])
     message = {
         'message_type': self.ASK_MESSAGE,
         'hole_card': hole_card,
         'valid_actions': valid_actions,
         'round_state': DataEncoder.encode_round_state(state),
         'action_histories':
         DataEncoder.encode_action_histories(state['table'])
     }
     return self.__build_ask_message(message)
예제 #15
0
 def test_encode_action_histories(self):
     table = setup_table()
     p1, p2, p3 = table.seats.players
     hsh = DataEncoder.encode_action_histories(table)
     hsty = hsh["action_histories"]
     self.eq(4, len(hsty["preflop"]))
     fetch_info = lambda info: (info["action"], info["amount"])
     self.eq(("RAISE", 10), fetch_info(hsty["preflop"][0]))
     self.eq("FOLD", hsty["preflop"][1]["action"])
     self.eq(("RAISE", 20), fetch_info(hsty["preflop"][2]))
     self.eq(("CALL", 20), fetch_info(hsty["preflop"][3]))
     self.eq(2, len(hsty["flop"]))
     self.eq(("CALL", 5), fetch_info(hsty["flop"][0]))
     self.eq(("RAISE", 5), fetch_info(hsty["flop"][1]))
     self.assertFalse("turn" in hsty)
     self.assertFalse("river" in hsty)
예제 #16
0
    def test_encode_action_histories(self):
        table = setup_table()
        p1, p2, p3 = table.seats.players
        hsh = DataEncoder.encode_action_histories(table)
        hsty = hsh['action_histories']
        self.eq(4, len(hsty['preflop']))

        def fetch_info(info):
            return (info['action'], info['amount'])

        self.eq(('RAISE', 10), fetch_info(hsty['preflop'][0]))
        self.eq('FOLD', hsty['preflop'][1]['action'])
        self.eq(('RAISE', 20), fetch_info(hsty['preflop'][2]))
        self.eq(('CALL', 20), fetch_info(hsty['preflop'][3]))
        self.eq(2, len(hsty['flop']))
        self.eq(('CALL', 5), fetch_info(hsty['flop'][0]))
        self.eq(('RAISE', 5), fetch_info(hsty['flop'][1]))
        self.assertFalse('turn' in hsty)
        self.assertFalse('river' in hsty)
예제 #17
0
 def test_encode_round_state(self):
     state = setup_round_state()
     state["table"].set_blind_pos(1, 3)
     hsh = DataEncoder.encode_round_state(state)
     self.eq("flop", hsh["street"])
     self.eq(DataEncoder.encode_pot(state["table"].seats.players),
             hsh["pot"])
     self.eq(
         DataEncoder.encode_seats(state["table"].seats)["seats"],
         hsh["seats"])
     self.eq(["CA"], hsh["community_card"])
     self.eq(state["table"].dealer_btn, hsh["dealer_btn"])
     self.eq(state["next_player"], hsh["next_player"])
     self.eq(1, hsh["small_blind_pos"])
     self.eq(3, hsh["big_blind_pos"])
     self.eq(
         DataEncoder.encode_action_histories(
             state["table"])["action_histories"], hsh["action_histories"])
     self.eq(state["round_count"], hsh["round_count"])
     self.eq(state["small_blind_amount"], hsh["small_blind_amount"])
예제 #18
0
 def test_encode_round_state(self):
     state = setup_round_state()
     state['table'].set_blind_pos(1, 3)
     hsh = DataEncoder.encode_round_state(state)
     self.eq('flop', hsh['street'])
     self.eq(DataEncoder.encode_pot(state['table'].seats.players),
             hsh['pot'])
     self.eq(
         DataEncoder.encode_seats(state['table'].seats)['seats'],
         hsh['seats'])
     self.eq(['2d'], hsh['community_card'])
     self.eq(state['table'].dealer_btn, hsh['dealer_btn'])
     self.eq(state['next_player'], hsh['next_player'])
     self.eq(1, hsh['small_blind_pos'])
     self.eq(3, hsh['big_blind_pos'])
     self.eq(
         DataEncoder.encode_action_histories(
             state['table'])['action_histories'], hsh['action_histories'])
     self.eq(state['round_count'], hsh['round_count'])
     self.eq(state['small_blind_amount'], hsh['small_blind_amount'])