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 Distributions
Hashes for phevaluator-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb0cfb6981808a387614bbee81e2b4022efefcea76cc5a3ad343ba9d297e9afa |
|
MD5 | 6ac4f9e598c66c2b5125abcbd8992e69 |
|
BLAKE2b-256 | 8b055c80dd04d390c288143a12d3a56d6415002726e6f55f3470e5401aea9987 |
Hashes for phevaluator-0.5.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea950b64fc45c66167995dc33e6aec7e19ab2cf7ed2ba8da249e40234512d462 |
|
MD5 | c109a0a03fb84e34adb0daf159555b2b |
|
BLAKE2b-256 | 54e321b8c50ecb2deeaa488ec410b61c1026912fd5ad22f7121f5737bb5fab53 |
Hashes for phevaluator-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b1baa769f75b6785c08f60ef53be2396bb86525eba319d1e69bd052fe952ea3 |
|
MD5 | 8bd89f539d74a387435269a640111a26 |
|
BLAKE2b-256 | ae12c17a8246092fef58b93eb4ed76f47254fe89d12eb57db0e0717ac5da5e16 |