Ejemplo n.º 1
0
    def test_split_6(self):
        """Split sixes if dealer's card is two through six."""
        expected1 = True
        expected2 = False

        hand = cards.Hand([
            cards.Card(6, 2),
            cards.Card(6, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(6, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual1 = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected1, actual1)

        hand = cards.Hand([
            cards.Card(6, 2),
            cards.Card(6, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(7, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual2 = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected2, actual2)
Ejemplo n.º 2
0
Archivo: cli.py Proyecto: pji/blackjack
def dealer_only():
    ui = LogUI()
    g = game.Engine(ui=ui)
    loop = game.main(g)
    play = next(loop)
    while play:
        play = loop.send(play)
Ejemplo n.º 3
0
    def test_has_decision_methods(self):
        """The players created by make_player() should have the
        decision methods for Players, such as will_hit and
        will_insure.
        """
        # As long as no exception is raised, this test passes.
        phand = cards.Hand([
            cards.Card(11, 3),
            cards.Card(1, 2),
        ])
        dhand = cards.Hand([
            cards.Card(11, 3),
            cards.Card(1, 2),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, None, None, 2)
        player = players.make_player()

        methods = [
            player.will_hit,
            player.will_split,
            player.will_double_down,
        ]
        for method in methods:
            _ = method(phand, g)

        methods = [
            player.will_buyin,
            player.will_insure,
        ]
        for method in methods:
            _ = method(g)
Ejemplo n.º 4
0
    def test_always_true(self):
        """will_double_down_always() will always return True."""
        g = game.Engine()
        h = cards.Hand()
        p = players.Player()
        actual = willdoubledown.will_double_down_always(p, h, g)

        self.assertTrue(actual)
Ejemplo n.º 5
0
    def test_always_true(self):
        """will_buyin_always() will always return True."""
        g = game.Engine()
        p = players.Player()
        p.will_buyin = partial(willbuyin.will_buyin_always, None)
        actual = p.will_buyin(g)

        self.assertTrue(actual)
Ejemplo n.º 6
0
    def test_always_zero(self):
        """will_double_down_always() will always return the maximum
        bet, which is half of the game's buy in."""
        expected = 10

        h = cards.Hand()
        p = players.Player()
        g = game.Engine(None, None, (p, ), None, 20)
        actual = willinsure.will_insure_always(p, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 7
0
 def test_is_will_hit(self):
     """A will_hit function should accept a Player, a Hand, and a
     Game objects.
     """
     player = players.Player()
     hand = cards.Hand([
         cards.Card(11, 0),
         cards.Card(11, 3),
     ])
     g = game.Engine()
     _ = willhit.will_hit_dealer(player, hand, g)
Ejemplo n.º 8
0
    def test_stand(self, mock_input):
        """When the user chooses to split, will_split_user() returns
        False.
        """
        expected = False

        mock_input.return_value = model.IsYes(expected)
        g = game.Engine(None, None, None, None, None)
        actual = willsplit.will_split_user(None, None, g)

        mock_input.assert_called()
        self.assertEqual(expected, actual)
Ejemplo n.º 9
0
    def test_insure(self, mock_input):
        """When the user chooses to double down,
        will_insure_user() returns True.
        """
        expected = 10

        mock_input.return_value = model.IsYes('y')
        g = game.Engine(None, None, None, None, expected * 2)
        actual = willinsure.will_insure_user(None, g)

        mock_input.assert_called()
        self.assertEqual(expected, actual)
Ejemplo n.º 10
0
    def test_not_double_down(self, mock_input):
        """When the user chooses to double down,
        will_double_down_user() returns False.
        """
        expected = False

        mock_input.return_value = model.IsYes(expected)
        g = game.Engine(None, None, None, None, None)
        actual = willdoubledown.will_double_down_user(None, None, g)

        mock_input.assert_called()
        self.assertEqual(expected, actual)
Ejemplo n.º 11
0
    def test_hit(self, mock_input):
        """When the user chooses to hit, will_hit_user() returns
        True.
        """
        expected = True

        mock_input.return_value = model.IsYes(expected)
        ui = cli.TableUI()
        g = game.Engine(None, None, None, None, None)
        actual = willhit.will_hit_user(None, None, g)

        mock_input.assert_called()
        self.assertEqual(expected, actual)
Ejemplo n.º 12
0
    def test_parameters(self):
        """Functions that follow the will_double_down protocol should
        accept the following parameters: self, hand, game.
        """
        player = players.Player()
        hand = cards.Hand()
        g = game.Engine()

        _ = willdoubledown.will_double_down_always(player, hand, game)

        # The test was that no exception was raised when will_buyin
        # was called.
        self.assertTrue(True)
Ejemplo n.º 13
0
    def test_parameters(self):
        """Functions that follow the will_insure protocol should
        accept the following parameters: self, game.
        """
        player = players.Player()
        hand = cards.Hand()
        g = game.Engine()

        _ = willinsure.will_insure_never(player, g)

        # The test was that no exception was raised when will_buyin
        # was called.
        self.assertTrue(True)
Ejemplo n.º 14
0
Archivo: cli.py Proyecto: pji/blackjack
def one_player():
    ui = LogUI()
    play = True
    deck = cards.Deck.build(6)
    deck.shuffle()
    deck.random_cut()
    dealer = players.Dealer(name='Dealer')
    player = players.AutoPlayer(name='Player', chips=200)
    g = game.Engine(deck, dealer, (player, ), ui=ui, buyin=2)
    loop = game.main(g)
    play = next(loop)
    while play:
        play = loop.send(play)
Ejemplo n.º 15
0
    def test_parameters(self):
        """Functions that follow the will_buyin protocol should
        accept the following parameter: game.
        """
        player = players.Player()
        g = game.Engine()

        player.will_buyin = partial(willbuyin.will_buyin_always, None)
        player.will_buyin(game)

        # The test was that no exception was raised when will_buyin
        # was called.
        self.assertTrue(True)
Ejemplo n.º 16
0
    def test_random_insure(self, mock_choice):
        """When called, will_insure_random() should call
        random.choice() and return the result.
        """
        exp_result = 1
        exp_call = call(range(0, 1))

        g = game.Engine(buyin=2)
        act_result = willinsure.will_insure_random(None, g)
        act_call = mock_choice.mock_calls[-1]

        self.assertEqual(exp_result, act_result)
        self.assertEqual(exp_call, act_call)
Ejemplo n.º 17
0
    def test_double_down_on_10(self):
        """If player's hand is 10 and the dealer's card is a 9 or
        less, the player should double down.
        """
        expected = False

        phand = cards.Hand([
            cards.Card(4, 0),
            cards.Card(5, 0),
        ])
        player = players.Player((phand, ), 'Terry')
        dhand = cards.Hand([
            cards.Card(1, 0),
            cards.Card(8, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willdoubledown.will_double_down_recommended(player, phand, g)

        self.assertEqual(expected, actual)

        expected = False

        phand = cards.Hand([
            cards.Card(4, 0),
            cards.Card(5, 0),
        ])
        player = players.Player((phand, ), 'Terry')
        dhand = cards.Hand([
            cards.Card(7, 0),
            cards.Card(8, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willdoubledown.will_double_down_recommended(player, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 18
0
    def test_split_2_3_or_7(self):
        """Split twos, threes, and sevens if the dealer's card is
        seven or less.
        """
        expected1 = True
        expected2 = False

        hand = cards.Hand([
            cards.Card(2, 2),
            cards.Card(2, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(7, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual1 = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected1, actual1)

        hand = cards.Hand([
            cards.Card(2, 2),
            cards.Card(2, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(8, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual2 = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected2, actual2)
Ejemplo n.º 19
0
    def test_paramters(self):
        """Functions that follow the will_split protocol should
        accept the following parameters: hand, player, dealer,
        playerlist.
        """
        hand = cards.Hand()
        player = players.Player((hand, ), 'John Cleese')
        g = game.Engine()
        method = MethodType(willsplit.will_split_always, player)
        player.will_split = partial(willsplit.will_split_always, None)
        player.will_split(hand, g)

        # The test was that no exception was raised when will_split
        # was called.
        self.assertTrue(True)
Ejemplo n.º 20
0
Archivo: cli.py Proyecto: pji/blackjack
def four_player():
    p1 = players.AutoPlayer(name='John', chips=200)
    p2 = players.BetterPlayer(name='Michael', chips=200)
    p3 = players.NeverPlayer(name='Graham', chips=200)
    p4 = players.RandomPlayer(name='Terry', chips=200)
    ui = TableUI(seats=5)
    play = True
    deck = cards.Deck.build(6)
    deck.shuffle()
    deck.random_cut()
    dealer = players.Dealer(name='Dealer')
    g = game.Engine(deck, dealer, (p1, p2, p3, p4), ui=ui, buyin=2)
    loop = game.main(g)
    play = next(loop)
    while play:
        play = loop.send(play)
Ejemplo n.º 21
0
Archivo: cli.py Proyecto: pji/blackjack
def two_player():
    p1 = players.AutoPlayer(name='John', chips=200)
    p2 = players.BetterPlayer(name='Michael', chips=200)
    ui = LogUI()
    play = True
    deck = cards.Deck.build(6)
    deck.shuffle()
    deck.random_cut()
    dealer = players.Dealer(name='Dealer')
    g = game.Engine(deck, dealer, (
        p1,
        p2,
    ), ui=ui, buyin=2)
    loop = game.main(g)
    play = next(loop)
    while play:
        play = loop.send(play)
Ejemplo n.º 22
0
    def test_never_double_down(self):
        """will_double_down_never should always return False."""
        expected = False

        phand = cards.Hand([
            cards.Card(4, 0),
            cards.Card(6, 0),
        ])
        player = players.Player((phand, ), 'Terry')
        dhand = cards.Hand([
            cards.Card(11, 0),
            cards.Card(8, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willdoubledown.will_double_down_never(player, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 23
0
    def test_stand(self):
        """If the situation doesn't match the above criteria, stand."""
        expected = False

        phand = cards.Hand([
            cards.Card(10, 1),
            cards.Card(11, 2),
        ])
        player = players.Player((phand, ), 'John')
        dhand = cards.Hand([
            cards.Card(5, 1),
            cards.Card(2, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, 20)
        actual = willhit.will_hit_recommended(None, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 24
0
    def test_never_split(self):
        """will_split_never() should return False."""
        expected = False

        hand = cards.Hand([
            cards.Card(10, 2),
            cards.Card(10, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(7, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willsplit.will_split_never(player, hand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 25
0
    def test_double_down_if_11(self):
        """If the player's hand is 11, player should double down."""
        expected = True

        phand = cards.Hand([
            cards.Card(5, 0),
            cards.Card(6, 0),
        ])
        player = players.Player((phand, ), 'Terry')
        dhand = cards.Hand([
            cards.Card(11, 0),
            cards.Card(8, 3),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willdoubledown.will_double_down_recommended(player, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 26
0
    def test_stand(self):
        """will_hit_never() should never return True."""
        expected = False

        phand = cards.Hand([
            cards.Card(10, 1),
            cards.Card(11, 2),
        ])
        player = players.Player((phand, ), 'John')
        dhand = cards.Hand([
            cards.Card(5, 1),
            cards.Card(2, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, 20)
        actual = willhit.will_hit_never(None, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 27
0
    def test_split_ace_or_8(self):
        """Always split aces or eights."""
        expected = True

        hand = cards.Hand([
            cards.Card(1, 2),
            cards.Card(1, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(7, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 28
0
    def test_split_4_5_or_8(self):
        """Never split fours, fives, or eights."""
        expected = False

        hand = cards.Hand([
            cards.Card(10, 2),
            cards.Card(10, 1),
        ])
        player = players.Player((hand, ), 'Graham')
        dhand = cards.Hand([
            cards.Card(7, 3),
            cards.Card(10, 0, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, None)
        actual = willsplit.will_split_recommended(player, hand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 29
0
    def test_do_not_hit_soft_19(self):
        """If the player's hand is a soft 19, don't hit."""
        expected = False

        phand = cards.Hand([
            cards.Card(1, 1),
            cards.Card(6, 2),
            cards.Card(2, 2),
        ])
        player = players.Player((phand, ), 'John')
        dhand = cards.Hand([
            cards.Card(2, 1),
            cards.Card(2, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, 20)
        actual = willhit.will_hit_recommended(None, phand, g)

        self.assertEqual(expected, actual)
Ejemplo n.º 30
0
    def test_stand_bust(self):
        """If the hand is bust, stand."""
        expected = False

        phand = cards.Hand((
            cards.Card(8, 2),
            cards.Card(6, 1),
            cards.Card(2, 1),
            cards.Card(7, 2),
        ))
        player = players.Player((phand, ), 'John')
        dhand = cards.Hand([
            cards.Card(5, 1),
            cards.Card(2, 3, cards.DOWN),
        ])
        dealer = players.Dealer((dhand, ), 'Dealer')
        g = game.Engine(None, dealer, (player, ), None, 20)
        actual = willhit.will_hit_recommended(None, phand, g)

        self.assertEqual(expected, actual)