Esempio n. 1
0
    def determine_role(self, players):
        ''' Determine landlord and peasants according to players' hand

        Args:
            players (list): list of DoudizhuPlayer objects

        Returns:
            int: landlord's player_id
        '''

        # deal cards
        self.shuffle()
        self.deal_cards(players)
        players[0].role = 'peasant'
        self.landlord = players[0]

        # determine 'landlord'
        max_score = get_landlord_score(
            cards2str(self.landlord.current_hand))
        for player in players[1:]:
            player.role = 'peasant'
            score = get_landlord_score(
                cards2str(player.current_hand))
            if score > max_score:
                max_score = score
                self.landlord = player
        self.landlord.role = 'landlord'

        # give the 'landlord' the  three cards
        self.landlord.hand.extend(self.deck[-3:])
        self.landlord.hand.sort(key=functools.cmp_to_key(doudizhu_sort_card))
        self.landlord.current_hand = copy.deepcopy(self.landlord.hand)
        return self.landlord.player_id
Esempio n. 2
0
 def test_get_landlord_score(self):
     score_1 = get_landlord_score('56888TTQKKKAA222R')
     self.assertEqual(score_1, 12)