예제 #1
0
    def playable(self, card_to_play: Card) -> bool:
        """Checks whether a card can be played.

        Args:
            card_to_play (Card): card to try to play

        Returns:
            bool: whether the card can be played or not
        """
        top_card = self.discard[-1]
        tc_suit = self.get_top_card_suit()  # suit might be set differently

        # Check the conditions to be met for the card to be playable.
        return (card_to_play.get_rank() == top_card.get_rank() or
                card_to_play.get_suit() == tc_suit or
                card_to_play.get_rank() == Rank.EIGHT)
예제 #2
0
    def play(self, player_num: int, card_to_play: Card,
             set_suit: Optional[Suit] = Suit.SPADES) -> bool:
        """Play a specific card, if possible.

        Args:
            player_num (int): number of the player playing the card. Defaults
            to player 1, the user.
            card_to_play (Card): desired card to play
            set_suit (Optional[Suit], optional): suit to change the play to
            if the card being played is an eight. Defaults to spades.

        Returns:
            bool: True if the card was played, and False otherwise
        """
        player = self.players.get(player_num)
        if player.has(card_to_play) and self.playable(card_to_play):
            player.remove_from_hand(card_to_play)
            self.discard.append(card_to_play)

            if not player.has_cards():
                self.game_state = "Round {}".format(str(len(self.round_hist) + 1))
                self.reset_round()

            if card_to_play.get_rank() == Rank.EIGHT:
                self.curr_suit = set_suit

            return True
        return False
예제 #3
0
 def test_get_rank(self):
     card1 = Card(Rank.ACE, Suit.SPADES)
     self.assertEqual(card1.get_rank(), Rank.ACE)