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
def test_impossible_bets_dpass_odds(): ''' Impossible to make Don't Pass/Come Odds bet without corresponding dpass/dcome bet existing ''' amount = 10 # Don't Pass odds strat = get_strat(0) bet = CBOdds(6, True, amount) with pytest.raises(IllegalBet): strat.add_bet(bet) # Don't Come odds strat = get_strat(0) strat.after_roll(R(1, 3)) assert strat.point == 4 bet = CBOdds(6, True, amount) with pytest.raises(IllegalBet): strat.add_bet(bet)
def test_bet_odds(): amount = 5 for point in {4, 5, 6, 8, 9, 10}: for is_dont_str in {'True', 'true', 'False', 'false'}: s = 'make bet odds %d %s %d done' % (point, is_dont_str, amount) ret = [_ for _ in parse(s)] assert len(ret) == 1 ret = ret[0] is_dont = is_dont_str.lower() == 'true' assert ret.bet == CBOdds(point, is_dont, amount)
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
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
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