Пример #1
0
def test_dpass_lose():
    amount = 5
    starting_bankroll = 0
    for roll in {R(3, 4), R(5, 6)}:
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(amount))
        evs = strat.after_roll(roll)
        # Should have a losing event
        assert len(evs) == 1
        assert isinstance(evs[0], CGEBetLost)
        assert evs[0].bet == CBDontPass(amount)
        # Dont Pass bet should be removed
        assert not len(strat.bets)
        assert strat.bankroll == starting_bankroll - amount
Пример #2
0
def test_dpass_win():
    amount = 5
    starting_bankroll = 0
    for roll in {R(1, 1), R(1, 2)}:
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(amount))
        evs = strat.after_roll(roll)
        # Should have a winning event
        assert len(evs) == 1
        assert isinstance(evs[0], CGEBetWon)
        assert evs[0].bet == CBDontPass(amount)
        # Dont Pass bet should be removed
        assert not len(strat.bets)
        # Bankroll be up
        assert strat.bankroll == starting_bankroll + amount
Пример #3
0
def test_dpass_point_nothing():
    amount = 5
    starting_bankroll = 0
    for first_roll in all_dice_combos():
        if first_roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(amount))
        evs = strat.after_roll(first_roll)
        # should establish point
        assert len(evs) == 1
        assert isinstance(evs[0], CGEPointEstablished)
        # DontPass bet should still exist
        assert len(strat.bets) == 1
        # point should be set
        assert strat.point == first_roll.value
        # roll all possibilites that aren't the point value (which would cause
        # a lose) or 7 (which would cause a win)
        for second_roll in all_dice_combos():
            if first_roll.value == second_roll.value:
                continue
            if second_roll.value == 7:
                continue
            evs = strat.after_roll(second_roll)
            # nothing should happen
            assert len(evs) == 0
            # point should be same
            assert strat.point is first_roll.value
            assert strat.bankroll == starting_bankroll - amount
            # bet should stay
            assert len(strat.bets) == 1
Пример #4
0
def test_dpass_point_lose():
    amount = 5
    starting_bankroll = 0
    for roll in all_dice_combos():
        if roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(amount))
        evs = strat.after_roll(roll)
        # should establish point
        assert len(evs) == 1
        assert isinstance(evs[0], CGEPointEstablished)
        # DontPass bet should still exist
        assert len(strat.bets) == 1
        # point should be set
        assert strat.point == roll.value
        # roll the point
        evs = strat.after_roll(roll)
        # should lose point
        assert len(evs) == 2
        assert len([e for e in evs if isinstance(e, CGEPointWon)]) == 1
        assert len([e for e in evs if isinstance(e, CGEBetLost)]) == 1
        # point should be none
        assert strat.point is None
        assert strat.bankroll == starting_bankroll - amount
        # bet should be gone
        assert not len(strat.bets)
Пример #5
0
def test_impossible_bets_dpass():
    ''' Can't make dpass bet if game has a point '''
    strat = get_strat(0)
    strat.after_roll(R(1, 3))
    assert strat.point == 4
    bet = CBDontPass(5)
    with pytest.raises(IllegalBet):
        strat.add_bet(bet)
Пример #6
0
def test_dpass_push():
    amount = 5
    starting_bankroll = 0
    strat = get_strat(starting_bankroll)
    strat.add_bet(CBDontPass(amount))
    evs = strat.after_roll(R(6, 6))
    assert len(evs) == 1
    assert isinstance(evs[0], CGEBetPush)
    assert not len(strat.bets)
    assert strat.bankroll == starting_bankroll
Пример #7
0
def test_dodds_win():
    flat_amount = 5
    amount = 30
    starting_bankroll = 0
    # Don't Pass odds
    for roll in all_dice_combos():
        if roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(flat_amount))
        # set point
        strat.after_roll(roll)
        assert strat.point == roll.value
        # make odds bet
        strat.add_bet(CBOdds(roll.value, True, amount))
        evs = strat.after_roll(R(3, 4))
        assert len([e for e in evs if isinstance(e, CGEBetWon)]) == 2
        assert not len(strat.bets)
        if roll.value in {4, 10}:
            expected = starting_bankroll + flat_amount + amount * 1 / 2
        elif roll.value in {5, 9}:
            expected = starting_bankroll + flat_amount + amount * 2 / 3
        else:
            expected = starting_bankroll + flat_amount + amount * 5 / 6
        assert strat.bankroll == expected
    # Don't Come odds
    for roll in all_dice_combos():
        if roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        # Set a point so come bets are legal
        strat.after_roll(R(2, 3 if roll.value != 5 else 2))
        assert strat.point is not None
        # Make that flat bet
        strat.add_bet(CBDontCome(flat_amount))
        # And set its point so a come odds bet is legal
        strat.after_roll(roll)
        # Hack to make sure its point is set
        assert sum([b.point for b in strat.bets
                    if isinstance(b, CBDontCome)]) == roll.value
        # Finally add the odds bet
        strat.add_bet(CBOdds(roll.value, True, amount))
        evs = strat.after_roll(R(3, 4))
        assert len([e for e in evs if isinstance(e, CGEBetWon)]) == 2
        assert not len(strat.bets)
        if roll.value in {4, 10}:
            expected = starting_bankroll + flat_amount + amount * 1 / 2
        elif roll.value in {5, 9}:
            expected = starting_bankroll + flat_amount + amount * 2 / 3
        else:
            expected = starting_bankroll + flat_amount + amount * 5 / 6
        assert strat.bankroll == expected
