Beispiel #1
0
def test_impossible_bets_dcome_point():
    ''' Making a dcome bet that has its own point set already should be illegal
    '''
    bet = CBDontCome(5)
    bet.set_point(9)
    strat = get_strat(0)
    # establish point so come bets are legal
    strat.after_roll(R(1, 3))
    with pytest.raises(IllegalBet):
        strat.add_bet(bet)
Beispiel #2
0
def test_impossible_bets_dcome():
    ''' Can't make dont come bet if game has no point '''
    strat = get_strat(0)
    bet = CBDontCome(5)
    assert strat.point is None
    with pytest.raises(IllegalBet):
        strat.add_bet(bet)
Beispiel #3
0
def test_dcome_lose():
    amount = 5
    starting_bankroll = 0
    for roll in {R(3, 4), R(5, 6)}:
        strat = get_strat(starting_bankroll)
        # set a point so come bets are legal
        strat.after_roll(R(2, 2))
        strat.add_bet(CBDontCome(amount))
        evs = strat.after_roll(roll)
        assert len([e for e in evs if isinstance(e, CGEBetLost)]) == 1
        assert not len(strat.bets)
        assert strat.bankroll == starting_bankroll - amount
Beispiel #4
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
Beispiel #5
0
def test_dcome_push():
    amount = 5
    starting_bankroll = 0
    strat = get_strat(starting_bankroll)
    strat.after_roll(R(2, 2))
    assert strat.point == 4
    strat.add_bet(CBDontCome(amount))
    assert strat.bankroll == starting_bankroll - 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
Beispiel #6
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]
Beispiel #7
0
def test_dcome_point_lose():
    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)
        # set a point so come bets are legal
        strat.after_roll(R(2, 2))
        strat.add_bet(CBDontCome(amount))
        evs = strat.after_roll(roll)
        assert len([e for e in evs if isinstance(e, CGEBetConverted)]) == 1
        evs = strat.after_roll(roll)
        assert len([e for e in evs if isinstance(e, CGEBetLost)]) == 1
        assert not len(strat.bets)
        assert strat.bankroll == starting_bankroll - amount
Beispiel #8
0
def test_dodds_push():
    flat_amount = 5
    amount = 10
    starting_bankroll = 0
    for dcome_point in {4, 5, 6, 8, 9, 10}:
        dcome_roll = R(int(dcome_point / 2),
                       int(dcome_point / 2) + dcome_point % 2)
        pass_point = 4 if dcome_point != 4 else 5
        pass_roll = R(2, 2 if pass_point == 4 else 3)
        strat = get_strat(starting_bankroll)
        # set a point so dcome bets are legal
        strat.after_roll(pass_roll)
        assert strat.point is pass_point
        # make a dcome bet and make it travel to its point
        strat.add_bet(CBDontCome(flat_amount))
        strat.after_roll(dcome_roll)
        # Make the dcome odds bet
        strat.add_bet(CBOdds(dcome_point, True, amount))
        assert len(strat.bets) == 2
        # Win the pass line point (no bet on it, just so puck goes off)
        strat.after_roll(pass_roll)
        assert strat.point is None
        # Dont Come odds should still be working (because that's how it's
        # coded. It isn't like real life where dealers will turn them off by
        # default) so we need to turn them off
        assert len(strat.bets) == 2
        for bet in [b for b in strat.bets if isinstance(b, CBOdds)]:
            assert bet.is_working
            bet.set_working(False)
        # Hack to assure the bet is off
        assert len([b for b in strat.bets if isinstance(b, CBOdds)]) == 1
        assert not sum(
            int(b.is_working) for b in strat.bets if isinstance(b, CBOdds))
        # Roll the Don't Come's point on come out roll. Don't Come will lose,
        # Don't Come Odds will push
        evs = strat.after_roll(dcome_roll)
        assert len([e for e in evs if isinstance(e, CGEBetPush)]) == 1
        assert not len(strat.bets)
        # Should be down just the flat amount. AKA should get the odds back in
        # our bankroll
        assert strat.bankroll == starting_bankroll - flat_amount
Beispiel #9
0
def test_dcome_point_nothing():
    amount = 5
    starting_bankroll = 0
    for first_roll in all_dice_combos():
        if first_roll.value in {2, 3, 7, 11, 12}:
            continue
        strat = get_strat(starting_bankroll)
        # set a point so come bets are legal
        strat.after_roll(R(2, 2))
        strat.add_bet(CBDontCome(amount))
        evs = strat.after_roll(first_roll)
        assert len([e for e in evs if isinstance(e, CGEBetConverted)]) == 1
        for second_roll in all_dice_combos():
            if second_roll.value in {first_roll.value, 7}:
                continue
            evs = strat.after_roll(second_roll)
            assert len(evs) <= 1
            if len(evs) == 1:
                assert isinstance(evs[0], CGEPoint)
            assert len(strat.bets) == 1
            assert strat.bankroll == starting_bankroll - amount
Beispiel #10
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
Beispiel #11
0
def test_impossible_bets_off_dcome():
    ''' Cannot turn dcome off '''
    bet = CBDontCome(5)
    with pytest.raises(IllegalBetChange):
        bet.set_working(False)