Skip to main content

A fast Hold'em seven card evaluator

Project description

Fast Python Seven Card Hand Evaluation

Hand evaluator for 7 card hands using a 512kb lookup table (2^18 shorts). An evaluation consists of calculating the index plus a single lookup. This is a Python port of the 7 card hand evaluator used by Hold'em Resources Calculator.

Installation

The library can be installed straight from PyPI.

pip install sval

The only dependencies are numpy and numba and the library should work with all Python versions >= 3.6.

Hand format:

The evaluation methods take a single long to represent the hand using the lowest 52 bits.

bits 0-3: 2s2h2d2c bits 4-7: 3s3h3d3c etc.

The library supports encoding strings such as '2s2h' as longs. However, avoid using all encoding/decoding methods for performance critical code and work with the longs directly.

>>> import sval
>>> sval.encode_cards('2s2h')
12
>>> sval.cards_to_string(12)
'2s2h'

This allows to check for board collision or to combine cards with simple bit arithmetic.

>>> sval.cards_to_string(sval.encode_cards('2s2h') & sval.encode_cards('2hAs'))
'2h'
>>> sval.cards_to_string(sval.encode_cards('2s2h') | sval.encode_cards('2hAs'))
'As2s2h'

Seven Card Evaluation

Given a set of seven cards, we can lookup it's rank by calculating it's index. Higher ranks are better.

>>> hand_1 = sval.encode_cards('As5h')
>>> hand_2 = sval.encode_cards('Ad2d')
>>> board_1 = sval.encode_cards('Ah3d5hTsKd')
>>> value_1 = sval.calculate_index(hand_1 | board_1)
>>> value_2 = sval.calculate_index(hand_2 | board_1)
>>> sval.rank_lookup[value_1]
4117
>>> sval.rank_lookup[value_2]
4114

We can then easily calculate the hand strength, i.e. the percentage the hand is better than all other opponents hands, by comparing the hand vs all other possible hands. Effective hand strength is defined as (2 * ahead + tied)/(ahead + tied + behind) (EHS Wikipedia).

Development

Using nix-shell default.nix drops you in a development shell with all dependencies already installed.

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

sval-0.1.2.tar.gz (95.1 kB view details)

Uploaded Source

Built Distribution

sval-0.1.2-py3-none-any.whl (92.8 kB view details)

Uploaded Python 3

File details

Details for the file sval-0.1.2.tar.gz.

File metadata

  • Download URL: sval-0.1.2.tar.gz
  • Upload date:
  • Size: 95.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for sval-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e4f7b6546f34bdd71bcac82a47df628d44407c2d8a83cc186f37f68ebe143d21
MD5 783f77bd708f201f941882fa67f55532
BLAKE2b-256 577e8242c0cc5207b45fbfa9e05e90e9609b1782bed661ec4218b6446972a899

See more details on using hashes here.

File details

Details for the file sval-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sval-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for sval-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7278b0807bef9500a293e70a0cb2afc5e172794871a280cbedf7156621c2393
MD5 0a5ea42333334133c50d78a2f82b901a
BLAKE2b-256 1f6b1c7d69884500c7a5c71338c9b9451af9609a6abd4ff9dbd186a19b6188e9

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