def test_start_new_round_exclude_no_money_players(self): uuids = ["ruypwwoqwuwdnauiwpefsw", "sqmfwdkpcoagzqxpxnmxwm", "uxrdiwvctvilasinweqven"] game_state = restore_game_state(ThreePlayerGameStateSample.round_state) original = reduce(lambda state, uuid: attach_hole_card_from_deck(state, uuid), uuids, game_state) sb_amount, ante = 5, 7 self.emu.set_game_rule(3, 10, sb_amount, ante) [self.emu.register_player(uuid, FoldMan()) for uuid in uuids] # case1: second player cannot pay small blind finish_state, events = self.emu.apply_action(original, "fold") finish_state["table"].seats.players[0].stack = 11 stacks = [p.stack for p in finish_state["table"].seats.players] game_state, events = self.emu.start_new_round(finish_state) self.eq(2, game_state["table"].dealer_btn) self.eq(1, game_state["next_player"]) self.eq(stacks[1] - sb_amount - ante, game_state["table"].seats.players[1].stack) self.eq(stacks[2] - sb_amount * 2 - ante, game_state["table"].seats.players[2].stack) self.eq(PayInfo.FOLDED, game_state["table"].seats.players[0].pay_info.status) self.eq(sb_amount * 3 + ante * 2, GameEvaluator.create_pot(game_state["table"].seats.players)[0]["amount"]) # case2: third player cannot pay big blind finish_state, events = self.emu.apply_action(original, "fold") finish_state["table"].seats.players[1].stack = 16 stacks = [p.stack for p in finish_state["table"].seats.players] game_state, events = self.emu.start_new_round(finish_state) self.eq(2, game_state["table"].dealer_btn) self.eq(0, game_state["next_player"]) self.eq(stacks[0] - sb_amount - ante, game_state["table"].seats.players[0].stack) self.eq(stacks[2] - sb_amount * 2 - ante, game_state["table"].seats.players[2].stack) self.eq(PayInfo.FOLDED, game_state["table"].seats.players[1].pay_info.status) self.eq(PayInfo.PAY_TILL_END, game_state["table"].seats.players[0].pay_info.status) self.eq(sb_amount * 3 + ante * 2, GameEvaluator.create_pot(game_state["table"].seats.players)[0]["amount"])
def test_start_new_round_exclude_no_money_players(self): uuids = ["ruypwwoqwuwdnauiwpefsw", "sqmfwdkpcoagzqxpxnmxwm", "uxrdiwvctvilasinweqven"] game_state = restore_game_state(ThreePlayerGameStateSample.round_state) original = reduce(lambda state, uuid: attach_hole_card_from_deck(state, uuid), uuids, game_state) sb_amount, ante = 5, 7 self.emu.set_game_rule(3, 10, sb_amount, ante) [self.emu.register_player(uuid, FoldMan()) for uuid in uuids] # case1: second player cannot pay small blind finish_state, events = self.emu.apply_action(original, "fold") finish_state["table"].seats.players[0].stack = 11 stacks = [p.stack for p in finish_state["table"].seats.players] game_state, events = self.emu.start_new_round(finish_state) self.eq(2, game_state["table"].dealer_btn) self.eq(1, game_state["next_player"]) self.eq(stacks[1]-sb_amount-ante, game_state["table"].seats.players[1].stack) self.eq(stacks[2]-sb_amount*2-ante, game_state["table"].seats.players[2].stack) self.eq(PayInfo.FOLDED, game_state["table"].seats.players[0].pay_info.status) self.eq(sb_amount*3 + ante*2, GameEvaluator.create_pot(game_state["table"].seats.players)[0]["amount"]) # case2: third player cannot pay big blind finish_state, events = self.emu.apply_action(original, "fold") finish_state["table"].seats.players[1].stack = 16 stacks = [p.stack for p in finish_state["table"].seats.players] game_state, events = self.emu.start_new_round(finish_state) self.eq(2, game_state["table"].dealer_btn) self.eq(0, game_state["next_player"]) self.eq(stacks[0]-sb_amount-ante, game_state["table"].seats.players[0].stack) self.eq(stacks[2]-sb_amount*2-ante, game_state["table"].seats.players[2].stack) self.eq(PayInfo.FOLDED, game_state["table"].seats.players[1].pay_info.status) self.eq(PayInfo.PAY_TILL_END, game_state["table"].seats.players[0].pay_info.status) self.eq(sb_amount*3 + ante*2, GameEvaluator.create_pot(game_state["table"].seats.players)[0]["amount"])
def encode_pot(self, players): pots = GameEvaluator.create_pot(players) main = {"amount": pots[0]["amount"]} gen_hsh = lambda sidepot: \ {"amount": sidepot["amount"], "eligibles": [p.uuid for p in sidepot["eligibles"]]} side = [gen_hsh(sidepot) for sidepot in pots[1:]] return {"main": main, "side": side}
def encode_pot(self, players): pots = GameEvaluator.create_pot(players) main = { "amount": pots[0]["amount"] } gen_hsh = lambda sidepot: \ { "amount": sidepot["amount"], "eligibles": [p.uuid for p in sidepot["eligibles"]] } side = [ gen_hsh(sidepot) for sidepot in pots[1:] ] return { "main": main, "side": side }
def test_collect_ante_skip_loser(self): ante = 10 sb_amount = 5 table = self.__setup_table() table.seats.players[2].stack = 0 table.seats.players[2].pay_info.status = PayInfo.FOLDED state, _ = RoundManager.start_new_round(1, sb_amount, ante, table) players = state["table"].seats.players self.eq(sb_amount + sb_amount * 2 + ante * 2, GameEvaluator.create_pot(players)[0]["amount"])
def test_collect_ante_skip_loser(self): ante = 10 sb_amount = 5 table = self.__setup_table() table.seats.players[2].stack = 0 table.seats.players[2].pay_info.status = PayInfo.FOLDED state, _ = RoundManager.start_new_round(1, sb_amount, ante, table) players = state["table"].seats.players self.eq(sb_amount+sb_amount*2+ante*2, GameEvaluator.create_pot(players)[0]["amount"])
def test_case2(self): players = { "A": self.__create_player_with_pay_info("A", 10, PayInfo.PAY_TILL_END), "B": self.__create_player_with_pay_info("B", 10, PayInfo.PAY_TILL_END), "C": self.__create_player_with_pay_info("C", 7, PayInfo.ALLIN), } pots = GameEvaluator.create_pot(players.values()) self.eq(2, len(pots)) self.__sidepot_check(players, pots[0], 21, ["A", "B", "C"]) self.__sidepot_check(players, pots[1], 6, ["A", "B"])
def test_case3(self): players = { "A": self.__create_player_with_pay_info("A", 20, PayInfo.FOLDED), "B": self.__create_player_with_pay_info("B", 30, PayInfo.PAY_TILL_END), "C": self.__create_player_with_pay_info("C", 7, PayInfo.ALLIN), "D": self.__create_player_with_pay_info("D", 30, PayInfo.PAY_TILL_END), } pots = GameEvaluator.create_pot(players.values()) self.eq(2, len(pots)) self.__sidepot_check(players, pots[0], 28, ["B", "C", "D"]) self.__sidepot_check(players, pots[1], 59, ["B", "D"])
def test_case1(self): players = { 'A': self.__create_player_with_pay_info('A', 50, PayInfo.PLAY_TILL_END), 'B': self.__create_player_with_pay_info('B', 20, PayInfo.ALLIN), 'C': self.__create_player_with_pay_info('C', 30, PayInfo.ALLIN), } pots = GameEvaluator.create_pot(players.values()) self.eq(3, len(pots)) self.__sidepot_check(players, pots[0], 60, ['A', 'B', 'C']) self.__sidepot_check(players, pots[1], 20, ['A', 'C']) self.__sidepot_check(players, pots[2], 20, ['A'])
def encode_pot(self, players): pots = GameEvaluator.create_pot(players) main = {'amount': pots[0]['amount']} def gen_hsh(sidepot): return { 'amount': sidepot['amount'], 'eligibles': [p.uuid for p in sidepot['eligibles']] } side = [gen_hsh(sidepot) for sidepot in pots[1:]] return {'main': main, 'side': side}
def test_case5(self): players = { "A": self.__create_player_with_pay_info("A", 5, PayInfo.ALLIN), "B": self.__create_player_with_pay_info("B", 10, PayInfo.PAY_TILL_END), "C": self.__create_player_with_pay_info("C", 8, PayInfo.ALLIN), "D": self.__create_player_with_pay_info("D", 10, PayInfo.PAY_TILL_END), "E": self.__create_player_with_pay_info("E", 2, PayInfo.FOLDED) } pots = GameEvaluator.create_pot(players.values()) self.eq(3, len(pots)) self.__sidepot_check(players, pots[0], 22, ["A", "B", "C", "D"]) self.__sidepot_check(players, pots[1], 9, ["B", "C", "D"]) self.__sidepot_check(players, pots[2], 4, ["B", "D"])
def test_case5(self): players = { 'A': self.__create_player_with_pay_info('A', 5, PayInfo.ALLIN), 'B': self.__create_player_with_pay_info('B', 10, PayInfo.PLAY_TILL_END), 'C': self.__create_player_with_pay_info('C', 8, PayInfo.ALLIN), 'D': self.__create_player_with_pay_info('D', 10, PayInfo.PLAY_TILL_END), 'E': self.__create_player_with_pay_info('E', 2, PayInfo.FOLDED) } pots = GameEvaluator.create_pot(players.values()) self.eq(3, len(pots)) self.__sidepot_check(players, pots[0], 22, ['A', 'B', 'C', 'D']) self.__sidepot_check(players, pots[1], 9, ['B', 'C', 'D']) self.__sidepot_check(players, pots[2], 4, ['B', 'D'])
def test_case3(self): players = { 'A': self.__create_player_with_pay_info('A', 20, PayInfo.FOLDED), 'B': self.__create_player_with_pay_info('B', 30, PayInfo.PLAY_TILL_END), 'C': self.__create_player_with_pay_info('C', 7, PayInfo.ALLIN), 'D': self.__create_player_with_pay_info('D', 30, PayInfo.PLAY_TILL_END), } pots = GameEvaluator.create_pot(players.values()) self.eq(2, len(pots)) self.__sidepot_check(players, pots[0], 28, ['B', 'C', 'D']) self.__sidepot_check(players, pots[1], 59, ['B', 'D'])
def test_collect_ante(self): ante = 10 sb_amount = 5 table = self.__setup_table() state, _ = RoundManager.start_new_round(1, sb_amount, ante, table) players = state["table"].seats.players self.eq(100-sb_amount-ante, players[0].stack) self.eq(100-sb_amount*2-ante, players[1].stack) self.eq(100-ante, players[2].stack) self.eq("ANTE", players[0].action_histories[0]["action"]) self.eq("ANTE", players[1].action_histories[0]["action"]) self.eq("ANTE", players[2].action_histories[0]["action"]) self.eq(sb_amount+ante, players[0].pay_info.amount) self.eq(sb_amount*2+ante, players[1].pay_info.amount) self.eq(ante, players[2].pay_info.amount) self.eq(sb_amount+sb_amount*2+ante*3, GameEvaluator.create_pot(players)[0]["amount"])
def test_collect_ante(self): ante = 10 sb_amount = 5 table = self.__setup_table() state, _ = RoundManager.start_new_round(1, sb_amount, ante, table) players = state["table"].seats.players self.eq(100 - sb_amount - ante, players[0].stack) self.eq(100 - sb_amount * 2 - ante, players[1].stack) self.eq(100 - ante, players[2].stack) self.eq("ANTE", players[0].action_histories[0]["action"]) self.eq("ANTE", players[1].action_histories[0]["action"]) self.eq("ANTE", players[2].action_histories[0]["action"]) self.eq(sb_amount + ante, players[0].pay_info.amount) self.eq(sb_amount * 2 + ante, players[1].pay_info.amount) self.eq(ante, players[2].pay_info.amount) self.eq(sb_amount + sb_amount * 2 + ante * 3, GameEvaluator.create_pot(players)[0]["amount"])
def test_add_amount_calculationl_when_raise_on_ante(self): table = self.__setup_table() pot_amount = lambda state: GameEvaluator.create_pot(state["table"].seats.players)[0]["amount"] stack_check = lambda expected, state: self.eq(expected, [p.stack for p in state["table"].seats.players]) start_state, _ = RoundManager.start_new_round(1, 10, 5, table) self.eq(45, pot_amount(start_state)) stack_check([85, 75, 95], start_state) folded_state, _ = RoundManager.apply_action(start_state, "fold", 0) called_state, _ = RoundManager.apply_action(folded_state, "call", 20) self.eq(55, pot_amount(called_state)) stack_check([85, 75, 95], start_state) called_state, _ = RoundManager.apply_action(start_state, "call", 20) self.eq(20, called_state["table"].seats.players[2].action_histories[-1]["paid"]) self.eq(65, pot_amount(called_state)) raised_state, _ = RoundManager.apply_action(start_state, "raise", 30) self.eq(30, raised_state["table"].seats.players[2].action_histories[-1]["paid"]) self.eq(75, pot_amount(raised_state))
def pot_amount(state): return GameEvaluator.create_pot( state['table'].seats.players)[0]['amount']