Ejemplo n.º 1
0
    def test_calculate_result_split_noneace(self):
        """Test result for split without aces
        """
        d = Deck(4)
        d.shuffle()
        d.cut()

        player_hand = Hand()
        player_hand.add_card(Card("Spades", "2"))
        player_hand.add_card(Card("Clubs", "2"))

        dealer_hand = Hand()
        dealer_hand.add_card(Card("Spades", "10"))
        dealer_hand.add_card(Card("Hearts", "3"))

        strategy = BasicStrategy(d)

        game = Game(d, strategy)
        game.calculate_results(player_hand, dealer_hand)
        game.display_results()
        self.assertGreaterEqual(len(strategy.split_hands), 2)
        self.assertEqual(
            game.game_info["losses"] + game.game_info["wins"] + game.game_info["ties"], 2)
Ejemplo n.º 2
0
    def test_calculate_result_split_ace(self):
        """Test result for split
        """
        d = Deck(4)
        d.shuffle()
        d.cut()

        player_hand = Hand()
        player_hand.add_card(Card("Spades", "A"))
        player_hand.add_card(Card("Clubs", "A"))

        dealer_hand = Hand()
        dealer_hand.add_card(Card("Spades", "10"))
        dealer_hand.add_card(Card("Hearts", "3"))

        strategy = BasicStrategy(d)

        game = Game(d, strategy)
        game.calculate_results(player_hand, dealer_hand)
        game.display_results()
        self.assertGreaterEqual(len(strategy.split_hands), 2)
        self.assertEqual(len(strategy.split_hands[0].cards), 2)
        self.assertEqual(len(strategy.split_hands[1].cards), 2)
Ejemplo n.º 3
0
    def test_calculate_earnings(self):
        d = Deck(4)
        d.shuffle()
        d.cut()

        h1 = Hand()
        h1.add_card(Card("Spades", "2"))
        h1.add_card(Card("Clubs", "2"))
        h1.add_bet(5.0)

        h2 = Hand()
        h2.add_card(Card("Spades", "2"))
        h2.add_card(Card("Clubs", "A"))
        h2.add_bet(5.0)

        h3 = Hand()
        h3.add_card(Card("Spades", "2"))
        h3.add_card(Card("Clubs", "J"))
        h3.add_bet(5.0)

        h4 = Hand()
        h4.add_card(Card("Spades", "2"))
        h4.add_card(Card("Clubs", "Q"))
        h4.add_bet(5.0)

        h5 = Hand()
        h5.add_card(Card("Spades", "2"))
        h5.add_card(Card("Clubs", "K"))
        h5.add_bet(5.0)

        strategy = BasicStrategy(d)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h1, WIN, False)
        self.assertEqual(earnings, 5.0)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h1, LOSS, False)
        self.assertEqual(earnings, 5.0)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h1, WIN, True)
        self.assertEqual(earnings, 5.0)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h2, WIN, False)
        self.assertEqual(earnings, 7.5)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h3, WIN, False)
        self.assertEqual(earnings, 7.5)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h4, WIN, False)
        self.assertEqual(earnings, 7.5)

        game = Game(d, strategy)
        earnings = game.calculate_earnings(h5, WIN, False)
        self.assertEqual(earnings, 7.5)
Ejemplo n.º 4
0
 def test_dealer_strategy_generic(self):
     dealer_hand = Hand()
     dealer_hand.add_card(Card("Spades", "J"))
     dealer_hand.add_card(Card("Clubs", "A"))
     self.strategy.play(dealer_hand)
     self.assertEqual(len(dealer_hand.cards), 2)
Ejemplo n.º 5
0
 def test_dealer_strategy_with_ace(self):
     dealer_hand = Hand()
     dealer_hand.add_card(Card("Spades", "2"))
     dealer_hand.add_card(Card("Clubs", "A"))
     self.strategy.play(dealer_hand)
     self.assertGreaterEqual(len(dealer_hand.cards), 3)