class TestBrainBets(unittest.TestCase): """Checks the predefined bets""" def setUp(self): bot = MockBot() self.brain = Brain(bot) d = MockData() d.big_blind = 20 d.pot = 130 self.brain.data = d def verify_bet(self, bet, bottom, top): self.assertTrue(bet >= bottom) self.assertTrue(bet <= top) def test_big_raise(self): """Tests the big bet range""" bet = self.brain.big_raise() pot = self.brain.data.pot self.verify_bet(bet, pot * 0.3, pot * 0.5) def test_minimum_bet(self): """Tests the minimum bet range""" bb = self.brain.data.big_blind bet = self.brain.minimum_bet() self.verify_bet(bet, bb * 2, bb * 4)
def brain(self): bot = MockBot() brain = Brain(bot) def r_test(one=None, two=None, three=None): return False brain.r_test = r_test brain.data = self.data return bot, brain
def setUp(self): bot = MockBot() self.brain = Brain(bot) self.brain.r_test = lambda x: False d = MockData() d.big_blind = 20 d.pot = 130 self.brain.data = d
def test_preflop_betting(self): """Sanity test of the preflop betting""" bot = MockBot() brain = Brain(bot) brain.data = self.data self.assertEqual(brain.pot_odds(), 12.5) # 20 to call, 140 in the pot brain.do_turn(1000) self.assertTrue(bot.raise_amount > 0) # shouldn't fold with a pair of aces
def test_river_betting(self): """Sanity tests of betting with common cards""" self.data.table_cards = [Card(C.ACE, C.SPADES), Card(2, C.DIAMONDS), Card(7, C.SPADES)] bot = MockBot() brain = Brain(bot) brain.data = self.data brain.iterations = 100 # smaller for unit tests brain.do_turn(500) self.assertTrue(bot.raise_amount > 0)
def setUp(self): bot = MockBot() self.brain = Brain(bot) d = MockData() d.big_blind = 20 d.pot = 130 self.brain.data = d
class TestBrainBets(unittest.TestCase): """Checks the predefined bets""" def setUp(self): bot = MockBot() self.brain = Brain(bot) self.brain.r_test = lambda x: False d = MockData() d.big_blind = 20 d.pot = 130 self.brain.data = d def verify_bet(self, bet, bottom, top): self.assertTrue(bet >= bottom) self.assertTrue(bet <= top) def test_big_raise(self): """Tests the big bet range""" pot = self.brain.data.pot self.brain.data.table_cards = [1] bet = self.brain.big_raise() self.verify_bet(bet, pot * 0.8, pot * 1.5) self.brain.data.table_cards = [] bet2 = self.brain.big_raise() bb = self.brain.data.big_blind self.verify_bet(bet2, bb * 3, bb * 5) def test_minimum_bet(self): """Tests the minimum bet range""" bb = self.brain.data.big_blind self.brain.data.table_cards = [] bet = self.brain.minimum_bet() self.verify_bet(bet, bb, bb * 3) self.brain.data.table_cards = [1] bet2 = self.brain.minimum_bet() pot = self.brain.data.pot self.verify_bet(bet2, pot * 0.16, pot * 0.4) def test_all_in(self): """Make sure an almost all-in bet is increased""" self.brain.data.stacks[self.brain.data.me] = 1000 bet = self.brain.finalize_bet(900) self.assertEqual(bet, 1000) def test_bet_rounding(self): """Make sure we round bets to nearest chip""" self.assertEqual(self.brain.finalize_bet(83.25), 83) self.assertEqual(self.brain.finalize_bet(85.55), 86)
def add_brain(self): self.brain = Brain(self)