Example #1
0
    def repopulate(self):
        """ If there are free seats, we'll take a random chance that a new player
            will occupy a seat. If there is only one player at the table
            (ie: probably the human), then we MUST add a new player to play.
            Otherwise, the chance a new player will arrive will be rather low,
            ~5-10%, to give some variety in the game play.
        """
        _logger.debug('Checking how many free seats there are.')
        freeseats = self.table.get_free_seats()
        _logger.debug('Checking if only one player is at the table.')
        loneplayer = (len(self.table) - len(freeseats)) == 1

        if not freeseats:
            _logger.debug('The table is full.')
            return False

        _logger.debug('Randomizing if we\'ll have a new player enter the game.')
        freshmeat = random.randint(1, 100) <= ENTER_CHANCE

        if loneplayer or freshmeat:
            _logger.debug('A new player is needed.')
            _logger.debug('Taking a player from the player pool.')
            newplayer = self.yank_from_pool()
            _logger.debug('Randomizing which free seat the new player will occupy')
            newseat = random.choice(freeseats)
            print('{} has entered the game and taken seat {}.'.format(newplayer.name, newseat.NUM))

            _logger.debug('Seating the new player at seat {}'.format(newseat.NUM))
            newseat.sitdown(newplayer)
            _logger.debug('Calculating a random buyin.')
            buyin = stacks.random_stack(self.blinds.SMBET)
            _logger.debug('Buying the new player {} chips'.format(buyin))
            newseat.buy_chips(buyin)
        return True
Example #2
0
def table_factory(**new_config):
    """ Takes a config dictionary and creates a new custom Table """
    config = {
        'seats': None,
        'tablename': 'default',
        'playerpool': None,
        'heroseat': None,
        'stack': DEF_STACK,
        'stepstacks': False,
        'remove': None,
        'bb': None,
        'varystacks': False
    }
    config.update(new_config)

    tbl = table.Table(config['seats'])
    tbl.name = config['tablename']

    # If playerpool is none, use a default playerpool.
    if config['playerpool'] is None:
        pool = make_playerpool(quantity=10)

    elif len(config['playerpool']) < config['seats']:
        raise Exception('The playerpool doesn\'t have another players to cover the table!')
    else:
        pool = config['playerpool']

    # Fund and Seat the players
    for i, s in enumerate(tbl):
        if i == config['heroseat']:
            continue  # Save this seat for the hero.
        s.sitdown(pool.pop(0))

    # Players buyin to the table.
    # There are a few different ways to set stack sizes.
    # - There is a DEF_STACK value for a default.
    # - stack parameter sets the stack amount.
    # - There is a stepstacks bool to trigger stacksizes as a stepped 100, 200, 300, pattern.
    # - There is a BBs parameter passed as a (BB size, BB quantity) pair to set stacks to the
    #    commonly measured units of big blinds.
    # - There is a stackvariation parameter to randomly vary the sizes of the stacks. The
    #   parameter is a float value that is used to randomly calculate the variations.

    # *** Player buyins ***
    # Go through all the seats
    for i, s in enumerate(tbl):
        # Check if the seat is occupied or vacant.
        if s.vacant():
            continue

        # Buy chips based on the parameter preference
        if config['stepstacks']:
            s.buy_chips(STEP * (i + 1))
        elif config['varystacks']:
            # Get a different stacksize(in BB's) for each player
            s.buy_chips(stacks.random_stack(config['bb']))

        elif config['stack']:
            s.buy_chips(config['stack'])
        else:
            s.buy_chips(DEF_STACK)

        # Random variations
            hilimit = int(s.stack * config['variance'])
            offset = random.randint(-hilimit, hilimit)
            s.stack -= offset

    # Removes a player from the table, if specified.
    if config['remove'] is not None:
        tbl.pop(config['remove'])

    return tbl