Пример #1
0
    def calc_playable_cards(self, player):
        """ Recalculate all legal cards the player can play according to his
        current hand.

        Args:
            player (PaodekuaiPlayer object): object of PaodekuaiPlayer
            init_flag (boolean): For the first time, set it True to accelerate
              the preocess.

        Returns:
            list: list of string of playable cards
        """

        player_id = player.player_id
        # old playable cards
        playable_cards = self.playable_cards[player_id].copy()

        # this current_hand is updated after action ,so it's different from old_playable_cards
        current_hand = cards2str(player.current_hand)

        current_legal = self.playable_cards_from_hand(current_hand)
        removed_playable_cards = list(playable_cards.difference(current_legal))
        self.playable_cards[player_id] = current_legal
        self._recorded_removed_playable_cards[player_id].append(
            removed_playable_cards)

        return self.playable_cards[player_id]
Пример #2
0
    def __init__(self, np_random):
        self.np_random = np_random
        self.trace = []
        self.played_cards = ''  #np.zeros((len(CARD_RANK_STR), ), dtype=np.int)

        self.greater_player = None
        self.dealer = Dealer(self.np_random)
        self.deck_str = cards2str(self.dealer.deck)
Пример #3
0
 def __init__(self, players, np_random):
     ''' Initilize the Judger class for Dou Dizhu
     '''
     self.playable_cards = [set() for _ in range(3)]
     self._recorded_removed_playable_cards = [[] for _ in range(3)]
     for player in players:
         player_id = player.player_id
         current_hand = cards2str(player.current_hand)
         # according to the game rule, generate all legal actions without comparison
         # the true legal actions are given directly by 'get_gt_cards' in pdkutils
         self.playable_cards[player_id] = self.playable_cards_from_hand(
             current_hand)
Пример #4
0
    def deal_cards(self, players):
        ''' Deal cards to players

        Args:
            players (list): list of PaodekuaiPlayer objects
        '''
        hand_num = len(self.deck) // self.num_split
        #check

        for index, player in enumerate(players):
            current_hand = self.deck[index * hand_num:(index + 1) * hand_num]
            current_hand.sort(key=functools.cmp_to_key(paodekuai_sort_card))
            player.set_current_hand(current_hand)
            player.initial_hand = cards2str(player.current_hand)
Пример #5
0
    def get_state(self, public, others_hands, actions):

        state = {
            **public, 'self': self.player_id,
            'initial_hand': self.initial_hand,
            'current_hand': cards2str(self._current_hand),
            'current_suit_hand': cards2str_with_suit(self._current_hand),
            'others_hand': others_hands,
            'actions': actions
        }

        #         state['deck'] = public['deck']
        # #        state['seen_cards'] = public['seen_cards']
        # #        state['landlord'] = public['landlord']
        #         state['trace'] = public['trace'].copy()
        #         state['played_cards'] = public['played_cards'].copy()

        return state
Пример #6
0
 def _get_others_current_hand(self, player):
     player_up = self.players[get_upstream_player_id(player, self.players)]
     player_down = self.players[get_downstream_player_id(
         player, self.players)]
     others_hand = merge(player_up.current_hand, player_down.current_hand, key=functools.cmp_to_key(paodekuai_sort_card))
     return cards2str(others_hand)