Exemplo n.º 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() == []
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def two_player_played_all():
    s = State(2)
    s.can_roll = 6
    s.rolled_dice = []
    s.turn_sum = 400
    return s
Exemplo n.º 6
0
def two_player_state():
    s = State(2)
    s.turn_sum = 200
    s.can_roll = 2
    s.rolled_dice = [Dice(5)] * 4
    return s
Exemplo n.º 7
0
def two_player_can_score_all():
    s = State(2)
    s.can_roll = 5
    s.rolled_dice = [Dice(1)]
    s.turn_sum = 300
    return s
Exemplo n.º 8
0
def two_player_scored_1_5_5():
    s = State(2)
    s.can_roll = 3
    s.rolled_dice = [Dice(i) for i in range(2, 5)]
    s.turn_sum = 200
    return s
Exemplo n.º 9
0
def two_player_scored_1():
    s = State(2)
    s.can_roll = 5
    s.rolled_dice = [Dice(i) for i in range(2, 6)] + [Dice(5)]
    s.turn_sum = 100
    return s
Exemplo n.º 10
0
def two_player_just_rolled():
    s = State(2)
    s.turn_sum = 0
    s.can_roll = 0
    s.rolled_dice = [Dice(i) for i in range(1, 6)] + [Dice(5)]
    return s