Example #1
0
 def setUp(self):
     self.mydeck = deck.Deck()
Example #2
0
    def play_round(self):
        """
        Plays a round.
        """

        # Create a deck of cards and shuffle it.
        self.deck = deck.Deck()
        self.deck.shuffle()

        # Deal cards and create kiddie.
        kiddie = self.deal_cards()

        # Keep track of the winning players and their cards.
        winners = []

        for player in self.players:
            print player, ':', player.hand
        print 'Kiddie', ':', kiddie

        # Start bidding process.
        bidding_player, current_bid = self.start_bidding()
        # Store the initial score to determine later if player made bid.
        bp_initial_score = self.score_board.get_score(bidding_player.name)

        # Determine the playing suit.
        playing_suit = bidding_player.select_suit()
        print 'Player %s has selected %s suit' % (bidding_player, playing_suit)

        # Initialize the starting player to bidder.
        starting_player = bidding_player

        # Give starting player the kiddie.
        for c in kiddie:
            starting_player.hand.add_card(c)

        # Allow players to throw out cards and get new cards.
        # Determine the order of the players.
        index = self.players.index(starting_player)
        ordered_players = self.players[index:] + self.players[:index]
        self.improve_cards(ordered_players, playing_suit)

        # Actually start playing!
        # 5 is the number of cards on each hand.
        for x in range(5):
            print "Starting player is", starting_player
            starting_player, winning_card = self.play_hand(starting_player,
                                                           playing_suit,
                                                           current_bid)
            winners.append((starting_player, winning_card))

        # Give the player with the highest card an additional 5 points.
        cards = [c for p, c in winners]
        highest_card = rules.get_highest_card_in_suit(playing_suit, cards)
        for p, c in winners:
            if c == highest_card:
                self.score_board.increment_score(p.name, 5)
                print p, 'had the highest card', c
                print 'Current score:'
                print self.score_board
                break

        # If bidding player didn't make bid, deduct the bid.
        bp_current_score = self.score_board.get_score(bidding_player.name)
        if bp_current_score - current_bid < bp_initial_score:
            print bidding_player, 'did NOT make his bid.'
            print ("Score before the adjustment: %d" %
                   self.score_board.get_score(bidding_player.name))
            self.score_board.set_score(bidding_player.name,
                                       bp_initial_score - current_bid)
            print ("Score after the adjustment: %d" %
                   self.score_board.get_score(bidding_player.name))
Example #3
0
 def test_different_order(self):
     d = deck.Deck()
     unshuffled_cards = list(d.cards)
     self.assertTrue(unshuffled_cards == d.cards)
     d.shuffle()
     self.assertFalse(unshuffled_cards == d.cards)