Esempio n. 1
0
 def __play_round(self, plays):
     """ Make the simple plays 'c' == call, 'f' == fold.  """
     for play in plays:
         player = self.__find_player_with_action()
         if play == 'c':
             action = find_action_in_list(Call, player.pending_actions)
         elif play == 'f':
             action = find_action_in_list(Fold, player.pending_actions)
         else:
             self.assertTrue(False, "Only 'c'all and 'f'old supported")
         self.game.process_action(player, action)
Esempio n. 2
0
 def test_normal_actions(self):
     # Test the normal situation where a player has enough chips to cover
     # the minimum raise and then some:
     nl = NoLimit(small_blind=Currency(0.5), big_blind=Currency(1))
     p = Player('Some Player', chips=1000)
     actions = nl.create_actions(p, 0, Currency(100), 0, Currency(100))
     self.assertEquals(3, len(actions))
     c = find_action_in_list(Call, actions)
     r = find_action_in_list(Raise, actions)
     self.assertEquals(Currency(100), c.amount)
     self.assertEquals(Currency(100), r.min_bet)
     self.assertEquals(None, r.max_bet)
Esempio n. 3
0
    def test_actions(self):
        two_four = FixedLimit(small_bet=Currency(2), big_bet=Currency(4))
        p = Player('Some Player', chips=1000)
        actions = two_four.create_actions(p, 0, 1, 1)
        self.assertEquals(3, len(actions))

        call = find_action_in_list(Call, actions)
        self.assertTrue(call != None)
        self.assertEquals(1, call.amount)

        r = find_action_in_list(Raise, actions)
        self.assertTrue(r != None)
        self.assertEquals(2, r.min_bet)
        self.assertEquals(2, r.max_bet)
Esempio n. 4
0
 def __call(self, player, expected_amount, expected_chips=None):
     self.assertEquals(3, len(player.pending_actions))
     call = find_action_in_list(Call, player.pending_actions)
     self.assertEquals(expected_amount, call.amount)
     self.game.process_action(player, call)
     if expected_chips:
         self.assertEquals(expected_chips, player.chips)
Esempio n. 5
0
    def sit_out(self, player, left_table=False):
        """
        Called by a player who wishes to sit out.

        Because the edge case code for when a player sits out is so similar
        to when they leave the table, handling both in this one method.
        """
        logger.info("Table %s: Sitting player out: %s" % (self.id, player))
        pending_actions_copy = []
        pending_actions_copy.extend(player.pending_actions)
        player.sit_out()

        event = PlayerSatOut(self, player.username)
        if left_table:
            seat_num = self.seats.get_seat_number(player.username)
            self.seats.remove_player(player.username)
            event = PlayerLeftTable(self, player.username, seat_num)

        if self.hand_underway():
            self.game_over_event_queue.append(event)
            self.game.sit_out(player)
        else:
            self.notify_all(event)
            # Check if this players departure interferes with our gathering
            # blinds for a new hand:

            if len(self.seats.active_players) < MIN_PLAYERS_FOR_HAND:
                logger.debug("Table %s: Not enough players for a new hand." % (self.id))
                self.wait()

            if (
                find_action_in_list(PostBlind, pending_actions_copy) != None
                and self.gsm.get_current_state() == STATE_SMALL_BLIND
            ):
                player.sit_out()
                self.prompt_small_blind()

            if (
                find_action_in_list(PostBlind, pending_actions_copy) != None
                and self.gsm.get_current_state() == STATE_BIG_BLIND
            ):
                player.sit_out()
                if len(self.seats.active_players) == 2:
                    # if down to heads up, we need a different small blind:
                    self.__restart()
                self.prompt_big_blind()
Esempio n. 6
0
 def __raise(self, player, amount, expected_chips):
     self.assertEquals(3, len(player.pending_actions))
     raise_action = find_action_in_list(Raise, player.pending_actions)
     self.assertEquals(None, raise_action.amount)
     raise_action.validate([amount])
     self.game.process_action(player, raise_action)
     self.assertEquals(amount, raise_action.amount)
     self.assertEquals(expected_chips, player.chips)