Пример #8
0
def test_bet_no_arg():
    amount = 5
    for b in {'pass', 'dont pass', 'come', 'dont come', 'field'}:
        s = 'make bet %s %d done' % (b, amount)
        ret = [_ for _ in parse(s)]
        assert len(ret) == 1
        ret = ret[0]
        assert ret.bet == {
            'pass': CBPass(amount),
            'dont pass': CBDontPass(amount),
            'come': CBCome(amount),
            'dont come': CBDontCome(amount),
            'field': CBField(amount),
        }[b]
Пример #9
0
def test_dpass_nothing():
    amount = 5
    starting_bankroll = 0
    for roll in all_dice_combos():
        if roll.value in {2, 3, 7, 11, 12}:
            continue
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(amount))
        evs = strat.after_roll(roll)
        # Should not have won or lost, just established a point or nothing
        assert len(evs) <= 1
        if len(evs):
            assert isinstance(evs[0], CGEPointEstablished)
        # Dont Pass bet should still exist
        assert len(strat.bets) == 1
        assert strat.bankroll == starting_bankroll - amount
Пример #10
0
def test_dodds_nothing():
    flat_amount = 5
    amount = 10
    starting_bankroll = 0
    for first_roll in {R(1, 3), R(1, 4), R(1, 5), R(2, 6), R(3, 6), R(4, 6)}:
        for second_roll in all_dice_combos():
            if second_roll.value in {first_roll.value, 7}:
                continue
            strat = get_strat(starting_bankroll)
            # Make flat bet
            strat.add_bet(CBDontPass(flat_amount))
            # Establish point so pass odds are legal
            strat.after_roll(first_roll)
            # Make odds bet
            strat.add_bet(CBOdds(first_roll.value, True, amount))
            evs = strat.after_roll(second_roll)
            assert not len([e for e in evs if isinstance(e, CGEBetWon)])
            assert not len([e for e in evs if isinstance(e, CGEBetLost)])
            assert len(strat.bets) == 2
            assert strat.bankroll == starting_bankroll - flat_amount - amount
Пример #11
0
def test_dodds_lose():
    flat_amount = 5
    amount = 10
    starting_bankroll = 0
    # Pass odds
    for roll in all_dice_combos():
        if roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        strat.add_bet(CBDontPass(flat_amount))
        # set point
        strat.after_roll(roll)
        assert strat.point == roll.value
        # make odds bet
        strat.add_bet(CBOdds(roll.value, True, amount))
        evs = strat.after_roll(roll)
        assert len([e for e in evs if isinstance(e, CGEBetLost)]) == 2
        assert not len(strat.bets)
        assert strat.bankroll == starting_bankroll - flat_amount - amount
    # Come odds
    for roll in all_dice_combos():
        if roll.value not in {4, 5, 6, 8, 9, 10}:
            continue
        strat = get_strat(starting_bankroll)
        # Set a point so come bets are legal
        strat.after_roll(R(2, 3 if roll.value != 5 else 2))
        assert strat.point is not None
        # Make that flat bet
        strat.add_bet(CBDontCome(flat_amount))
        # And set its point so a come odds bet is legal
        strat.after_roll(roll)
        # Hack to make sure its point is set
        assert sum([b.point for b in strat.bets
                    if isinstance(b, CBDontCome)]) == roll.value
        # Finally add the odds bet
        strat.add_bet(CBOdds(roll.value, True, amount))
        evs = strat.after_roll(roll)
        assert len([e for e in evs if isinstance(e, CGEBetLost)]) == 2
        assert not len(strat.bets)
        assert strat.bankroll == starting_bankroll - flat_amount - amount
Пример #12
0
def test_impossible_bets_off_dpass():
    ''' Cannot turn dpass off '''
    bet = CBDontPass(5)
    with pytest.raises(IllegalBetChange):
        bet.set_working(False)