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
评论列表
文章目录