示例#1
0
 def test_init_hs_info_start_game(self):
     own_hand = ["2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "Th"]
     p1 = Player.player_start_of_game(0, own_hand)
     res = p1._init_hs_info_start_game(0, own_hand)
     expected = {}
     opp_hs_info = {hs: 0 for hs in card_utils.gen_all_halfsuits()}
     for i in range(1, constants.NUM_PLAYERS):
         expected[i] = opp_hs_info.copy()
     own_hs_info = {hs: 0 for hs in card_utils.gen_all_halfsuits()}
     own_hs_info["Lh"] = 6
     own_hs_info["8J"] = 1
     own_hs_info["Hh"] = 2
     expected[0] = own_hs_info.copy()
     self.assertEqual(res, expected, "Failed in init_hs_info_start_game")
示例#2
0
 def test_init_public_hs_info_start_game(self):
     p1 = Player.player_start_of_game(0, [])
     res = p1._init_public_hs_info_start_game()
     expected = {
         ID: {hs: 0
              for hs in card_utils.gen_all_halfsuits()}
         for ID in range(constants.NUM_PLAYERS)
     }
     self.assertEqual(res, expected,
                      "Failed in init_public_hs_info_start_game")
示例#3
0
 def test_is_consistent_duplicate_cards(self):
     info = {
         ID:
         {card: constants.UNSURE
          for card in card_utils.gen_all_cards()}
         for ID in range(constants.NUM_PLAYERS)
     }
     hs_info = {
         ID: {hs: 1
              for hs in card_utils.gen_all_halfsuits()}
         for ID in range(constants.NUM_PLAYERS)
     }
     info[0]["2h"] = constants.YES
     info[1]["2h"] = constants.YES
     self.assertFalse(
         Player._is_consistent(
             info, list(card_utils.gen_all_halfsuits()), hs_info,
             {ID: 9
              for ID in range(constants.NUM_PLAYERS)}),
         "Failed to catch duplicate cards in _is_consistent")
示例#4
0
 def test_is_consistent_hs(self):
     info = {
         ID:
         {card: constants.UNSURE
          for card in card_utils.gen_all_cards()}
         for ID in range(constants.NUM_PLAYERS)
     }
     hs_info = {
         ID: {hs: 0
              for hs in card_utils.gen_all_halfsuits()}
         for ID in range(constants.NUM_PLAYERS)
     }
     hs_info[1]["Hc"] = 4
     info[1]["9c"] = constants.NO
     info[1]["Tc"] = constants.NO
     self.assertTrue(
         Player._is_consistent(
             info, list(card_utils.gen_all_halfsuits()), hs_info,
             {ID: 9
              for ID in range(constants.NUM_PLAYERS)}),
         "Incorrectly claimed inconsistency")
示例#5
0
 def _init_public_hs_info_start_game():
     """
     Returns the public half suit info at the start of a game
     (This is just an empty dictionary)
     """
     public_hs_info = {}
     for ID in range(NUM_PLAYERS):
         d = {}
         for hs in card_utils.gen_all_halfsuits():
             d[hs] = 0
         public_hs_info[ID] = d
     return public_hs_info
示例#6
0
 def _check_card_guarenteed(self):
     """
     Checks if an opponent player has a card that you know you are guarenteed to guess correctly
     If so, return a tuple (player_id, card)
     If not, return False
     """
     for hs in card_utils.gen_all_halfsuits():
         if self.hs_info[self.ID][hs] > 0:
             for card in card_utils.find_cards(hs):
                 for ID in self._get_opponents():
                     if self.info[ID][card] == YES:
                         return ID, card
     return False
示例#7
0
 def _init_hs_info_start_game(ID, own_cards):
     """
     Returns the half suit info dictionary assuming its the start of a new game
     Uses data from the already intialized info dictionary
     """
     blank_hs = {hs: 0 for hs in card_utils.gen_all_halfsuits()}
     hs_info = {
         player_id: blank_hs.copy()
         for player_id in range(NUM_PLAYERS)
     }
     for card in own_cards:
         hs_info[ID][card_utils.find_half_suit(card)] += 1
     return hs_info
示例#8
0
 def player_start_of_game(cls, ID, own_cards, name=None):
     """
     This initialization corresponds to the initialization at the start of a fish game
     Assumes that everyone has 9 cards
     """
     num_cards = {x: 9 for x in range(NUM_PLAYERS)}
     return cls(ID,
                num_cards,
                cls._init_info_start_game(ID, own_cards),
                cls._init_public_info_start_game(),
                cls._init_hs_info_start_game(ID, own_cards),
                cls._init_public_hs_info_start_game(),
                list(card_utils.gen_all_halfsuits()),
                name=name)
示例#9
0
 def check_call(self):
     """
     Check if you can call a half suit
     Returns a list of tuples like this:
     [(player, card), (player, card) ...]
     If no call can be made, return False
     """
     for hs in card_utils.gen_all_halfsuits():
         call = []
         for card in card_utils.find_cards(hs):
             for ID in self._get_teammates():
                 if self.info[ID][card] == YES:
                     call.append((ID, card))
         if len(call) == HS_SIZE:
             return call
     return False
示例#10
0
    def generate_state_vector(info, hs_info, num_cards, public_info, ID_player):
        """
        Generates a state vector from the player's information

        The structure of the state vector is as follows:
        Length: 708 (SIZE_STATES)
        The order of players in each section starts with the ID of the player
        and counts up mod 6 (example: 3, 4, 5, 0, 1, 2)
        The order of cards is defined in card_utils.gen_all_cards
        The first 54 * 6 = 324 entries are for the info dict, with the values
        being the same as in the info dict
        The next 54 * 6 = 324 entries are for the public_info dict, with the values
        being the same as in the public_info dict
        The next 9 * 6 = 54 entries are for the hs_info, with the values
        being the same as in the hs_info dict
        The last 6 entries are the number of cards each player has

        :param info: defined in Player class
        :param hs_info: defined in Player class
        :param num_cards: defined in Player class
        :param public_info: defined in Player class
        :param ID_player: ID of the player
        :return: a state vector
        """
        player_order = list(range(6))[ID_player:] + list(range(6))[:ID_player]
        state = []
        # Info dict
        for ID in player_order:
            for card in card_utils.gen_all_cards():
                state.append(info[ID][card])
        # Public Info dict
        for ID in player_order:
            for card in card_utils.gen_all_cards():
                state.append(public_info[ID][card])
        # Half suit info dict
        for ID in player_order:
            for hs in card_utils.gen_all_halfsuits():
                state.append(hs_info[ID][hs])
        # Num cards
        for ID in player_order:
            state.append(num_cards[ID])
        return state
示例#11
0
 def test_is_consistent_all_nos_3(self):
     info = {
         ID:
         {card: constants.UNSURE
          for card in card_utils.gen_all_cards()}
         for ID in range(constants.NUM_PLAYERS)
     }
     hs_info = {
         ID: {hs: 0
              for hs in card_utils.gen_all_halfsuits()}
         for ID in range(constants.NUM_PLAYERS)
     }
     for ID in range(constants.NUM_PLAYERS):
         info[ID]["2h"] = constants.NO
     self.assertTrue(
         Player._is_consistent(
             info, ["8J"], hs_info,
             {ID: 1
              for ID in range(constants.NUM_PLAYERS)}),
         "Incorrectly claimed inconsistency")
示例#12
0
 def test_is_consistent_all_nos(self):
     info = {
         ID:
         {card: constants.UNSURE
          for card in card_utils.gen_all_cards()}
         for ID in range(constants.NUM_PLAYERS)
     }
     hs_info = {
         ID: {hs: 0
              for hs in card_utils.gen_all_halfsuits()}
         for ID in range(constants.NUM_PLAYERS)
     }
     for ID in range(constants.NUM_PLAYERS):
         info[ID]["2h"] = constants.NO
     self.assertFalse(
         Player._is_consistent(
             info, ["Lh"], hs_info,
             {ID: 1
              for ID in range(constants.NUM_PLAYERS)}),
         "Failed to catch duplicate cards in _is_consistent")