Skip to main content

A texasholdem python package

Project description

texasholdem

A python package for Texas Hold 'Em Poker.

Current Release Version v0.2.0

v1.0.0 Roadmap

Contributing

To be added as a contributor, please email me at evyn.machi@gmail.com with your GitHub username and mention one of the open issues / a new issue you would like to tackle first. For more information about contributing, please see the wiki.

Install

pip install texasholdem

Quickstart Guide

Starting a game is as simple as the following:

from texasholdem import TexasHoldEm

game = TexasHoldEm(buyin=500, 
                   big_blind=5, 
                   small_blind=2,
                   max_players=9)
game.start_hand()
while game.is_hand_running():
    game.take_action(...)

Game Information

Get game information and take actions through intuitive attributes:

from texasholdem import TexasHoldEm, HandPhase, ActionType

game = TexasHoldEm(buyin=500, 
                   big_blind=5, 
                   small_blind=2,
                   max_players=9)
game.start_hand()

assert game.hand_phase == HandPhase.PREFLOP
assert HandPhase.PREFLOP.next_phase() == HandPhase.FLOP
assert game.chips_to_call(game.current_player) == game.big_blind

game.take_action(ActionType.CALL)
game.take_action(ActionType.RAISE, value=10)

assert game.chips_to_call(game.current_player) == 10 - game.big_blind

Card Module

The card module represents cards as 32-bit integers for simple and fast hand evaluations. For more information about the representation, see the Card module.

from texasholdem.card import Card

card = Card("Kd")                       # King of Diamonds
assert isinstance(card, int)            # True
assert card.rank == 11                  # 2nd highest rank (0-12)
assert card.pretty_string == "[ K ♦ ]"

The game.get_hand(player_id=...) method of the TexasHoldEm class will return a list of type list[Card].

Evaluator Module

The evaluator module returns the rank of the best 5-card hand from a list of 5 to 7 cards. The rank is a number from 1 (strongest) to 7462 (weakest). This determines the winner in the TexasHoldEm module:

from texasholdem.card import Card
from texasholdem.evaluator import evaluate, rank_to_string

assert evaluate(cards=[Card("Kd"), Card("5d")],
                board=[Card("Qd"), 
                       Card("6d"), 
                       Card("5s"), 
                       Card("2d"),
                       Card("5h")]) == 927
assert rank_to_string(927) == "Flush, King High"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

texasholdem-0.2.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

texasholdem-0.2.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file texasholdem-0.2.0.tar.gz.

File metadata

  • Download URL: texasholdem-0.2.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for texasholdem-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a8a9a421c7ac478f38cfcdf05117a47840096b86aaebc4ebac8d6d01146a8f10
MD5 26e4c3539faf88d61a219e2bc85dd32d
BLAKE2b-256 d9b3a3cb2f3176812288aec9438ecbd014f608b8d1f104c7e57a7de6453f4c29

See more details on using hashes here.

Provenance

File details

Details for the file texasholdem-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: texasholdem-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for texasholdem-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a5d6dfe0c03f40269ee38328f192301bb116d027a406da1373d0e43f62477bf
MD5 5eacb873b1355b45c36e41cb1785c246
BLAKE2b-256 0be4e2159e9ef95f89c2e476ff9dc40eac9809457a0cdb6bb0fb7cc2a08899bb

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page