Example #1
0
    def test_enumerate_options_bankrupt(self):
        # simulate having only one die left and rolling a 3
        s = State(2)
        s.rolled_dice = [Dice(3)]
        s.can_roll = 0

        assert s.enumerate_options() == []
Example #2
0
 def test_enumerate_finds_straight(self):
     s = State(2)
     s.can_roll
     s.rolled_dice = [Dice(i) for i in range(1, 7)]
     actions = s.enumerate_options()
     want = Action({i: 1 for i in range(1, 7)}, "1-2-3-4-5-6", 3000)
     assert want in actions
Example #3
0
    def test_enumerate_roll_and_stop(self):
        # the condition for having roll and stop is if we've scored
        # any dice with the current roll
        s = State(2).roll()  # don't care what roll is, just that it sets can_roll to 0
        assert s.can_roll == 0

        actions = s.enumerate_options()
        roll = Action({}, "roll", 0)
        stop = Action({}, "stop", 0)
        assert roll not in actions
        assert stop not in actions

        # now change can_roll
        s.can_roll = 1
        actions2 = s.enumerate_options()
        assert roll in actions2
        assert stop in actions2
Example #4
0
    def test_enumerate_finds_three_pairs(self):
        s = State(2)
        s.rolled_dice = [Dice(2), Dice(2), Dice(3), Dice(3), Dice(4), Dice(4)]
        s.can_roll = 0
        actions = s.enumerate_options()

        want = [Action({2: 2, 3: 2, 4: 2}, "Three pairs", 1500)]
        assert len(actions) == len(want)
        assert all(a in want for a in actions)
Example #5
0
    def test_enumerate_finds_three_singles(self):
        s = State(2)
        s.can_rol = 0

        for num in range(1, 7):
            other = 2 if num != 2 else 3
            s.rolled_dice = [Dice(num)] * 3 + [Dice(other)] * 3
            actions = s.enumerate_options()
            points = 1000 if num == 1 else num * 100
            want = Action({num: 3}, f"Three {num}'s", points)
            assert want in actions
Example #6
0
 def test_enumerate_finds_four_five_six_kind(self):
     s = State(2)
     s.can_roll = 0
     for num in range(1, 7):
         for n in range(4, 7):
             other = 2 if num != 2 else 3
             s.rolled_dice = [Dice(num)] * n + [Dice(other)] * (6 - n)
             actions = s.enumerate_options()
             name = {4: "Four", 5: "Five", 6: "Six"}[n]
             points = {4: 1000, 5: 2000, 6: 3000}[n]
             want = Action({num: n}, f"{name} {num}'s", points)
             assert want in actions