示例#1
0
class TestBetting(unittest.TestCase):


    def setUp(self):
        self.betting = Betting(CrapsGame())


    def testSimple(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(d1_val=4, d2_val=3)
        self.assertTrue(self.betting.game.is_seven(), "msg")
        self.assertEqual(10, self.betting.check_winnings(), "msg")
        self.assertFalse(self.betting.play_come_bet(5), "msg")
        self.assertEqual(10, self.betting.check_winnings(), "msg")
        
    def testPassLine(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(d1_val=4, d2_val=3)
        self.assertEqual(10, self.betting.check_winnings(), "got %s not 10" % self.betting.check_winnings())
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(d1_val=4, d2_val=2)
        self.betting.play_pass_line_odds(10)
        self.betting.game.roll_dice(d1_val=4, d2_val=2)
        self.assertEqual(5 + 5 + 10 + 12, self.betting.check_winnings(), "32 != %s" % self.betting.check_winnings())
        
        
    def testCraps(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(d1_val=1, d2_val=2)
        self.assertTrue(self.betting.game.is_craps(), "msg")
        self.assertEqual(0, self.betting.check_winnings(), "msg")
        self.assertEqual(0, self.betting.pass_line_bet, "msg")
        
    def testPlaceBets(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(d1_val=1, d2_val=5)
        self.betting.place_the_number(8, 6)
        self.betting.game.roll_dice(d1_val=5, d2_val=3)
        self.assertEqual(7, self.betting.check_winnings(), "msg")
        
    def testComeBets(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(verbose=True, d1_val=1, d2_val=5)
        self.betting.play_pass_line_odds(10)
        self.betting.play_come_bet(5)
        self.betting.game.roll_dice(verbose=True, d1_val=2, d2_val=5)
        self.assertEqual(10, self.betting.check_winnings(), "msg")
        self.assertFalse(self.betting.play_come_bet(5), "msg")
        self.assertEqual(0, self.betting.num_come_bets(), "expecting 0 got %s" % self.betting.num_come_bets())
        self.betting.game.roll_dice(verbose=True, d1_val=1, d2_val=5)
        self.assertEqual(0, self.betting.check_winnings(), "msg")
        self.assertTrue(self.betting.play_come_bet(5), "msg")
        self.betting.game.roll_dice(verbose=True, d1_val=1, d2_val=3)
        self.assertEqual(0, self.betting.check_winnings(), "msg")  
        self.assertEqual(1, self.betting.num_come_bets(), "expected 1 got %s" % self.betting.num_come_bets())      
        self.assertTrue(self.betting.play_come_bet_odds(4, 10), "msg")
        self.betting.game.roll_dice(verbose=True, d1_val=2, d2_val=2)
        self.assertEqual(40, self.betting.check_winnings(verbose=True), "expected 40 got %s" % self.betting.check_winnings())        
      
    def testPlaceAndPass(self):
        self.betting.play_pass_line(5)
        self.betting.game.roll_dice(verbose=True, d1_val=1, d2_val=5)
        self.betting.check_winnings(verbose=True)
        self.betting.play_pass_line_odds(10)
        self.betting.place_the_number(4, 5)
        self.betting.place_the_number(5, 5)
        self.betting.place_the_number(8, 6)
        self.betting.place_the_number(9, 5)
        self.betting.place_the_number(10, 5)
        self.betting.game.roll_dice(verbose=True, d1_val=1, d2_val=4)
        self.betting.check_winnings(verbose=True)
        self.betting.game.roll_dice(verbose=True, d1_val=2, d2_val=4)
        self.assertEqual(32, self.betting.check_winnings(verbose=True), "got %s" % self.betting.check_winnings())
示例#2
0
#            print "before winnings s1 = %s, s2 = %s, s3 = %s" % (stake1, stake2, stake3)
            # Check the winnings
            win1 = across.check_winnings(verbose=False)
            if win1:
                stake1 += win1
            win2 = six_eight.check_winnings(verbose=False)
            if win2:
                stake2 += win2
            win3 = come.check_winnings(verbose=False)
            if win3:
                stake3 += win3
#            print "Roll<%s> s1 = %s, s2 = %s, s3 = %s" % (i, stake1, stake2, stake3)
            # make sure all come bets have odds
            for c_b in come.come_bets_wo_odds():
                if come.play_come_bet_odds(c_b, line_odds):
                    stake3 -= line_odds
                    if debug:
                        print "Come: come bet odds of %s on %s" % (line_odds, c_b)
            num_come_bets = come.num_come_bets()
            
        print "Ending Profits p1: %d, p2: %d p3: %d" % ((stake1 - atm1), (stake2 - atm2), (stake3 - atm3))
        profits1.append(stake1 - atm1)
        profits2.append(stake2 - atm2)
        profits3.append(stake3 - atm3)
       
#    print "Stake (min, mean, max) = (%s, %s, %s)" % (min(stakes), stats.mean(stakes), max(stakes))
#    print "ATM (min, mean, max) = (%s, %s, %s)" % (min(atms), stats.mean(atms), max(atms))
    print "Profits across (min, mean, max) = (%s, %.2f, %.2f, %s)" % (min(profits1), stats.median(profits1), stats.mean(profits1), max(profits1))
    print "Profits 6 and 8 (min, mean, max) = (%s, %.2f, %s)" % (min(profits2), stats.mean(profits2), max(profits2))
    print "Profits3 2 come bet (min, mean, max) = (%s, %.2f, %s)" % (min(profits3), stats.mean(profits3), max(profits3))
                    if debug:
                        print "pass line odds %s" % line_odds
            if stake > line_bet and num_come_bets < 3:
                if b.play_come_bet(line_bet):
                    num_come_bets += 1
                    stake -= line_bet
                    if debug:
                        print "come bet %s" % line_bet
            g.roll_dice(verbose=debug)
            for c_b in b.come_bets_wo_odds():
                if b.play_come_bet_odds(c_b, line_odds):
                    stake -= line_odds
                    if debug:
                        print "come bet odds of %s on %s" % (line_odds, c_b)

            num_come_bets = b.num_come_bets()

            if debug:
                print b.show_bets()
            win = b.check_winnings(verbose=debug)
            if win:
                stake += win
            if debug:
                print "Roll %s stake = %s" % (i, stake)

        print "Ending Stake = %s, ATM withdraws = %s" % (stake, atm)
        stakes.append(stake)
        atms.append(atm)
        profits.append(stake - atm)

    #    print "Stake (min, mean, max) = (%s, %s, %s)" % (min(stakes), stats.mean(stakes), max(stakes))