class TestCards(unittest.TestCase): def setUp(self): self.deck = Deck(2) def test_all(self): cards = self.deck.deal(4) cards += self.deck.deal() cards.append(self.deck.deal_one())
for _ in xrange(nb_runs): # Give some cards for p in players + [dealer]: p.hand = Hand(deck.deal(2)) for p in players: stats_key = (Hand(dealer.hand[0]).name, p.hand.name) stats[stats_key]['count'] += 1 action = p.ask() if action == 'hit': p.hand.hit(deck.deal_one()) if player_hand.bust: stats[stats_key]['gains'] -= 1 continue while dealer_hand.sum < 17: dealer_hand.hit(deck.deal()) if dealer_hand.bust: stats[stats_key]['gains'] += 1 continue # Here nobody busted