Esempio n. 1
0
class Robot(Person):
    """机器人"""
    def __init__(self, name, credits=100):
        super().__init__(name, credits)
        self.is_real = False
        self.output_name = name
        self.cards_blocks = None

    def reset_profile(self):
        self.cards = Cards()
        self.identity = None
        self.landlord_score = None
        self.cards_blocks = None

    def deal_landlord_score(self, last_landlord_score):
        if self.landlord_score is None:
            self.landlord_score = min(self.cards.cal_confidence(), 3)
        if self.landlord_score > last_landlord_score:
            MessagePoster.post_hint(hint_type='person_gave_landlord_score',
                                    output_name=self.output_name,
                                    landlord_score=str(self.landlord_score))
            return self.landlord_score
        else:
            MessagePoster.post_hint(
                hint_type='person_abandon_giving_landlord_score',
                output_name=self.output_name)
            return

    def deal_cards_with_last_cards(self, last_cards, last_person_identity):

        ## 不管10以上的同伙的牌
        if self.identity == last_person_identity and last_cards.size >= Card(
                'J').size:
            MessagePoster.post_hint(hint_type='person_abandon_dealing_cards',
                                    output_name=self.output_name)
            return
        for undealed_cards in self.cards_blocks[::-1]:
            if undealed_cards > last_cards:
                self.cards_blocks.remove(undealed_cards)
                self.cards -= undealed_cards
                MessagePoster.post_hint(hint_type='person_dealed_cards',
                                        output_name=self.output_name,
                                        unprinted_cards=str(undealed_cards))
                return undealed_cards
        else:
            MessagePoster.post_hint(hint_type='person_abandon_dealing_cards',
                                    output_name=self.output_name)
            return

    def deal_cards_without_last_cards(self):
        undealed_cards = self.cards_blocks.pop()
        self.cards -= undealed_cards
        MessagePoster.post_hint(hint_type='person_dealed_cards',
                                unprinted_cards=str(undealed_cards),
                                output_name=self.output_name)
        return undealed_cards

    def deal_cards(self, last_cards, last_person_identity):
        if self.cards_blocks is None:
            self.cards_blocks = self.cards.separate()
            # for cards_block in self.cards_blocks:
            # 	print(f'{str(cards_block)}, {cards_block.species}, {cards_block.chain_length}, {cards_block.size}')
        if last_cards is not None:
            undealed_cards = self.deal_cards_with_last_cards(
                last_cards, last_person_identity)
        else:
            undealed_cards = self.deal_cards_without_last_cards()
        return undealed_cards