コード例 #1
0
 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])
コード例 #2
0
    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])
コード例 #3
0
    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"])
コード例 #4
0
 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])
コード例 #5
0
    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))
コード例 #6
0
    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)))
コード例 #7
0
 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)
コード例 #8
0
  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])
コード例 #9
0
    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])
コード例 #10
0
    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])
コード例 #11
0
  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])
コード例 #12
0
 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))
コード例 #13
0
 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))
コード例 #14
0
ファイル: engine_wrapper.py プロジェクト: nn-simon/PokerAI
 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'])
コード例 #15
0
    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])
コード例 #16
0
 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
コード例 #17
0
 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'])
コード例 #18
0
 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']
コード例 #19
0
ファイル: dealer.py プロジェクト: ishikota/PyPokerEngine
 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"]
コード例 #20
0
 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])
コード例 #21
0
 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])
コード例 #22
0
 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])
コード例 #23
0
 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])
コード例 #24
0
 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])
コード例 #25
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])
コード例 #26
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])
コード例 #27
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])
コード例 #28
0
  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"])
コード例 #29
0
 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
コード例 #30
0
  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)))
コード例 #31
0
 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)
コード例 #32
0
ファイル: dealer.py プロジェクト: team55/holdem-challenge
 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"]
コード例 #33
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)
コード例 #34
0
 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'])
コード例 #35
0
 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"])
コード例 #36
0
 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"])
コード例 #37
0
 def test_state_after_apply_raise(self):
     state, _ = self.__start_round()
     state, _ = RoundManager.apply_action(state, 'raise', 20)
     self.eq(0, state['next_player'])
     self.eq('RAISE',
             state['table'].seats.players[2].action_histories[0]['action'])
コード例 #38
0
 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"])
コード例 #39
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)
コード例 #40
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, 'fold', 0)
     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, 'fold', 0)
コード例 #41
0
 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'])
コード例 #42
0
 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])
コード例 #43
0
 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"])
コード例 #44
0
 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"])
コード例 #45
0
 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"])