Esempio n. 1
0
    def filter_valid_moves(self, hand, state):
        top_card = card.from_cardpoint(state.top_card)
        # Different playing compulsions and scenarios
        if state.market_mode == 'PickTwo':
            ret = []
            for item in hand:
                if card.from_cardpoint(item).label == self.pick_two_label:
                    ret.append(item)

            return ret
        elif state.market_mode == 'General':
            # For general market, nothing can be played
            return []
        elif top_card.shape == 5:
            # If whot 20 is played, then look at the called card and return the matches
            # Whot 20 will also match
            ret = []
            for item in hand:
                item_card = card.from_cardpoint(item)
                if item_card.shape == state.called_card or item_card.shape == 5:
                    ret.append(item)

            return ret
        else:
            # Otherwise, choose all cards that match the top card either shape or label
            ret = []
            for item in hand:
                item_card = card.from_cardpoint(item)
                if item_card.shape == top_card.shape or item_card.label == top_card.label or item_card.shape == 5:
                    ret.append(item)

            return ret
Esempio n. 2
0
    def normalize(self):
        grid = np.zeros([5, 20], np.float32)

        # Transform the top card using a binary coded representation of the card label as the columns
        # and the card shape to specify the row e.g:
        # - Circle 12 [shape=2, label=12 (1100 in binary)] will have [0, 0, 1, 1, ...] written in the
        #   first 4 columns of the 3rd row of the grid.
        # - Cross 7 [shape=1, label=7 (0111 in binary)] will have [1, 1, 1, 0, ...] written in the
        #   first 4 columns of the 2nd row of the grid...etc.
        top = card.from_cardpoint(self.top_card)
        count = 0
        if top.shape != 5:
            while count < 4:
                grid[top.shape, count] = (top.label >> count) & 1
                count += 1
        elif self.called_card is not None:
            # If the card played is whot, then we just use the called card as the top card, while we
            # use the special number 15 (binary 1111) to indicate Whot was played.
            grid[self.called_card, 0:3] = 1.

        # Transform the market mode.
        pos = {'Normal': 0, 'PickTwo': 1, 'General': 2}[self.market_mode]
        grid[pos, 4] = 1.

        # Transform the cards in hand.
        num_whots = 0
        for item in self.hand:
            item_card = card.from_cardpoint(item)
            if item_card.shape == 5:  # WHOT
                grid[num_whots, 19] = 1.
                num_whots += 1
            else:
                grid[item_card.shape, 4 + item_card.label] = 1.

        return np.reshape(grid, [-1, 100])
Esempio n. 3
0
def top_matches(probability, number):
    # Find the highest probabilities.
    highest = np.argsort(-probability, axis=1)[0][0:number]
    return [card.from_cardpoint(cardpoint) for cardpoint in highest]
Esempio n. 4
0
 def __str__(self):
     return "Top: {}; Called: {}; Current player: {}; Mode: {}; Hand: {}"\
         .format(card.from_cardpoint(self.top_card), 'None' if self.called_card is None else card.shapes[self.called_card],
                 self.current_player, self.market_mode, [str(card.from_cardpoint(item)) for item in self.hand])
Esempio n. 5
0
 def is_hold_on(self, move, state):
     return card.from_cardpoint(move).label == self.hold_on_label
Esempio n. 6
0
 def is_suspension(self, move, state):
     return card.from_cardpoint(move).label == self.suspension_label
Esempio n. 7
0
 def is_general_market(self, move, state):
     return card.from_cardpoint(move).label == self.general_market_label
Esempio n. 8
0
 def is_pick_two(self, move, state):
     return card.from_cardpoint(move).label == self.pick_two_label
Esempio n. 9
0
 def matches_top_card(self, move, state):
     top_card = card.from_cardpoint(state.top_card)
     move_card = card.from_cardpoint(move)
     return move_card.label == top_card.label or move_card.shape == top_card.shape \
            or move_card.shape == 5 or move_card.shape == state.called_card
Esempio n. 10
0
 def is_pick_two_counter(self, move, state):
     move_card = card.from_cardpoint(move)
     return state.market_mode != 'PickTwo' or move_card.label == self.pick_two_label