worldveil / deuces Goto Github PK
View Code? Open in Web Editor NEWA pure Python poker hand evaluation library
A pure Python poker hand evaluation library
Will you be providing the lookup for preflop equity?
evaluator.evaluate() function help asserts it accepts empty board. How is this done?
I need to evaluate a hand vs another hand in terms of probability prior to knowing the flop.
Thank you very much.
Given
hand1=['4h', 'Ac']
hand2=['8c', '5d']
and a corresponding 5 card board
board=['9d', 'Ah', 'Qs', '8s', '9s']
Feeding these in to the evaluator:
score = evaluator.evaluate(board, hand)
print evaluator.class_to_string(evaluator.get_rank_class(score))
The output is:
hand1 had a Two Pair. hand2 had a Two Pair.
However the correct output should be:
hand1 has a Pair. hand2 has a Pair.
Trying out your code! Thanks for creating.
The readme still has "import deuces"
and this sample needs () around it:
print evaluator.evaluate(board, hand)
Hi Will,
thanks for providing this module.
After installing deuces with: pip install deuces and doing: import deuces
I get the error:
No module named 'card'
I use python 3.5.2.
Thanks for any help.
By the way, this is also described here: http://stackoverflow.com/questions/40337024/import-error-python-no-module-named-card
I've prepared PR for supporting both of versions
The score of royal flush case is handled correctly but the class_to_string function returns it as a straight flush.
I have used 2to3 to run this library and I keep on running into a TypeError of:
TypeError: unsupported operand type(s) for >>: 'float' and 'int'
def get_lexographically_next_bit_sequence(self, bits): t = (bits | (bits - 1)) + 1 next = t | ((((t & -t) // (bits & -bits)) >> 1) - 1) yield next while True: t = (next | (next - 1)) + 1 next = t | ((((t & -t) // (next & -next)) >> 1) - 1) yield next
I have tried other parts of the library and they work, so I'm pretty confident that 2to3 worked fine. It's only when I load the evaluator that this message pops up. Any thoughts?
I am utilizing deuces in an AI project. I have a client written up for it that utilizes the console for player input and output. This is all well and good, however when I run the client, the output for the card symbols refuses to convert correctly in command prompt. It could just be the logic in my code causing it, but I would appreciate assistance.
Here is an example of what I am seeing.
When two hands have same rank (tie), the results choose the winner with smaller index instead of concluded as a tie game, for example:
Dealing a new hand...
The board:
[ 9 ♠ ] , [ 2 ❤ ] , [ 6 ♦ ] , [ 7 ♠ ] , [ 4 ♣ ]
Player 1's cards:
[ 8 ♦ ] , [ Q ♣ ]
Player 2's cards:
[ 8 ♣ ] , [ Q ♠ ]
Player 1 hand rank = 7147 (High Card)
Player 2 hand rank = 7147 (High Card)
========== FLOP ==========
Player 1 hand = High Card, percentage rank among all hands = 0.958858
Player 2 hand = High Card, percentage rank among all hands = 0.958858
Player 1 hand is currently winning.
========== TURN ==========
Player 1 hand = High Card, percentage rank among all hands = 0.957786
Player 2 hand = High Card, percentage rank among all hands = 0.957786
Player 1 hand is currently winning.
========== RIVER ==========
Player 1 hand = High Card, percentage rank among all hands = 0.957786
Player 2 hand = High Card, percentage rank among all hands = 0.957786
========== HAND OVER ==========
Player 1 is the winner with a High Card
i run this:
from deuces import Card, Evaluator, Deck
evaluator = Evaluator()
for x in range(0, 1000):
deck = Deck()
board = [
Card.new('2h'),
Card.new('2s'),
Card.new('Jc')
]
board = board + deck.draw(2)
player1_hand = deck.draw(2)
p1_score = evaluator.evaluate(board, player1_hand)
p1_class = evaluator.get_rank_class(p1_score)
print "%s" % (evaluator.class_to_string(p1_class))
i get this (and similar) errors (it works maybe one third of the time and two thirds of the time gives the error):
File "go.py", line 17, in
p1_score = evaluator.evaluate(board, player1_hand)
File "/home/abc/omattekstit/cpoker/deuces/oma/deuces/evaluator.py", line 35, in evaluate
return self.hand_size_maplen(all_cards)
File "/home/abc/omattekstit/cpoker/deuces/oma/deuces/evaluator.py", line 84, in _seven
score = self._five(combo)
File "/home/abc/omattekstit/cpoker/deuces/oma/deuces/evaluator.py", line 49, in _five
return self.table.flush_lookup[prime]
KeyError: 10846
I just installed deuces with the command:
sudo pip3 install deuces (also tried without sudo but that doesn't work)
But when I do import deuces in a simple script it gives me following error:
Traceback (most recent call last):
File "main.py", line 1, in
import deuces
File "/usr/local/lib/python3.5/dist-packages/deuces/init.py", line 1, in
from card import Card
ImportError: No module named 'card'
What's the problem and how do I properly install deuces?
Please help me.
According to evaluator.py line 31, the evaluate function supports an empty board.
However, the function produces an error when providing an empty board (list) or no board.
Hi,
I read your evaluation code and Kev's "paper". But I don't understand what the rank really tells me. When I'm looking at some poker related code, a common thing seems to be, to run a couple of thousand samples (Monte Carlo) and check that way what the strength of a hand is. Is the rank the same? Just with super fast bit operations? I mean, when your rank is "1" that means I have the nuts, same as MC telling me I win 100% of the games sampled, correct?. Is it the same for hands in the "mid-field"?
Could you please share your thoughts on this?
Thx
import deuces
from deuces import Card
board = [Card.new('Jd'), Card.new('7h'), Card.new('Jc'), Card.new('Kh'), Card.new('Ks')]
hand1 = [Card.new('Ah'), Card.new('8h')]
hand2 = [Card.new('As'), Card.new('Qc')]
from deuces import Evaluator
evaluator = Evaluator()
print evaluator.evaluate(board, hand1)
2611
print evaluator.evaluate(board, hand2)
2611
Shouldn't hand2 be the stronger hand? Or does deuces pick the highest card only as the kicker?
According to this: https://en.wikipedia.org/wiki/Kicker_(poker) -- the second hole card should be considered as well, or am I missing something?
from deuces import Card, Evaluator
evaluator = Evaluator()
straight_flush = [Card.new(x) for x in ['Ah', '2h', '3h', '4h', '5h']]
four_of_a_kind = [Card.new(x) for x in ['Ah', 'As', 'Ac', 'Ad', 'Kh']]
rank_sf = evaluator.evaluate([], straight_flush)
rank_quads = evaluator.evaluate([], four_of_a_kind)
evaluator.class_to_string(evaluator.get_rank_class(rank_sf))
evaluator.class_to_string(evaluator.get_rank_class(rank_quads))
Reports the 5-high SF as a 'Four of a Kind'. I want to fix this with a PR, but I the evaluator code is too fancy for me.
This is not an issue, so much as a question or request: How would you get or highlight just the cards that comprised the best hand for a player? So for example, say the player has what they need for a flush, how could I isolate just those cards from the total of 7 cards? Is there a way to do it from the library as it exists now? If not, any tips on how to achieve that?
Just wanted to share my 7 card Python evaluator with you. Just 10 lines of active Python code and a lookup table.
Given
hand1=['Jd', 'Th']
hand2=['9c', 'Qh']
and a corresponding 5 card board
board=['2s', '9h', '7h', 'Qc', 'Tc'].
Feeding these in to the evaluator:
score = evaluator.evaluate(board, hand)
print evaluator.class_to_string(evaluator.get_rank_class(score))
The output is:
hand1 has a Pair. hand2 has a Pair.
However the correct output should be:
hand1 has a Pair. hand2 has two Pairs.
I was trying to use this library and I kept on getting this error:
Traceback (most recent call last):
File "c:\Users\rattl\OneDrive\Desktop\PROJECTS\poker.py", line 1, in
from card import Card
ModuleNotFoundError: No module named 'card'
I tried to re-write this code with cython
On my dev branch
$ python3 perf_deuces.py
7 card evaluation:
[] Deuces: Average time per evaluation: 0.000006
[] Decues: Evaluations per second = 155845.607360
6 card evaluation:
[] Deuces: Average time per evaluation: 0.000004
[] Decues: Evaluations per second = 283565.609514
5 card evaluation:
[] Deuces: Average time per evaluation: 0.000001
[] Decues: Evaluations per second = 1019817.156195
On master branch
$ python2 perf_deuces.py
7 card evaluation:
[] Deuces: Average time per evaluation: 0.000038
[] Decues: Evaluations per second = 26337.395638
6 card evaluation:
[] Deuces: Average time per evaluation: 0.000013
[] Decues: Evaluations per second = 78230.631209
5 card evaluation:
[] Deuces: Average time per evaluation: 0.000002
[] Decues: Evaluations per second = 430052.701733
I don't expect cython can beat C implementation, while I think we can find a balance between python's convinience and performance.
I hope you can have a try on my fork. Looking to your ideas.
I'm trying to use your library in my project but when i import the library as:
from libraries.deuces import *
the system throws the error:
Traceback (most recent call last):
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\poker_game.py", line 6, in
from libraries.deuces import *
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\libraries\deuces__init__.py", line 1, in
from .card import Card
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\libraries\deuces\card.py", line 199
print Card.int_to_pretty_str(card_int)
^
SyntaxError: invalid syntax
if i comment the print it shows other errors like :
Traceback (most recent call last):
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\poker_game.py", line 6, in
from libraries.deuces import *
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\libraries\deuces__init__.py", line 1, in
from .card import Card
File "C:\Users\jorge\Desktop\Poker_AI\poker_game\src\libraries\deuces\card.py", line 214
print output
^
SyntaxError: Missing parentheses in call to 'print'
COULD BE A PYTHON VERSION ERROR ??
i try useing python versions: 2.7.6 and 3.3.3
thanks for all
jorge Aleman Gonzalez
Steps to reproduce
hole1=['Ks', '3d']
hole2=['3h', 'Qs']
board=['2d', '7h', '7s', '2s', '7c']
Feeding these in to the evaluator:
score = evaluator.evaluate(board, hole1)
print evaluator.class_to_string(evaluator.get_rank_class(score))
score = evaluator.evaluate(board, hole2)
print evaluator.class_to_string(evaluator.get_rank_class(score))
Output
Player P1-3000 had a Full House. Player P2-3001 had a Full House.
Problem Description
Neither player has one of their hole cards in play.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.