You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

treys

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treys - pypi Package Compare versions

Comparing version
0.1.3
to
0.1.4
+19
LICENSE
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.
+156
-154

@@ -1,160 +0,8 @@

Metadata-Version: 1.1
Metadata-Version: 2.1
Name: treys
Version: 0.1.3
Version: 0.1.4
Summary: treys is a pure Python poker hand evaluation library
Home-page: https://github.com/ihendley/treys
Author: Will Drevo
Author-email: UNKNOWN
License: MIT
Description: 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>`__. Most of work is taken
from `msaindon’s <https://github.com/msaindon/deuces>`__ fork.
Treys (originally Deuces) was written by `Will
Drevo <http://willdrevo.com/>`__ for the MIT Pokerbots Competition. It
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. Once again, refer to my blog post for a more
mathematically complete explanation of why this is so.
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
Platform: UNKNOWN

@@ -168,1 +16,155 @@ Classifier: Development Status :: 3 - Alpha

Classifier: Topic :: Games/Entertainment
License-File: LICENSE
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>`__. Most of work is taken
from `msaindon’s <https://github.com/msaindon/deuces>`__ fork.
Treys (originally Deuces) was written by `Will
Drevo <http://willdrevo.com/>`__ for the MIT Pokerbots Competition. It
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. Once again, refer to my blog post for a more
mathematically complete explanation of why this is so.
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

@@ -9,3 +9,3 @@ """

name='treys',
version='0.1.3',
version='0.1.4',
description='treys is a pure Python poker hand evaluation library',

@@ -12,0 +12,0 @@ long_description=open('README.rst').read(),

@@ -1,160 +0,8 @@

Metadata-Version: 1.1
Metadata-Version: 2.1
Name: treys
Version: 0.1.3
Version: 0.1.4
Summary: treys is a pure Python poker hand evaluation library
Home-page: https://github.com/ihendley/treys
Author: Will Drevo
Author-email: UNKNOWN
License: MIT
Description: 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>`__. Most of work is taken
from `msaindon’s <https://github.com/msaindon/deuces>`__ fork.
Treys (originally Deuces) was written by `Will
Drevo <http://willdrevo.com/>`__ for the MIT Pokerbots Competition. It
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. Once again, refer to my blog post for a more
mathematically complete explanation of why this is so.
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
Platform: UNKNOWN

@@ -168,1 +16,155 @@ Classifier: Development Status :: 3 - Alpha

Classifier: Topic :: Games/Entertainment
License-File: LICENSE
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>`__. Most of work is taken
from `msaindon’s <https://github.com/msaindon/deuces>`__ fork.
Treys (originally Deuces) was written by `Will
Drevo <http://willdrevo.com/>`__ for the MIT Pokerbots Competition. It
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. Once again, refer to my blog post for a more
mathematically complete explanation of why this is so.
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

@@ -0,1 +1,2 @@

LICENSE
README.rst

@@ -2,0 +3,0 @@ setup.py

@@ -51,4 +51,7 @@ class Card:

# hearts and diamonds
PRETTY_REDS = [2, 4]
SUIT_COLORS = {
2: "red",
4: "blue",
8: "green"
}

@@ -186,6 +189,6 @@ @staticmethod

# if we need to color red
# color
s = Card.PRETTY_SUITS[suit_int]
if color and suit_int in Card.PRETTY_REDS:
s = colored(s, "red")
if color and suit_int in Card.SUIT_COLORS:
s = colored(s, Card.SUIT_COLORS[suit_int])

@@ -201,6 +204,6 @@ r = Card.STR_RANKS[rank_int]

"""
return Card.int_to_pretty_str(card_int)
print(Card.int_to_pretty_str(card_int))
@staticmethod
def print_pretty_cards(card_ints):
def ints_to_pretty_str(card_ints):
"""

@@ -218,1 +221,8 @@ Expects a list of cards in integer form.

return output
@staticmethod
def print_pretty_cards(card_ints):
"""
Expects a list of cards in integer form.
"""
print(Card.ints_to_pretty_str(card_ints))

@@ -31,4 +31,3 @@ import itertools

Supports empty board, etc very flexible. No input validation
because that's cycles!
No input validation because that's cycles!
"""

@@ -96,3 +95,5 @@ all_cards = cards + board

"""
if hr >= 0 and hr <= LookupTable.MAX_STRAIGHT_FLUSH:
if hr >= 0 and hr <= LookupTable.MAX_ROYAL_FLUSH:
return LookupTable.MAX_TO_RANK_CLASS[LookupTable.MAX_ROYAL_FLUSH]
elif hr <= LookupTable.MAX_STRAIGHT_FLUSH:
return LookupTable.MAX_TO_RANK_CLASS[LookupTable.MAX_STRAIGHT_FLUSH]

@@ -140,3 +141,3 @@ elif hr <= LookupTable.MAX_FOUR_OF_A_KIND:

for hand in hands:
assert len(hand) == 2, "Inavlid hand length"
assert len(hand) == 2, "Invalid hand length"

@@ -143,0 +144,0 @@ line_length = 10

@@ -28,2 +28,3 @@ import itertools

"""
MAX_ROYAL_FLUSH = 1
MAX_STRAIGHT_FLUSH = 10

@@ -40,2 +41,3 @@ MAX_FOUR_OF_A_KIND = 166

MAX_TO_RANK_CLASS = {
MAX_ROYAL_FLUSH: 0,
MAX_STRAIGHT_FLUSH: 1,

@@ -53,2 +55,3 @@ MAX_FOUR_OF_A_KIND: 2,

RANK_CLASS_TO_STRING = {
0: "Royal Flush",
1: "Straight Flush",

@@ -55,0 +58,0 @@ 2: "Four of a Kind",