本文整理汇总了Python中table.Table.init_hand方法的典型用法代码示例。如果您正苦于以下问题:Python Table.init_hand方法的具体用法?Python Table.init_hand怎么用?Python Table.init_hand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类table.Table
的用法示例。
在下文中一共展示了Table.init_hand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPot
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import init_hand [as 别名]
class TestPot(unittest.TestCase):
"""Do we have a fully functional pot object?"""
def setUp(self):
self.p0 = Player('p0', 100)
self.p1 = Player('p1', 100)
self.p2 = Player('p2', 100)
self.p3 = Player('p3', 100)
self.p4 = Player('p4', 100)
self.p5 = Player('p5', 100)
self.s0 = Seat('s0')
self.s1 = Seat('s1')
self.s2 = Seat('s2')
self.s3 = Seat('s3')
self.s4 = Seat('s4')
self.s5 = Seat('s5')
players = [self.p0, self.p1, self.p2, self.p3, self.p4, self.p5]
seats = [self.s0, self.s1, self.s2, self.s3, self.s4, self.s5]
self.table = Table(seats, 5, 10, 0)
self.dealer = Dealer(self.table)
self.table.dealer = self.dealer
player = 0
for seat in seats:
seat.player = players[player]
seat.player.seat = seat
seat.active = True
seat.player.table = self.table
player += 1
self.table.init_hand()
def test_who_is_first_pre_flop(self):
"""Do we make the proper player act first pre-flop??"""
self.dealer.deal_hole()
self.assertTrue(self.table.seats[self.table.under_the_gun].player.action)
def test_who_is_first_post_flop(self):
"""Do we make the proper player act first post-flop"""
self.dealer.deal_hole()
self.table.seats[self.table.under_the_gun].player.action = False
self.dealer.deal()
self.assertTrue(self.table.seats[self.table.first].player.action)
def test_bet(self):
"""Can each player bet 50?"""
self.dealer.deal_hole()
i = 0
while i < 6:
i += 1
for seat in self.table.pots[-1].seats:
print(seat.player.name, seat.player.equity, seat.player.action)
if seat.player.action:
seat.player.bet(50)
self.table.pots[-1].betting_round()
break
print(seat.player.name, seat.player.equity, seat.player.action)
print(self.table.pots[-1].pot)
示例2: TestDealer
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import init_hand [as 别名]
class TestDealer(unittest.TestCase):
"""Do we have a functioning Dealer?"""
def setUp(self):
self.p1 = Player('p1', 100)
self.p2 = Player('p2', 100)
self.p3 = Player('p3', 0)
self.p4 = Player('p4', 100)
self.s1 = Seat('s1')
self.s2 = Seat('s2')
self.s3 = Seat('s3')
self.s4 = Seat('s4')
players = [self.p1, self.p2, self.p3, self.p4]
seats = [self.s1, self.s2, self.s3, self.s4]
self.table = Table(seats, 5, 10, 0)
self.dealer = Dealer(self.table)
self.table.dealer = self.dealer
player = 0
for seat in seats:
seat.player = players[player]
seat.player.seat = seat
seat.active = True
seat.player.table = self.table
player += 1
def test_deal_hole(self):
"""can the dealer deal two cards to each player??"""
self.table.seats[2].active = False
self.table.init_hand()
# only want the active players
players = []
for seat in self.table.seats:
if seat.active:
players.append(seat.player)
# active players should have cards
for player in players:
self.assertEqual(len(player.hole), 2)
# inactive players shouldn't have cards
self.assertEqual(len(self.table.seats[2].player.hole), 0)
示例3: TestTable
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import init_hand [as 别名]
#.........这里部分代码省略.........
self.p5.missed_big_blind = True
self.table.button = 2
self.table.small_blind = 3
self.table.big_blind = 0
self.table._button_move()
self.assertEqual(self.table.button, 0)
self.assertEqual(self.table.small_blind, 0)
self.assertEqual(self.table.big_blind, 1)
self.assertEqual(self.table.under_the_gun, 0)
def test_set_missed_bb(self):
"""Do we set the players missed bb appropriately?"""
self.table.button = 5
self.table.small_blind = 0
self.table.big_blind = 1
self.s2.active = False
self.table._button_move()
self.assertTrue(self.p2.missed_big_blind)
self.assertFalse(self.p2.missed_small_blind)
def test_set_missed_sb(self):
"""Do we set the players missed sb appropriatly?"""
self.table.button = 0
self.table.small_blind = 1
self.table.big_blind = 3
self.s2.active = False
self.p2.missed_big_blind = True
self.table._button_move()
self.assertTrue(self.p2.missed_small_blind)
def test_buying_the_button(self):
"""first active seat between buttons and sb should buy
the button, all others should be frozen"""
self.table.button = 0
self.p1.missed_big_blind = True
self.p2.missed_big_blind = True
self.table.small_blind = 3
self.table.big_blind = 4
self.table._reset_blinds()
self.assertTrue(self.table.bought_button == 1)
self.assertTrue(self.p2.frozen)
def test_button_buy_pays(self):
"""The bb and sb don't pay after a button buy"""
self.table.button = 0
self.table.bought_button = 1
self.table.small_blind = 2
self.table.big_blind = 3
self.table._create_pot()
self.assertTrue(self.p2.stack == 100)
self.assertTrue(self.p3.stack == 100)
self.assertTrue(self.p1.stack == 85)
def test_create_pot(self):
""" can we spawn a pot object properly? """
self.table.small_blind = 0
self.table.big_blind = 1
self.table.utg = 2
self.p0.missed_big_blind = True
self.p4.missed_big_blind = True
self.p4.missed_small_blind = True
pot = self.table._create_pot()
self.assertEqual(pot.pot, 40)
self.assertEqual(len(self.table.pots), 1)
self.assertEqual(pot.increment, self.table.big_blind_amount)
def test_reset_players(self):
""" Can we reset for a new hand??"""
self.table.seats[0].player.equity = 50
self.table.seats[0].player.hole = [1, 2, 3]
self.table._reset_players()
self.assertTrue(self.table.seats[0].player.equity == 0)
self.assertEqual(len(self.table.seats[0].player.hole), 0)
def test_reset_frozen_seat(self):
""" Can we reset dead button player to active"""
self.table.seats[4].active = False
self.table.seats[4].player.frozen = True
self.table._reset_players()
self.assertTrue(self.table.seats[4].active)
self.assertFalse(self.table.seats[4].player.frozen)
def test_remove_0_stack(self):
"""Does the table remove broke players at the start of a hand??"""
self.setUp()
self.table.seats[2].player.stack = 0
self.table._remove_0_stack()
self.assertFalse(self.table.seats[2].active)
def test_init_hand(self):
"""Does it all come together?"""
self.p0.stack = 0
self.table.init_hand()
self.assertTrue(self.table.pots[0].pot == 15)
self.assertEqual(len(self.p1.hole), 2)
示例4: TestAnalyzer
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import init_hand [as 别名]
class TestAnalyzer(unittest.TestCase):
def setUp(self):
self.p0 = Player('p0', 100)
self.p1 = Player('p1', 100)
self.p2 = Player('p2', 100)
self.p3 = Player('p3', 100)
self.p4 = Player('p4', 100)
self.p5 = Player('p5', 100)
self.s0 = Seat('s0')
self.s1 = Seat('s1')
self.s2 = Seat('s2')
self.s3 = Seat('s3')
self.s4 = Seat('s4')
self.s5 = Seat('s5')
players = [self.p0, self.p1, self.p2, self.p3, self.p4, self.p5]
seats = [self.s0, self.s1, self.s2, self.s3, self.s4, self.s5]
self.table = Table(seats, 5, 10, 0)
self.dealer = Dealer(self.table)
self.table.dealer = self.dealer
player = 0
for seat in seats:
seat.player = players[player]
seat.player.seat = seat
seat.active = True
seat.player.table = self.table
player += 1
self.table.init_hand()
self.dealer.deal()
self.dealer.deal()
self.dealer.deal()
self.analyzer = Analyzer(self.table)
def test_award(self):
"""can we award a single winner the entire pot?"""
players = [self.p2]
self.table.pots[0].pot = 100
self.p2.stack = 90
self.analyzer._award(players)
self.assertEqual(self.p2.stack, 190)
def test_award_multiple(self):
"""Can we pay out evenly to multiple winners?"""
players = [self.p2, self.p3]
self.table.pots[0].pot = 100
self.p2.stack = 50
self.p3.stack = 50
self.analyzer._award(players)
self.assertEqual(self.p2.stack, 100)
self.assertEqual(self.p3.stack, 100)
def test_award_indivisible(self):
"""Can we properly pay pots that don't divide
evenly?"""
players = [self.p2, self.p3]
self.table.first = 1
self.table.pots[0].pot = 105
self.p2.stack = 50
self.p3.stack = 50
self.analyzer._award(players)
self.assertEqual(self.p2.stack, 105)
self.assertEqual(self.p3.stack, 100)
def test_compare(self):
"""can we determine the winning hand"""
players = self.analyzer._setup()
self.p0.hand = [0, 14, 12, 11, 10, 8]
self.p1.hand = [1, 14, 12, 11, 8]
self.p2.hand = [7, 8, 14]
self.p3.hand = [7, 10, 2]
self.p4.hand = [0]
self.p5.hand = [0]
result = self.analyzer._compare(players)
expected = [self.p3]
self.assertEqual(expected, result)
def test_compare_multiple(self):
"""if there are multiple winners do we
return all of them?"""
players = self.analyzer._setup()
self.p0.hand = [0, 14, 12, 11, 10, 8]
self.p1.hand = [1, 14, 12, 11, 8]
self.p2.hand = [7, 10, 2]
self.p3.hand = [7, 10, 2]
self.p4.hand = [0]
self.p5.hand = [0]
result = self.analyzer._compare(players)
expected = [self.p2, self.p3]
#.........这里部分代码省略.........