Giter Club home page Giter Club logo

clubs's Introduction

Logo

clubs

PyPI Status PyPI Status codecov CodeFactor Documentation Status

clubs is a python library for running arbitrary configurations of community card poker games. This includes anything from simple Leduc or Kuhn poker to full n-player No Limit Texas Hold'em or Pot Limit Omaha.

Install

Install using pip install clubs. To enable webserver rendering (see example below), install using pip install clubs[render].

Example

import random

import clubs

config = clubs.configs.NO_LIMIT_HOLDEM_SIX_PLAYER
dealer = clubs.poker.Dealer(**config)
obs = dealer.reset()

while True:
    call = obs['call']
    min_raise = obs['min_raise']
    max_raise = obs['max_raise']

    rand = random.random()
    if rand < 0.1:
        bet = 0
    elif rand < 0.80:
        bet = call
    else:
        bet = random.randint(min_raise, max_raise)

    obs, rewards, done = dealer.step(bet)
    if all(done):
        break

print(rewards)

Configuration

The type of poker game is defined using a configuration dictionary. See configs.py for some example configurations. A configuration dictionary has to have the following key value structure:

  • num_players
    • int: maximum number of players
  • num_streets
    • int: number of streets
  • blinds
    • int or list of ints: the blind distribution starting from the button e.g. [0, 1, 2, 0, 0, 0] for a 6 player 1-2 game
    • a single int is expanded to the number of players, settings blinds=0 will result in no blinds [0, 0, 0, 0, 0, 0]
  • antes
    • int or list of ints: the ante distribution starting from the button, analog to the blind distribution
    • single ints are expanded to the number of players
  • raise_sizes
    • float or str or list of floats or str: the maximum raise size as a list of values, one for each street
    • options are ints (for fixed raise sizes), float('inf') (for no limit raise sizes) or 'pot' for pot limit raise sizes
    • single values are expanded to the number of streets
  • num_raises
    • float or list of floats: the maximum number of raises for each street
    • options are ints (for a fixed number of bets per round) or float('inf') for unlimited number of raises
    • single values are expanded to the number of streets
  • num_suits
    • number of suits in the deck
  • num_ranks
    • number of ranks in the deck
  • num_hole_cards
    • number of hole cards for each player
  • num_community_cards
    • number of community cards per street
  • num_cards_for_hand
    • number of cards for a valid poker hand
  • mandatory_num_hole_cards
    • number of hole cards which must be used for a poker hand
  • start_stack
    • initial stack size

API

clubs adopts the Open AI gym interface. See clubs gym for a full clubs gym environment. To deal a new hand, call dealer.reset(), which returns a dictionary of observations for the current active player. To advance the game, call dealer.step({bet}) with an integer bet size. Invalid bet sizes are always rounded to the nearest valid bet size. When the bet lies exactly between 2 valid bet sizes, it is always rounded down. For example, if the minimum raise size is 10 and the bet is 5, the bet is rounded down to 0, i.e. call or fold.

Universal Deuces

The hand evaluator is heavily inspired by the deuces library. The basic logic is identical, but the evaluator and lookup table are generalized to work for any deck configuration with number of ranks <= 13 and number of suits <= 4 and poker hands with 5 or less cards. See the poker README for further details.

Some speed was sacrificed for the sake of better usability. Nonetheless, the evaluator is still quite fast on modern machines (Intel(R) Core(TM) i5-8250U):

>>> import clubs
>>> evaluator = clubs.poker.Evaluator(4, 13, 5)
>>> avg_time = evaluator.speed_test()
>>> print(f"Average time per evaluation: {avg_time}")
Average time per evaluation: 1.3986515504075214e-06
>>> print(f"Evaluations per second = {1.0/avg_time}")
Evaluations per second = 714974.362062254

Visualize

3 different render modes are available via dealer.render(). The default render mode uses a web front which gets exposed on localhost on a specified or random port.

Render Example

Limitations

Even though the library is designed to be as general as possible, it currently has a couple limitations:

  • Only integer chip denominations are supported
  • The evaluator only works for sub decks of the standard 52 card deck as well as a maximum of 5 card poker hands
  • Draw and stud poker games are not supported

clubs's People

Contributors

fschlatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

clubs's Issues

hand probabilities

To determine how likely it is a hand will we win we need to implement a Monte Carlo sampling method to evaluate unfinished hands

add human GUI

Create a pretty GUI (preferably using HTML to have assets for website) to display hands in human recognizable fashion

Dealer.reset() doesn't update button position correctly

Hi @fschlatt,

First of all, thanks for taking the time to write this library and making it public!

I think line 267 of engine.py is missing a parenthesis around the self.button + 1 part of the assignment operation:

self.button = self.button + 1 % self.num_players

vs.

self.button = (self.button + 1) % self.num_players

I can create a pull request with tests etc. if you'd like, but simply entering a REPL session should give you the proof.
E.g. a game with 3 players, button is on player 3 (index 2) and should be moved to player 1 (index 0) when Dealer.reset() is called:

>>> 2 + 1 % 3   
3 

vs.

>>> (2 + 1) % 3  
0  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.