Esempio n. 7
0
    def test_actions_previous_player_raised_all_in(self):
        # Test that if a player raises all in, the following player will
        # be able to call the exact amount raised, but a raise would complete
        # the partial raise the all-in player couldn't.
        two_four = FixedLimit(small_bet=Currency(2), big_bet=Currency(4))
        p = Player('Some Player', chips=1000)
        actions = two_four.create_actions(p, 0, 3.5, 1)
        self.assertEquals(3, len(actions))

        c = find_action_in_list(Call, actions)
        self.assertTrue(c != None)
        self.assertEquals(3.5, c.amount)

        r = find_action_in_list(Raise, actions)
        self.assertTrue(r != None)
        self.assertEqual(0.5, r.max_bet)
        self.assertEqual(0.5, r.min_bet)
Esempio n. 8
0
    def test_actions_call_all_in(self):
        two_four = FixedLimit(small_bet=Currency(2), big_bet=Currency(4))
        p = Player('Some Player', chips=1.5)
        actions = two_four.create_actions(p, 0, 2, 1)
        self.assertEquals(2, len(actions))

        # Should detect that we don't have enough to call and
        # adjust the call amount accordingly:
        c = find_action_in_list(Call, actions)
        self.assertTrue(c != None)
        self.assertEquals(1.5, c.amount)
Esempio n. 9
0
    def test_actions_raise_all_in(self):
        two_four = FixedLimit(small_bet=Currency(2), big_bet=Currency(4))
        p = Player('Some Player', chips=3.5)
        actions = two_four.create_actions(p, 0, 2, 1)
        self.assertEquals(3, len(actions))

        # Should detect that we don't have enough to make the full raise and
        # adjust the raise limits accordingly:
        r = find_action_in_list(Raise, actions)
        self.assertTrue(r != None)
        self.assertEquals(1.5, r.min_bet)
        self.assertEquals(1.5, r.max_bet)
Esempio n. 10
0
    def test_standard_post_blinds(self):
        self.__create_table(3, 0)
        self.table.begin()
        self.assertEquals(STATE_SMALL_BLIND,
                          self.table.gsm.get_current_state())
        sb = self.players[1]
        self.assertEquals(1, len(sb.pending_actions))
        self.assertEquals(None, self.table.small_blind)

        # simulate player posting small blind:
        post_sb_action = find_action_in_list(PostBlind, sb.pending_actions)
        self.table.process_action(sb.username, 0, [])
        self.assertEquals(STATE_BIG_BLIND, self.table.gsm.get_current_state())
        self.assertEquals(sb, self.table.small_blind)
        bb = self.players[2]
        self.assertEquals(1, len(bb.pending_actions))

        # simulate player posting big blind:
        post_bb_action = find_action_in_list(PostBlind, bb.pending_actions)
        self.assertEquals(None, self.table.big_blind)
        self.table.process_action(bb.username, 0, [])
        self.assertEquals(bb, self.table.big_blind)
        self.assertEquals(HAND_UNDERWAY, self.table.gsm.get_current_state())
        self.assertTrue(self.table.hand_underway())
Esempio n. 11
0
    def sit_out(self, player):
        """
        Handle a player sitting out.

        Note this method is called by the table object which has
        already actually marked the player object as sitting out. Here we
        just deal with any mess related to ongoing action that may have
        involved the player.
        """
        # If the player sitting out is the one we were currently awaiting a
        # response from, simulate a fold:
        logger.debug("Player sitting out: %s" % player.username)
        if player in self.pending_actions.keys():
            logger.debug("   player had pending actions, simulating fold.")
            fold = find_action_in_list(Fold, self.pending_actions[player])
            self.process_action(player, fold)
Esempio n. 12
0
    def prompt_player(self, player, actions_list):
        """ Prompt the player with a list of actions. """
        self._check_if_finished()
        if player in self.pending_actions.keys():
            # Shouldn't happen, but just in case:
            logger.error("Error adding pending actions for player: " + str(player))
            logger.error("   Pre-existing pending actions: " + str(self.pending_actions[player]))
            raise RounderException("Pending actions already exist")

        self.pending_actions[player] = actions_list

        # If player has sat out, simulate a fold here:
        if player.sitting_out:
            logger.debug("   player is sitting out, simulating fold.")
            fold = find_action_in_list(Fold, actions_list)
            self.process_action(player, fold)
        else:
            logger.debug("Prompting %s with actions: %s" % (player.username, actions_list))
            # TODO: Two prompt calls here, should probably be one:
            player.prompt(actions_list)
            if self.table != None:
                self.table.prompt_player(player, actions_list)
Esempio n. 13
0
 def __fold(self, player, expected_chips):
     self.assertEquals(3, len(player.pending_actions))
     fold = find_action_in_list(Fold, player.pending_actions)
     self.game.process_action(player, fold)
     self.assertEquals(expected_chips, player.chips)