def test_message_skip_when_only_one_player_is_active(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, msgs = RoundManager.apply_action(state, "fold", 0) self.eq(Const.Street.FINISHED, state["street"]) self.false("street_start_message" in [msg["message"]["message_type"] for _, msg in msgs])
def test_state_after_forward_to_flop(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) self.eq(Const.Street.FLOP, state["street"]) self.eq(0, state["next_player"]) self.eq([Card.from_id(cid) for cid in range(7, 10)], state["table"].get_community_card()) fetch_player = lambda uuid: [ p for p in state["table"].seats.players if p.uuid == uuid ][0] self.true( all( map(lambda p: len(p.action_histories) == 0, state["table"].seats.players))) self.eq( 2, len( fetch_player("uuid0").round_action_histories[ Const.Street.PREFLOP])) self.eq( 2, len( fetch_player("uuid1").round_action_histories[ Const.Street.PREFLOP])) self.eq( 1, len( fetch_player("uuid2").round_action_histories[ Const.Street.PREFLOP])) self.assertIsNone( fetch_player("uuid0").round_action_histories[Const.Street.TURN])
def test_add_amount_calculation_when_raise_on_ante(self): table = self.__setup_table() def pot_amount(state): return GameEvaluator.create_pot( state['table'].seats.players)[0]['amount'] def stack_check(expected, state): return 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', 40) self.eq( 40, raised_state['table'].seats.players[2].action_histories[-1] ['paid']) self.eq(85, pot_amount(raised_state))
def test_message_skip_when_only_one_player_is_active(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, 'fold', 0) state, msgs = RoundManager.apply_action(state, 'fold', 0) self.eq(Const.Street.FINISHED, state['street']) self.false('street_start_message' in [msg['message']['message_type'] for _, msg in msgs])
def test_deepcopy_state(self): table = self.__setup_table() original = RoundManager._RoundManager__gen_initial_state(2, 5, table) copied = RoundManager._RoundManager__deep_copy_state(original) check = lambda key: self.eq(original[key], copied[key]) [ check(key) for key in ["round_count", "small_blind_amount", "street", "next_player"] ]
def test_table_reset_after_showdown(self): mock_return = [1, 0] * 3 with patch( 'pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return ), patch( 'pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value='boo' ), patch( 'pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value='foo'): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, 'fold', 0) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 0) state, _ = RoundManager.apply_action(state, 'call', 0) state, _ = RoundManager.apply_action(state, 'call', 0) state, _ = RoundManager.apply_action(state, 'call', 0) state, _ = RoundManager.apply_action(state, 'call', 0) state, _ = RoundManager.apply_action(state, 'call', 0) table = state['table'] player = state['table'].seats.players[0] self.eq(52, table.deck.size()) self.eq([], table.get_community_card()) self.eq([], player.hole_card) self.eq([], player.action_histories) self.eq(PayInfo.PLAY_TILL_END, player.pay_info.status)
def test_state_after_showdown(self): mock_return = [1, 0] * 3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value="bogo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) self.eq(Const.Street.FINISHED, state["street"]) self.eq(110, state["table"].seats.players[0].stack) self.eq(90, state["table"].seats.players[1].stack) self.eq(100, state["table"].seats.players[2].stack) self.true( all( map(lambda p: len(p.action_histories) == 0, state["table"].seats.players))) self.true( all( map(lambda p: p.round_action_histories == [None] * 4, state["table"].seats.players)))
def play_round(self, round_count, blind_amount, ante, table): state, msgs = RoundManager.start_new_round(round_count, blind_amount, ante, table) while True: self.__message_check(msgs, state['street']) if state['street'] != Const.Street.FINISHED: # continue the round action, bet_amount = self.__publish_messages(msgs) state, msgs = RoundManager.apply_action(state, action, bet_amount) else: # finish the round after publish round result self.__publish_messages(msgs) break return state['table']
def play_round(self, round_count, blind_amount, ante, table): state, msgs = RoundManager.start_new_round(round_count, blind_amount, ante, table) while True: self.__message_check(msgs, state["street"]) if state["street"] != Const.Street.FINISHED: # continue the round action, bet_amount = self.__publish_messages(msgs) state, msgs = RoundManager.apply_action(state, action, bet_amount) else: # finish the round after publish round result self.__publish_messages(msgs) break return state["table"]
def test_deepcopy_state(self): table = self.__setup_table() original = RoundManager._RoundManager__gen_initial_state(2, 5, table) copied = RoundManager._RoundManager__deep_copy_state(original) def check(key): return self.eq(original[key], copied[key]) [ check(key) for key in ['round_count', 'small_blind_amount', 'street', 'next_player'] ]
def test_message_after_forward_to_flop(self): with patch('pypokerengine.engine.message_builder.MessageBuilder.build_street_start_message', return_value="fuga"),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_ask_message', return_value="bar"),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value="boo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) _, msgs = RoundManager.apply_action(state, "call", 10) self.eq((-1, "boo"), msgs[0]) self.eq((-1, "fuga"), msgs[1]) self.eq(("uuid0", "bar"), msgs[2])
def test_state_after_forward_to_turn(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, 'fold', 0) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 0) state, msgs = RoundManager.apply_action(state, 'call', 0) self.eq(Const.Street.TURN, state['street']) self.eq([Card.from_id(cid) for cid in range(7, 11)], state['table'].get_community_card()) self.eq(3, len(msgs)) def fetch_player(uuid): return [p for p in state['table'].seats.players if p.uuid == uuid][0] self.true( all( map(lambda p: len(p.action_histories) == 0, state['table'].seats.players))) self.eq( 2, len( fetch_player('uuid0').round_action_histories[ Const.Street.PREFLOP])) self.eq( 2, len( fetch_player('uuid1').round_action_histories[ Const.Street.PREFLOP])) self.eq( 1, len( fetch_player('uuid2').round_action_histories[ Const.Street.PREFLOP])) self.eq( 1, len( fetch_player('uuid0').round_action_histories[ Const.Street.FLOP])) self.eq( 1, len( fetch_player('uuid1').round_action_histories[ Const.Street.FLOP])) self.eq( 0, len( fetch_player('uuid2').round_action_histories[ Const.Street.FLOP])) self.assertIsNone( fetch_player('uuid0').round_action_histories[Const.Street.TURN])
def __start_round(self): table = self.__setup_table() round_count = 1 small_blind_amount = 5 ante = 0 return RoundManager.start_new_round(round_count, small_blind_amount, ante, table)
def test_state_after_forward_to_flop(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) self.eq(Const.Street.FLOP, state["street"]) self.eq(0, state["next_player"]) self.eq([Card.from_id(cid) for cid in range(7,10)], state["table"].get_community_card()) fetch_player = lambda uuid: [p for p in state["table"].seats.players if p.uuid==uuid][0] self.true(all(map(lambda p: len(p.action_histories)==0, state["table"].seats.players))) self.eq(2, len(fetch_player("uuid0").round_action_histories[Const.Street.PREFLOP])) self.eq(2, len(fetch_player("uuid1").round_action_histories[Const.Street.PREFLOP])) self.eq(1, len(fetch_player("uuid2").round_action_histories[Const.Street.PREFLOP])) self.assertIsNone(fetch_player("uuid0").round_action_histories[Const.Street.TURN])
def update_game(self, action, bet_amount): state, msgs = RoundManager.apply_action(self.current_state, action, bet_amount) if state['street'] == Const.Street.FINISHED: state, new_msgs = self._start_next_round( state['round_count']+1, self.config['blind_structure'], state['table']) msgs += new_msgs self.current_state = state return _parse_broadcast_destination(msgs, self.current_state['table'])
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 test_message_after_forward_to_flop(self): with patch( 'pypokerengine.engine.message_builder.MessageBuilder.build_street_start_message', return_value='fuga' ), patch( 'pypokerengine.engine.message_builder.MessageBuilder.build_ask_message', return_value='bar' ), patch( 'pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value='boo'): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, 'fold', 0) state, _ = RoundManager.apply_action(state, 'call', 10) _, msgs = RoundManager.apply_action(state, 'call', 10) self.eq((-1, 'boo'), msgs[0]) self.eq((-1, 'fuga'), msgs[1]) self.eq(('uuid0', 'bar'), msgs[2])
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 apply_action(self, game_state, action, bet_amount=0): if game_state["street"] == Const.Street.FINISHED: game_state, events = self._start_next_round(game_state) updated_state, messages = RoundManager.apply_action(game_state, action) events = [self.create_event(message[1]["message"]) for message in messages] events = [e for e in events if e] if self._is_last_round(updated_state, self.game_rule): events += self._generate_game_result_event(updated_state) return updated_state, events
def update_game(self, action, bet_amount): state, msgs = RoundManager.apply_action(self.current_state, action, bet_amount) if state['street'] == Const.Street.FINISHED: state, new_msgs = self._start_next_round( state['round_count'] + 1, self.config['blind_structure'], state['table']) msgs += new_msgs self.current_state = state return _parse_broadcast_destination(msgs, self.current_state['table'])
def _start_next_round(self, round_count, blind_structure, table): table.shift_dealer_btn() small_blind, ante = _get_forced_bet_amount(round_count, blind_structure) table = _exclude_short_of_money_players(table, ante, small_blind) if self._has_game_finished(round_count, table, self.config['max_round']): finished_state = { 'table': table } game_result_msg = _gen_game_result_message(table, self.config) msgs = _parse_broadcast_destination([game_result_msg], table) return finished_state, msgs else: return RoundManager.start_new_round(round_count, small_blind, ante, table)
def play_round(self, round_count, blind_amount, ante, table): state, msgs = RoundManager.start_new_round(round_count, blind_amount, ante, table) while True: self.__message_check(msgs, state["street"]) if state["street"] != Const.Street.FINISHED: # continue the round answer = self.__publish_messages(msgs) bot_info = None if len(answer) == 3: action, bet_amount, bot_info = answer else: action, bet_amount = answer state, msgs = RoundManager.apply_action(state, action, bet_amount, bot_info=bot_info) else: # finish the round after publish round result self.__publish_messages(msgs) break return state["table"]
def test_message_after_showdown(self): mock_return = [1,0]*3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value="boo"),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value="foo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) _, msgs = RoundManager.apply_action(state, "call", 0) self.eq((-1, "boo"), msgs[0]) self.eq((-1, "foo"), msgs[1])
def test_message_after_showdown(self): mock_return = [1, 0] * 3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value="boo"),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value="foo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) _, msgs = RoundManager.apply_action(state, "call", 0) self.eq((-1, "boo"), msgs[0]) self.eq((-1, "foo"), msgs[1])
def deal_community_card(self, state, num): self.community_to = self.community_from + num cards = self.cards[ self.round_count - 1]['community'][self.community_from:self.community_to] for card in cards: state["table"].add_community_card(card) self.community_from = self.community_to return RoundManager._RoundManager__forward_street(state)
def _start_next_round(self, round_count, blind_structure, table): table.shift_dealer_btn() small_blind, ante = _get_forced_bet_amount(round_count, blind_structure) table = _exclude_short_of_money_players(table, ante, small_blind) if self._has_game_finished(round_count, table, self.config['max_round']): finished_state = {'table': table} game_result_msg = _gen_game_result_message(table, self.config) msgs = _parse_broadcast_destination([game_result_msg], table) return finished_state, msgs else: return RoundManager.start_new_round(round_count, small_blind, ante, table)
def test_ask_player_target_when_dealer_btn_player_is_folded(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'call', 10) state, _ = RoundManager.apply_action(state, 'fold', 10) state, _ = RoundManager.apply_action(state, 'call', 0) state, msgs = RoundManager.apply_action(state, 'call', 0) self.eq('uuid1', msgs[-1][0])
def test_ask_player_target_when_dealer_btn_player_is_folded(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "fold", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, msgs = RoundManager.apply_action(state, "call", 0) self.eq("uuid1", msgs[-1][0])
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 run_until_round_finish(self, game_state): mailbox = [] while game_state["street"] != Const.Street.FINISHED: next_player_pos = game_state["next_player"] next_player_uuid = game_state["table"].seats.players[next_player_pos].uuid next_player_algorithm = self.fetch_player(next_player_uuid) msg = MessageBuilder.build_ask_message(next_player_pos, game_state)["message"] action, amount = next_player_algorithm.declare_action(\ msg["valid_actions"], msg["hole_card"], msg["round_state"]) game_state, messages = RoundManager.apply_action(game_state, action, amount) mailbox += messages events = [self.create_event(message[1]["message"]) for message in mailbox] events = [e for e in events if e] if self._is_last_round(game_state, self.game_rule): events += self._generate_game_result_event(game_state) return game_state, events
def start_new_round(self, game_state): round_count = game_state["round_count"] + 1 ante, sb_amount = self.game_rule["ante"], self.game_rule["sb_amount"] deepcopy = deepcopy_game_state(game_state) deepcopy_table = deepcopy["table"] deepcopy_table.shift_dealer_btn() ante, sb_amount = update_blind_level(ante, sb_amount, round_count, self.blind_structure) deepcopy_table = exclude_short_of_money_players(deepcopy_table, ante, sb_amount) is_game_finished = len([1 for p in deepcopy_table.seats.players if p.is_active()])==1 if is_game_finished: return deepcopy, self._generate_game_result_event(deepcopy) new_state, messages = RoundManager.start_new_round(round_count, sb_amount, ante, deepcopy_table) events = [self.create_event(message[1]["message"]) for message in messages] events = [e for e in events if e] return new_state, events
def test_state_after_showdown(self): mock_return = [1,0]*3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value="bogo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) self.eq(Const.Street.FINISHED, state["street"]) self.eq(110, state["table"].seats.players[0].stack) self.eq( 90, state["table"].seats.players[1].stack) self.eq(100, state["table"].seats.players[2].stack) self.true(all(map(lambda p: len(p.action_histories)==0, state["table"].seats.players))) self.true(all(map(lambda p: p.round_action_histories==[None]*4, state["table"].seats.players)))
def test_table_reset_after_showdown(self): mock_return = [1,0]*3 with patch('pypokerengine.engine.hand_evaluator.HandEvaluator.eval_hand', side_effect=mock_return),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_game_update_message', return_value="boo"),\ patch('pypokerengine.engine.message_builder.MessageBuilder.build_round_result_message', return_value="foo"): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "call", 0) table = state["table"] player = state["table"].seats.players[0] self.eq(52, table.deck.size()) self.eq([], table.get_community_card()) self.eq([], player.hole_card) self.eq([], player.action_histories) self.eq(PayInfo.PAY_TILL_END, player.pay_info.status)
def test_everyone_agree_logic_regression(self): players = [Player("uuid%d" % i, 100) for i in range(4)] players[0].stack = 150 players[1].stack = 150 players[2].stack = 50 players[3].stack = 50 deck = Deck(cheat=True, cheat_card_ids=range(1,53)) table = Table(cheat_deck=deck) for player in players: table.seats.sitdown(player) table.dealer_btn = 3 table.set_blind_pos(0, 1) state, _ = RoundManager.start_new_round(1, 5, 0, table) state, _ = RoundManager.apply_action(state, "raise", 15) state, _ = RoundManager.apply_action(state, "raise", 20) state, _ = RoundManager.apply_action(state, "raise", 25) state, _ = RoundManager.apply_action(state, "raise", 30) state, _ = RoundManager.apply_action(state, "raise", 50) state, _ = RoundManager.apply_action(state, "call", 50) state, _ = RoundManager.apply_action(state, "raise", 125) state, _ = RoundManager.apply_action(state, "call", 125) state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "fold", 0) self.eq(Const.Street.FINISHED, state["street"])
def test_state_after_apply_raise(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "raise", 15) self.eq(0, state["next_player"]) self.eq("RAISE", state["table"].seats.players[2].action_histories[0]["action"])
def test_state_after_apply_call(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "call", 10) self.eq(0, state["next_player"]) self.eq("CALL", state["table"].seats.players[2].action_histories[0]["action"])
def test_everyone_agree_logic_regression(self): players = [Player("uuid%d" % i, 100) for i in range(4)] players[0].stack = 150 players[1].stack = 150 players[2].stack = 50 players[3].stack = 50 deck = Deck(cheat=True, cheat_card_ids=range(1, 53)) table = Table(cheat_deck=deck) for player in players: table.seats.sitdown(player) table.dealer_btn = 3 table.set_blind_pos(0, 1) state, _ = RoundManager.start_new_round(1, 5, 0, table) state, _ = RoundManager.apply_action(state, "raise", 15) state, _ = RoundManager.apply_action(state, "raise", 20) state, _ = RoundManager.apply_action(state, "raise", 25) state, _ = RoundManager.apply_action(state, "raise", 30) state, _ = RoundManager.apply_action(state, "raise", 50) state, _ = RoundManager.apply_action(state, "call", 50) state, _ = RoundManager.apply_action(state, "raise", 125) state, _ = RoundManager.apply_action(state, "call", 125) state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "fold", 0) self.eq(Const.Street.FINISHED, state["street"])
def test_skip_asking_to_allin_player(self): state, _ = self.__start_round() # Round 1 state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "raise", 50) state, _ = RoundManager.apply_action(state, "call", 50) state, _ = RoundManager.apply_action(state, "fold", 0) self.eq([95, 40, 165], [p.stack for p in state["table"].seats.players]) # Round 2 state["table"].shift_dealer_btn() state["table"].set_blind_pos(1, 2) state, _ = RoundManager.start_new_round(2, 5, 0, state["table"]) state, _ = RoundManager.apply_action(state, "raise", 40) state, _ = RoundManager.apply_action(state, "call", 40) state, _ = RoundManager.apply_action(state, "raise", 70) state, msgs = RoundManager.apply_action(state, "call", 70) self.eq([25, 0, 95], [p.stack for p in state["table"].seats.players]) self.eq(1, state["street"]) self.eq("uuid2", msgs[-1][0])
def test_when_only_one_player_is_waiting_ask(self): state, _ = self.__start_round() # Round 1 state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "fold", 0) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "raise", 50) state, _ = RoundManager.apply_action(state, "call", 50) state, _ = RoundManager.apply_action(state, "fold", 0) self.eq([95, 40, 165], [p.stack for p in state["table"].seats.players]) # Round 2 state["table"].shift_dealer_btn() state, _ = RoundManager.start_new_round(2, 5, 0, state["table"]) state, _ = RoundManager.apply_action(state, "raise", 40) state, _ = RoundManager.apply_action(state, "call", 40) state, _ = RoundManager.apply_action(state, "raise", 70) state, _ = RoundManager.apply_action(state, "call", 70) state, _ = RoundManager.apply_action(state, "call", 0) state, _ = RoundManager.apply_action(state, "raise", 10) state, _ = RoundManager.apply_action(state, "call", 10) state, _ = RoundManager.apply_action(state, "raise", 85) state, _ = RoundManager.apply_action(state, "call", 85)
def test_ask_big_blind_in_preflop(self): state, _ = self.__start_round() state, _ = RoundManager.apply_action(state, "call", 10) state, msg = RoundManager.apply_action(state, "call", 10) self.eq("uuid1", msg[-1][0]) self.eq(Const.Street.PREFLOP, state["street"])
def test_deepcopy_state(self): table = self.__setup_table() original = RoundManager._RoundManager__gen_initial_state(2, 5, table) copied = RoundManager._RoundManager__deep_copy_state(original) check = lambda key: self.eq(original[key], copied[key]) [check(key) for key in ["round_count", "small_blind_amount", "street", "next_player"]]