Esempio n. 1
0
def test_pool_add_card_1():
    """Adding 1 card to pool"""
    player1 = Player('Player1', Hand())
    card1 = Card('D', 'A')
    pool = Pool()
    pool.add_card(card1, player1)
    assert str(pool) == '[D-A :: Player1]'
Esempio n. 2
0
def pool_with_diff_value_card():
    """setting pool with different value cards."""
    card1, card2 = Card('D', '5'), Card('S', '8')
    player1, player2 = Player('Player1', Hand()), Player('Player2', Hand())
    player1.hand.add_card(card1)
    player2.hand.add_card(card2)
    pool = Pool()
    pool.add_card(player1.hand.take_top(), player1)
    pool.add_card(player2.hand.take_top(), player2)
    return pool
Esempio n. 3
0
def test_pool_winner_cards_value_same():
    """Pool winner is None when card value same"""
    player1 = Player('Player1', Hand())
    card1 = Card('D', '5')
    player2 = Player('Player2', Hand())
    card2 = Card('S', '5')
    pool = Pool()
    pool.add_card(card1, player1)
    pool.add_card(card2, player2)
    assert pool.winner is None
Esempio n. 4
0
def test_pool_winner_cards_value_differ():
    """Pool winner when card value differ"""
    player1 = Player('Player1', Hand())
    card1 = Card('D', '5')
    player2 = Player('Player2', Hand())
    card2 = Card('S', '8')
    pool = Pool()
    pool.add_card(card1, player1)
    pool.add_card(card2, player2)
    assert pool.winner.name == 'Player2'
Esempio n. 5
0
def pool_with_same_value_card():
    """setting pool with some same value cards."""
    player1, player2 = Player('Player1', Hand()), Player('Player2', Hand())
    player1.hand.cards = [
        Card('D', 'A'),
        Card('D', '8'),
        Card('H', '3'),
        Card('S', '9'),
        Card('C', 'Q')
    ]
    player2.hand.cards = [
        Card('H', 'A'),
        Card('C', 'J'),
        Card('H', '2'),
        Card('S', '2'),
        Card('S', 'A')
    ]
    pool = Pool()
    pool.add_card(player1.hand.take_top(), player1)
    pool.add_card(player2.hand.take_top(), player2)
    pool.add_bonus([
        player1.hand.take_top(),
        player1.hand.take_top(),
        player1.hand.take_top(),
        player2.hand.take_top(),
        player2.hand.take_top(),
        player2.hand.take_top()
    ])
    pool.add_card(player1.hand.take_top(), player1)
    pool.add_card(player2.hand.take_top(), player2)

    return pool
Esempio n. 6
0
def test_player_drop_bonus_have_more_than_3_cards(players):
    """Player drops 3 cards to bonus bucket of pool, when hand has more than 3 cards."""
    player1 = players[0]
    pool = Pool()
    player1.drop_bonus(pool, 3)
    assert len(player1.hand.cards) == 2
    assert len(pool.bonus) == 3
Esempio n. 7
0
def test_player_drop_card_empty_hand():
    """Empty hand drop card to pool."""
    player1 = Player('Player1', Hand())
    pool = Pool()
    player1.drop_card(pool)
    assert len(pool.cards) == 0
    assert len(player1.hand.cards) == 0
Esempio n. 8
0
def test_player_drop_card(players):
    """ Players drop cards to pool. Decreases the each player hand by 1"""
    pool = Pool()
    players[0].drop_card(pool)
    players[1].drop_card(pool)
    assert len(players[0].hand.cards) == len(players[1].hand.cards) == 4
    assert len(pool.cards) == 2
Esempio n. 9
0
def test_player_drop_bonus_have_less_than_3_cards():
    """Player drops number of cards in hand to bonus bucket, when hand has less than 3 cards."""
    player1 = Player('Player1', Hand())
    player1.hand.cards = [Card('D', 'A'), Card('D', '8')]
    pool = Pool()
    player1.drop_bonus(pool, 3)
    assert len(player1.hand.cards) == 0
    assert len(pool.bonus) == 2
Esempio n. 10
0
    def play_once(self, tied=False):
        """
        Called in every round of the game. Its recursively called until there is a winner.
        @param tied: Checks if the round is tied or not. The value can be None or Player
        @return: returns the winner.
        """
        if tied is False:
            self.count_round()
        else:
            print('..Its a Tie..')
        pool = Pool()

        for player in self.players:
            if tied:
                player.drop_bonus(pool, 3)
            player.drop_card(pool)
        winner = pool.winner
        if winner is not None:
            pool.reward(winner)
            print('**** Round winner is {} ****'.format(winner.name))
        else:
            winner = self.play_once(pool.tied)
            pool.reward(winner)

        return winner
Esempio n. 11
0
def test_pool_add_bonus_when_tie():
    """Adding cards to bonus bucket of pool."""
    player1 = Player('Player1', Hand())
    card1 = Card('D', '5')
    player2 = Player('Player2', Hand())
    card2 = Card('C', '5')
    pool = Pool()
    pool.add_card(card1, player1)
    pool.add_card(card2, player2)
    cards = [Card('H', '6'), Card('S', '8'), Card('D', '6')]
    pool.add_bonus(cards)
    assert len(pool.bonus) == len(cards)
Esempio n. 12
0
def test_pool_add_card_multiple():
    """ Adding multiple cards to pool using add_card """
    player1 = Player('Player1', Hand())
    card1 = Card('D', 'A')
    player2 = Player('Player2', Hand())
    card2 = Card('C', '5')
    player3 = Player('Player3', Hand())
    card3 = Card('S', '10')
    pool = Pool()
    pool.add_card(card1, player1)
    pool.add_card(card2, player2)
    pool.add_card(card3, player3)
    assert str(pool) == '[D-A :: Player1, C-5 :: Player2, S-10 :: Player3]'
Esempio n. 13
0
def test_pool_empty_initialization():
    """Empty pool initialization"""
    pool = Pool()
    assert len(pool.cards) == 0
    assert len(pool.players) == 0
    assert len(pool.bonus) == 0
Esempio n. 14
0
def test_pool_tied():
    """Pool is tied"""
    pool = Pool()
    assert pool.tied