PH Evaluator - an efficient Poker Hand Evaluator based on a Perfect Hash algorithm
Project description
PH Evaluator Python package (phevaluator)
Description
PH Evaluator is designed for evaluating poker hands with more than 5 cards. Instead of traversing all the combinations, it uses a perfect hash algorithm to get the hand strength from a pre-computed hash table, which only costs very few CPU cycles and considerably small memory (~100kb for the 7 card evaluation). With slight modification, the same algorithm can be also applied to evaluating Omaha poker hands.
Installation
The library requires Python 3.
- with
pip
pip install .
Using the library
The main function is the evaluate_cards
function.
from phevaluator import evaluate_cards
p1 = evaluate_cards("9c", "4c", "4s", "9d", "4h", "Qc", "6c")
p2 = evaluate_cards("9c", "4c", "4s", "9d", "4h", "2c", "9h")
# Player 2 has a stronger hand
print(f"The rank of the hand in player 1 is {p1}") # 292
print(f"The rank of the hand in player 2 is {p2}") # 236
The function can take both numbers and card strings (with format like: 'Ah' or '2C'). Usage examples can be seen in examples.py
.
Test
There are 1000 random examples tested for each type of hand (5 cards, 6 cards, and 7 cards). The examples are stored in json files the tests folder and were generated with the original C++ evaluator.
- with current environment
python3 -m unittest discover -v
Development
-
recommended to format with
black
before commitcheck where to correct (without formatting)
black . --diff --color
format all
black .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file phevaluator-0.4.0.3.tar.gz
.
File metadata
- Download URL: phevaluator-0.4.0.3.tar.gz
- Upload date:
- Size: 104.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56e0c58a78f78b590f15c8c9672d65b68b3d345fd7316b1f8f1f02712539b9f0 |
|
MD5 | db6eb72a64d57dcbca10cb4d4bc14534 |
|
BLAKE2b-256 | 5ec2fca5534bc236e522e5617ff0ac75ed2ba6730efe8b309bc40bfe934a4936 |
File details
Details for the file phevaluator-0.4.0.3-py3-none-any.whl
.
File metadata
- Download URL: phevaluator-0.4.0.3-py3-none-any.whl
- Upload date:
- Size: 104.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75236d040098bd424adacacbc130265326bf19f82592637e5a51ee077fc7a488 |
|
MD5 | b5cd8e24ce60f615c79b089b605ddd62 |
|
BLAKE2b-256 | 3edddd1521f78aa993874e5674cfc6b7852b9ec7dbb093a70d97f49012fe6b61 |