Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3f1985f
python3 fixes for perf_deuces, move to top level and rename to perf, …
ihendley Dec 11, 2017
5679e36
update README.md
ihendley Dec 11, 2017
a03fea5
update README.md
ihendley Dec 11, 2017
b7eab65
fix installation instructions and describe fork
ihendley Dec 11, 2017
8c2aa94
reflect rename in README.md
ihendley Dec 11, 2017
4aaad56
refactor for repo rename
ihendley Dec 11, 2017
1080c12
indicate Python 3 support in setup.py
ihendley Dec 11, 2017
1ba0c11
fixed setup.py description
ihendley Dec 11, 2017
544b940
update installation instructions for pypi
ihendley Dec 11, 2017
ab83b0b
Update README.md
ihendley Dec 13, 2017
262a4fb
Update README.md
ihendley Dec 13, 2017
dcd3098
Update README.md
ihendley Dec 13, 2017
4e4e023
f string isn't supported by python 3.5
Feb 22, 2018
1f4c1f4
f string isn't supported by python 3.5
Feb 22, 2018
d4eb101
f string isn't supported by python 3.5
Feb 22, 2018
c9cdcee
Merge pull request #1 from chuchuhao/master
ihendley Mar 3, 2018
f7505e6
pretty print methods should return the string, not just print
gitblight1 May 31, 2018
3f24fe0
Added 1 to all winners' index
yw10 Aug 15, 2018
b54138f
Merge pull request #2 from gitblight1/master
ihendley Aug 21, 2018
3372af5
Merge pull request #3 from yw10/master
ihendley Aug 21, 2018
172d8d3
cleanup and version bump
ihendley Aug 21, 2018
9263eff
move license to own file and convert readme to rst
ihendley Aug 21, 2018
8d05d4f
version bump for pypi
ihendley Aug 21, 2018
f018bf7
Fix typo
scascar Jun 19, 2019
70b481c
Merge pull request #4 from scascar/patch-1
ihendley Aug 13, 2019
71c0c55
fix card and rank printing, add royal flush rank, add four-color deck
ihendley May 4, 2022
9a9df7d
add type hints, various bug fixes and cleanup
ihendley May 5, 2022
1836be8
add plo evaluation and deck seeding
ihendley Jun 21, 2022
ef1e8b2
fix imports
ihendley Jun 21, 2022
01cb5f2
fix imports
ihendley Jun 21, 2022
2d5ce1f
Add unicode support to Card.new
Chazzz Feb 10, 2023
0f2f4ff
Merge pull request #13 from Chazzz/Chazzz-unicode-support-card-new
ihendley Feb 11, 2023
c856e89
Fix 104 card deck
NutCr4cker12 Mar 8, 2023
70fbaad
Merge pull request #15 from NutCr4cker12/master
ihendley Mar 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2013 Will Drevo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
172 changes: 0 additions & 172 deletions README.md

This file was deleted.

148 changes: 148 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
Treys
=====

A pure Python poker hand evaluation library

::

[ 3 ❤ ] , [ 3 ♠ ]

Installation
------------

::

$ pip install treys

Implementation notes
--------------------

Treys is a Python 3 port of
`Deuces <https://github.com/worldveil/deuces>`__ based on the initial work in
`msaindon’s <https://github.com/msaindon/deuces>`__ fork. Deuces was written
by `Will Drevo <http://willdrevo.com/>`__ for the MIT Pokerbots Competition.

Treys is lightweight and fast. All lookups are done with bit arithmetic and
dictionary lookups. That said, Treys won’t beat a C implemenation (~250k
eval/s) but it is useful for situations where Python is required or
where bots are allocated reasonable thinking time (human time scale).

Treys handles 5, 6, and 7 card hand lookups. The 6 and 7 card lookups
are done by combinatorially evaluating the 5 card choices.

Usage
-----

Treys is easy to set up and use.

.. code:: python

>>> from treys import Card
>>> card = Card.new('Qh')

Card objects are represented as integers to keep Treys performant and
lightweight.

Now let’s create the board and an example Texas Hold’em hand:

.. code:: python

>>> board = [
>>> Card.new('Ah'),
>>> Card.new('Kd'),
>>> Card.new('Jc')
>>> ]
>>> hand = [
>>> Card.new('Qs'),
>>> Card.new('Th')
>>> ]

Pretty print card integers to the terminal:

::

>>> Card.print_pretty_cards(board + hand)
[ A ❤ ] , [ K ♦ ] , [ J ♣ ] , [ Q ♠ ] , [ T ❤ ]

If you have `termcolor <http://pypi.python.org/pypi/termcolor>`__
installed, they will be colored as well.

Otherwise move straight to evaluating your hand strength:

.. code:: python

>>> from treys import Evaluator
>>> evaluator = Evaluator()
>>> print(evaluator.evaluate(board, hand))
1600

Hand strength is valued on a scale of 1 to 7462, where 1 is a Royal
Flush and 7462 is unsuited 7-5-4-3-2, as there are only 7642 distinctly
ranked hands in poker.

If you want to deal out cards randomly from a deck, you can also do that
with Treys:

.. code:: python

>>> from treys import Deck
>>> deck = Deck()
>>> board = deck.draw(5)
>>> player1_hand = deck.draw(2)
>>> player2_hand = deck.draw(2)

and print them:

::

>>> Card.print_pretty_cards(board)
[ 4 ♣ ] , [ A ♠ ] , [ 5 ♦ ] , [ K ♣ ] , [ 2 ♠ ]
>>> Card.print_pretty_cards(player1_hand)
[ 6 ♣ ] , [ 7 ❤ ]
>>> Card.print_pretty_cards(player2_hand)
[ A ♣ ] , [ 3 ❤ ]

Let’s evaluate both hands strength, and then bin them into classes, one
for each hand type (High Card, Pair, etc)

.. code:: python

>>> p1_score = evaluator.evaluate(board, player1_hand)
>>> p2_score = evaluator.evaluate(board, player2_hand)
>>> p1_class = evaluator.get_rank_class(p1_score)
>>> p2_class = evaluator.get_rank_class(p2_score)

or get a human-friendly string to describe the score,

::

>>> print("Player 1 hand rank = %d (%s)\n" % (p1_score, evaluator.class_to_string(p1_class)))
Player 1 hand rank = 6330 (High Card)

>>> print("Player 2 hand rank = %d (%s)\n" % (p2_score, evaluator.class_to_string(p2_class)))
Player 2 hand rank = 1609 (Straight)

or, coolest of all, get a blow-by-blow analysis of the stages of the
game with relation to hand strength:

::

>>> hands = [player1_hand, player2_hand]
>>> evaluator.hand_summary(board, hands)

========== FLOP ==========
Player 1 hand = High Card, percentage rank among all hands = 0.893192
Player 2 hand = Pair, percentage rank among all hands = 0.474672
Player 2 hand is currently winning.

========== TURN ==========
Player 1 hand = High Card, percentage rank among all hands = 0.848298
Player 2 hand = Pair, percentage rank among all hands = 0.452292
Player 2 hand is currently winning.

========== RIVER ==========
Player 1 hand = High Card, percentage rank among all hands = 0.848298
Player 2 hand = Straight, percentage rank among all hands = 0.215626

========== HAND OVER ==========
Player 2 is the winner with a Straight
Empty file removed __init__.py
Empty file.
3 changes: 0 additions & 3 deletions deuces/__init__.py

This file was deleted.

Loading