Skip to main content

PH Evaluator - an efficient Poker Hand Evaluator based on a Perfect Hash algorithm

Project description

PH Evaluator Python package (phevaluator)

GitHub Workflow Status PyPI version PyPI downloads Apache_2.0

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.

  • from release on PyPI
    pip install phevaluator
    
  • from source code
    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 a format like: 'Ah' or '2C'). Usage examples can be seen in examples.py.

Test

  • The pre-calculated tables (phevaluator.tables) are tested by comparing them with the tables generated by test codes.
  • The functionality of the evaluators is tested by comparing with the JSON files generated by the original C++ evaluator.
  • The functionality of the other modules is tested by its purposes.
python3 -m unittest discover -v

Development

  • install from source code with editable mode

    pip install -e .
    

    The installed package reflects changes to files inside the phevaluator folder automatically.

  • recommended to format with black before commit

    check where to correct (without formatting)

    black . --diff --color
    

    format all

    black .
    

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

phevaluator-0.5.0.3.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

phevaluator-0.5.0.3-py3-none-any.whl (3.7 MB view details)

Uploaded Python 3

File details

Details for the file phevaluator-0.5.0.3.tar.gz.

File metadata

  • Download URL: phevaluator-0.5.0.3.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • 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 phevaluator-0.5.0.3.tar.gz
Algorithm Hash digest
SHA256 9fcf591ee3e06deffe41bdbc53f363e6b75e2bdd4be2ab0d275a294521391a4b
MD5 c0a30bd89a80da69ed04f101c5017010
BLAKE2b-256 85a3e6f78c41a4b151fb48e6e871cb8d01987b760f4fd371c390a856263f72fc

See more details on using hashes here.

File details

Details for the file phevaluator-0.5.0.3-py3-none-any.whl.

File metadata

  • Download URL: phevaluator-0.5.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.7 MB
  • 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 phevaluator-0.5.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e48e298ffb9c259de9ab4e4baa8d06ce82e78922f396e72602207711757cc7
MD5 7a398c08d49cb6b5bb68046f140f0ed7
BLAKE2b-256 e7836737955d6b8338b7b49788fa0dc32b1e93d05114d1090cf37063c630a2f2

See more details on using hashes here.

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