texasholdem


Nametexasholdem JSON
Version 0.11.0 PyPI version JSON
download
home_pagehttps://github.com/SirRender00/texasholdem
SummaryA texasholdem python package
upload_time2024-09-21 16:49:40
maintainerNone
docs_urlNone
authorEvyn Machi
requires_python<4.0,>=3.8
licenseMIT
keywords texasholdem holdem poker
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # texasholdem
![Pytest Status](https://github.com/SirRender00/texasholdem/actions/workflows/pytest.yml/badge.svg)
[![codecov](https://codecov.io/github/SirRender00/texasholdem/branch/main/graph/badge.svg?token=1PH1NHTGXP)](https://codecov.io/github/SirRender00/texasholdem)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/SirRender00/texasholdem/main/LICENSE)
[![Documentation Status](https://readthedocs.org/projects/texasholdem/badge/?version=stable)](https://texasholdem.readthedocs.io/en/stable/?badge=stable)
![Pylint Status](https://github.com/SirRender00/texasholdem/actions/workflows/pylint.yml/badge.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

A python package for Texas Hold 'Em Poker providing:
- Fast evaluation of hand strengths 
- Export & import human-readable game history
- GUIs to view games and game history
- Simple & complex agents 
- Compliance with World Series of Poker Official Rules
- And more

| Version Name | Latest Tag | Release Notes                                                                    | Patch Notes                                                                    | Documentation                                                | Release Date  | End Support Date |
|--------------|------------|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------|---------------| ---------------- |
| 0.11         | v0.11.0    | [Release Notes](https://github.com/SirRender00/texasholdem/releases/tag/v0.11.0) | [Patch Notes](https://github.com/SirRender00/texasholdem/releases/tag/v0.11.0) | [Documentation](https://texasholdem.readthedocs.io/en/0.11/) | 30 March 2024 | |

Current Roadmap \
[v1.0.0](https://github.com/SirRender00/texasholdem/wiki/Version-1.0.0-Roadmap)

## Changelog v0.11.0

### Other Changes

- Upgraded to support python 3.12

## Contributing
Want a new feature, found a bug, or have questions? Feel free to add to our issue board on Github!
[Open Issues](https://github.com/SirRender00/texasholdem/issues>).

We welcome any developer who enjoys the package enough to contribute! Please message me at evyn.machi@gmail.com
if you want to be added as a contributor and check out the 
[Developer's Guide](https://github.com/SirRender00/texasholdem/wiki/Developer's-Guide).

## Install
The package is available on pypi and can be installed with

```bash
pip install texasholdem
```

For the latest experimental version
```bash
pip install texasholdem --pre
```

## Quickstart
Play a game from the command line and take turns for every player out of the box.

```python
from texasholdem.game.game import TexasHoldEm
from texasholdem.gui.text_gui import TextGUI

game = TexasHoldEm(buyin=500, big_blind=5, small_blind=2, max_players=6)
gui = TextGUI(game=game)

while game.is_game_running():
    game.start_hand()

    while game.is_hand_running():
        gui.run_step()

    path = game.export_history('./pgns')     # save history
    gui.replay_history(path)                 # replay history
```

## Overview
The following is a quick summary of what's in the package. Please see the 
[docs](https://texasholdem.readthedocs.io/en/stable/) for all the details.

### Game Information

Get game information and take actions through intuitive attributes.

```python
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
assert len(game.get_hand(game.current_player)) == 2

game.take_action(ActionType.CALL)

player_id = game.current_player
game.take_action(ActionType.RAISE, total=10)
assert game.player_bet_amount(player_id) == 10
assert game.chips_at_stake(player_id) == 20     # total amount in all pots the player is in

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

### Cards
The card module represents cards as 32-bit integers for simple and fast hand
evaluations.

```python
from texasholdem 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 ♦ ]"
```

### Agents
The package also comes with basic agents including `call_agent` and `random_agent`

```python
from texasholdem import TexasHoldEm
from texasholdem.agents import random_agent, call_agent

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

while game.is_hand_running():
    if game.current_player % 2 == 0:
        game.take_action(*random_agent(game))
    else:
        game.take_action(*call_agent(game))
```

### Game History
Export and import the history of hands to files.

```python
from texasholdem import TexasHoldEm
from texasholdem.gui import TextGUI

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

while game.is_hand_running():
    game.take_action(*some_strategy(game))

# export to file
game.export_history("./pgns/my_game.pgn")

# import and replay
gui = TextGUI()
gui.replay_history("./pgns/my_game.pgn")
```
PGN files also support single line and end of line comments starting with "#".

### Poker Evaluator
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).

```python
from texasholdem 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"
```

### GUIs
The GUI package currently comes with a text-based GUI to play games from the command line. Coming later
will be web-app based GUIs.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SirRender00/texasholdem",
    "name": "texasholdem",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "texasholdem, holdem, poker",
    "author": "Evyn Machi",
    "author_email": "evyn.machi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/48/9f/a26464fd4fbd506eada17ec5b26556b4fec25d2143a67fad58af6762557f/texasholdem-0.11.0.tar.gz",
    "platform": null,
    "description": "# texasholdem\n![Pytest Status](https://github.com/SirRender00/texasholdem/actions/workflows/pytest.yml/badge.svg)\n[![codecov](https://codecov.io/github/SirRender00/texasholdem/branch/main/graph/badge.svg?token=1PH1NHTGXP)](https://codecov.io/github/SirRender00/texasholdem)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/SirRender00/texasholdem/main/LICENSE)\n[![Documentation Status](https://readthedocs.org/projects/texasholdem/badge/?version=stable)](https://texasholdem.readthedocs.io/en/stable/?badge=stable)\n![Pylint Status](https://github.com/SirRender00/texasholdem/actions/workflows/pylint.yml/badge.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nA python package for Texas Hold 'Em Poker providing:\n- Fast evaluation of hand strengths \n- Export & import human-readable game history\n- GUIs to view games and game history\n- Simple & complex agents \n- Compliance with World Series of Poker Official Rules\n- And more\n\n| Version Name | Latest Tag | Release Notes                                                                    | Patch Notes                                                                    | Documentation                                                | Release Date  | End Support Date |\n|--------------|------------|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------|---------------| ---------------- |\n| 0.11         | v0.11.0    | [Release Notes](https://github.com/SirRender00/texasholdem/releases/tag/v0.11.0) | [Patch Notes](https://github.com/SirRender00/texasholdem/releases/tag/v0.11.0) | [Documentation](https://texasholdem.readthedocs.io/en/0.11/) | 30 March 2024 | |\n\nCurrent Roadmap \\\n[v1.0.0](https://github.com/SirRender00/texasholdem/wiki/Version-1.0.0-Roadmap)\n\n## Changelog v0.11.0\n\n### Other Changes\n\n- Upgraded to support python 3.12\n\n## Contributing\nWant a new feature, found a bug, or have questions? Feel free to add to our issue board on Github!\n[Open Issues](https://github.com/SirRender00/texasholdem/issues>).\n\nWe welcome any developer who enjoys the package enough to contribute! Please message me at evyn.machi@gmail.com\nif you want to be added as a contributor and check out the \n[Developer's Guide](https://github.com/SirRender00/texasholdem/wiki/Developer's-Guide).\n\n## Install\nThe package is available on pypi and can be installed with\n\n```bash\npip install texasholdem\n```\n\nFor the latest experimental version\n```bash\npip install texasholdem --pre\n```\n\n## Quickstart\nPlay a game from the command line and take turns for every player out of the box.\n\n```python\nfrom texasholdem.game.game import TexasHoldEm\nfrom texasholdem.gui.text_gui import TextGUI\n\ngame = TexasHoldEm(buyin=500, big_blind=5, small_blind=2, max_players=6)\ngui = TextGUI(game=game)\n\nwhile game.is_game_running():\n    game.start_hand()\n\n    while game.is_hand_running():\n        gui.run_step()\n\n    path = game.export_history('./pgns')     # save history\n    gui.replay_history(path)                 # replay history\n```\n\n## Overview\nThe following is a quick summary of what's in the package. Please see the \n[docs](https://texasholdem.readthedocs.io/en/stable/) for all the details.\n\n### Game Information\n\nGet game information and take actions through intuitive attributes.\n\n```python\nfrom texasholdem import TexasHoldEm, HandPhase, ActionType\n\ngame = TexasHoldEm(buyin=500,\n                   big_blind=5,\n                   small_blind=2,\n                   max_players=9)\ngame.start_hand()\n\nassert game.hand_phase == HandPhase.PREFLOP\nassert HandPhase.PREFLOP.next_phase() == HandPhase.FLOP\nassert game.chips_to_call(game.current_player) == game.big_blind\nassert len(game.get_hand(game.current_player)) == 2\n\ngame.take_action(ActionType.CALL)\n\nplayer_id = game.current_player\ngame.take_action(ActionType.RAISE, total=10)\nassert game.player_bet_amount(player_id) == 10\nassert game.chips_at_stake(player_id) == 20     # total amount in all pots the player is in\n\nassert game.chips_to_call(game.current_player) == 10 - game.big_blind\n```\n\n### Cards\nThe card module represents cards as 32-bit integers for simple and fast hand\nevaluations.\n\n```python\nfrom texasholdem import Card\n\ncard = Card(\"Kd\")                       # King of Diamonds\nassert isinstance(card, int)            # True\nassert card.rank == 11                  # 2nd highest rank (0-12)\nassert card.pretty_string == \"[ K \u2666 ]\"\n```\n\n### Agents\nThe package also comes with basic agents including `call_agent` and `random_agent`\n\n```python\nfrom texasholdem import TexasHoldEm\nfrom texasholdem.agents import random_agent, call_agent\n\ngame = TexasHoldEm(buyin=500, big_blind=5, small_blind=2)\ngame.start_hand()\n\nwhile game.is_hand_running():\n    if game.current_player % 2 == 0:\n        game.take_action(*random_agent(game))\n    else:\n        game.take_action(*call_agent(game))\n```\n\n### Game History\nExport and import the history of hands to files.\n\n```python\nfrom texasholdem import TexasHoldEm\nfrom texasholdem.gui import TextGUI\n\ngame = TexasHoldEm(buyin=500, big_blind=5, small_blind=2)\ngame.start_hand()\n\nwhile game.is_hand_running():\n    game.take_action(*some_strategy(game))\n\n# export to file\ngame.export_history(\"./pgns/my_game.pgn\")\n\n# import and replay\ngui = TextGUI()\ngui.replay_history(\"./pgns/my_game.pgn\")\n```\nPGN files also support single line and end of line comments starting with \"#\".\n\n### Poker Evaluator\nThe evaluator module returns the rank of the best 5-card hand from a list of 5 to 7 cards.\nThe rank is a number from 1 (strongest) to 7462 (weakest).\n\n```python\nfrom texasholdem import Card\nfrom texasholdem.evaluator import  evaluate, rank_to_string\n\nassert evaluate(cards=[Card(\"Kd\"), Card(\"5d\")],\n                board=[Card(\"Qd\"),\n                       Card(\"6d\"),\n                       Card(\"5s\"),\n                       Card(\"2d\"),\n                       Card(\"5h\")]) == 927\nassert rank_to_string(927) == \"Flush, King High\"\n```\n\n### GUIs\nThe GUI package currently comes with a text-based GUI to play games from the command line. Coming later\nwill be web-app based GUIs.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A texasholdem python package",
    "version": "0.11.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/SirRender00/texasholdem/issues",
        "Documentation": "https://texasholdem.readthedocs.io/en/stable/",
        "Homepage": "https://github.com/SirRender00/texasholdem",
        "Repository": "https://github.com/SirRender00/texasholdem",
        "Wiki": "https://github.com/SirRender00/texasholdem/wiki"
    },
    "split_keywords": [
        "texasholdem",
        " holdem",
        " poker"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "572856080504701745757aae444e6cf90f94816f445545b40ccdf14d0699ee70",
                "md5": "b2ef80a126aee3b5880c481a3e99a153",
                "sha256": "7ce5dfc2d52dbd38ef89fbf62c0a1122e1bef8c587d235b806e06c0a640458e4"
            },
            "downloads": -1,
            "filename": "texasholdem-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2ef80a126aee3b5880c481a3e99a153",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 49176,
            "upload_time": "2024-09-21T16:49:39",
            "upload_time_iso_8601": "2024-09-21T16:49:39.205885Z",
            "url": "https://files.pythonhosted.org/packages/57/28/56080504701745757aae444e6cf90f94816f445545b40ccdf14d0699ee70/texasholdem-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "489fa26464fd4fbd506eada17ec5b26556b4fec25d2143a67fad58af6762557f",
                "md5": "1746d8bbb85e54a930b304150e0d16c0",
                "sha256": "3795c2e24021e3a3cae22fa2ffa04f1da539d662005f02c5d72728dc92e55402"
            },
            "downloads": -1,
            "filename": "texasholdem-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1746d8bbb85e54a930b304150e0d16c0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 40738,
            "upload_time": "2024-09-21T16:49:40",
            "upload_time_iso_8601": "2024-09-21T16:49:40.962587Z",
            "url": "https://files.pythonhosted.org/packages/48/9f/a26464fd4fbd506eada17ec5b26556b4fec25d2143a67fad58af6762557f/texasholdem-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-21 16:49:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SirRender00",
    "github_project": "texasholdem",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "texasholdem"
}
        
Elapsed time: 2.67851s