Пример #1
0
    def test_on_playing_draw_4_next_player_takes_4_card(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [
            Card("RED", 5),
            Card("YELLOW", 4),
            Card("RED", 2),
            Card("GREEN", action="SKIP"),
            Card(wild="WILD_DRAW_FOUR")
        ]

        # Here the draw 4 card is the only valid play
        game.play_turn()
        self.assertTrue(game.top_card.is_d4)
        self.assertEqual(game.last_player_decision, "PLAY")

        game.current_player = 2  # Need to manually set it here for the tests

        # Next turn. This player should pick two cards
        game.play_turn()
        self.assertEqual(len(players[2].cards), 11)  # 7+4
Пример #2
0
    def test_player_plays_the_card_with_the_highest_value(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [
            Card("YELLOW", action="REVERSE"),
            Card("RED", 2),
            Card("GREEN", action="SKIP"),
            Card(wild="WILD"),
            Card("BLUE", action="DRAW_TWO")
        ]
        # Blue Draw two -> value = 20
        # Yellow Reverse -> Value = 20
        # Wild Draw Four -> value = 50l
        game.play_turn()
        self.assertTrue(game.top_card.is_wild_card)
        self.assertTrue(game.top_card.wild == "WILD")
Пример #3
0
    def test_player_should_play_draw_four_only_if_no_other_valid_cards(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [
            Card("YELLOW", action="REVERSE"),
            Card("RED", 2),
            Card("GREEN", action="SKIP"),
            Card(wild="WILD_DRAW_FOUR"),
            Card("BLUE", action="DRAW_TWO")
        ]
        # Blue Draw two -> value = 20
        # Yellow Reverse -> Value = 20
        # Wild Draw Four -> value = 50
        game.play_turn()

        # ALtghough Draw four is the card with the highest value but since we
        # can still play yellow reverse or blue draw two, draw four shouldn't be
        # played
        self.assertFalse(game.top_card.is_wild_card)
        self.assertFalse(game.top_card.is_d4)
Пример #4
0
    def test_wild_cards_played_should_have_a_color_associated_with_them(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [
            Card("RED", 5),
            Card("YELLOW", 4),
            Card("RED", 2),
            Card("GREEN", action="SKIP"),
            Card(wild="WILD")
        ]

        # Here the wild card is the only valid play
        game.play_turn()

        self.assertTrue(game.top_card.is_wild_card)
        self.assertTrue(game.top_card.color)  # Shouldn't be None
Пример #5
0
    def test_reverse_should_flip_direction_and_change_next_player(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [
            Card("RED", action="REVERSE"),
            Card("YELLOW", 4),
            Card("RED", 2),
            Card("GREEN", action="SKIP")
        ]

        # Here the reverse card is the only valid play
        game.play_turn()

        self.assertFalse(game.is_clockwise)
        self.assertEqual(game.next_player, 0)
Пример #6
0
    def test_winner_is_printed_when_a_game_ends(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]
        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [Card("BLUE", 5)]

        game.play_turn()
        self.assertEqual(game.winner, 1)
Пример #7
0
    def test_winner_name_is_printed(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        captured_out = io.StringIO()
        sys.stdout = captured_out

        game = Game(players, deck, disable_output=False)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[1].cards = [Card("BLUE", 5)]
        game.play_turn()

        sys.stdout = sys.__stdout__

        self.assertTrue("Winner: Sasuke" in captured_out.getvalue())
        self.assertTrue("GAME OVER" in captured_out.getvalue())
Пример #8
0
    def test_players_points_after_win(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]
        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="REVERSE")
        game.discard_pile = [Card("BLUE", action="REVERSE")]

        players[0].cards = [Card("RED", 2), Card("BLUE", action="SKIP")]
        players[2].cards = [
            Card(wild="WILD_DRAW_FOUR"),
            Card("YELLOW", 8),
            Card("GREEN", action="REVERSE")
        ]

        players[1].cards = [Card("BLUE", 5)]

        game.play_turn()
        self.assertEqual(players[1].score, 100)
Пример #9
0
    def test_skip_should_skip_the_next_player(self):
        players = [
            Player(name="Naruto", cards=[]),
            Player(name="Sasuke", cards=[]),
            Player(name="Sakura", cards=[])
        ]

        game = Game(players, deck, disable_output=True)

        # Overwriting variables for mocking
        game.top_card = Card("BLUE", action="SKIP")
        game.discard_pile = [Card("BLUE", action="SKIP")]

        players[1].cards = [
            Card("RED", action="REVERSE"),
            Card("YELLOW", 4),
            Card("RED", 2),
            Card("GREEN", action="SKIP")
        ]

        # The player has to play skip here as that is the only valid card
        game.play_turn()

        self.assertEqual(game.next_player, 0)