server.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Hanabi-AI 作者: MeGotsThis 项目源码 文件源码
def discard_card(self, player: int, deckIdx: int) -> None:
        if self.isGameComplete():
            raise GameException('Game is complete')
        if self.lastAction == player:
            raise GameException('Player already made a move', player)
        if self.currentPlayer != player:
            raise GameException('Wrong Player Turn', player)
        if self.clues == 8:
            raise GameException('Cannot Discard')
        card: ServerCard = self.deck[deckIdx]
        if card.status != CardStatus.Hand:
            raise GameException('Bad Card Status', card.status)
        if card.player != player:
            raise GameException('Card does not belong to player', card.player)
        self.discards[card.suit].append(card.position)
        self.send('notify',
                  {'type': 'discard',
                   'which': {'suit': card.suit, 'rank': card.rank,
                             'index': card.index, 'order': card.position}})
        card.status = CardStatus.Discard
        position: int
        position = len(self.hands[player]) - self.hands[player].index(deckIdx)
        self.hands[player].remove(deckIdx)
        self.clues += 1
        self.print(
            "{} discards {} {}".format(
                names[player], card.suit.full_name(self.variant),
                card.rank.value),
            "{} discards {} {} from slot {}".format(
                names[player], card.suit.full_name(self.variant),
                card.rank.value, position))
        self.draw_card(player)
        self.lastAction = player
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号