
Show HN: A simple Poker API to calculate the winning hand/s - GFuller
https://www.pokerapi.dev/
======
eximius
I have a sudden urge to extend this to calculating probabilities and to buy a
pair of smart glasses.

~~~
gexla
This has been a standard tool in remote poker for years. That tooling has even
included hand histories for your opponent. One of the last great new players
to blow up the poker scene before "Black Friday" almost went bust in a match
where his opponent analyzed his hand history. You wouldn't gain an edge with
these tools, you would be way behind if you didn't use them.

Running the calculations in your head isn't hard. You can get it with practice
and it's an obvious step for being a good poker player.

There's a huge difference in quality of players in virtual gaming vs "B&M"
(bricks and mortar, or playing face to face.) The world mourned the poker
scene after Black Friday because the market for horrible players with money to
blow disappeared. This left the hard core grinders with nobody to fish but
each other. I suppose this would be much like potential competition in a world
of WFH vs requiring your presence in one of the most expensive cities in the
world.

There's still lots of horrible players in B&M games. You can do okay with just
a gut feel for the calculations in these games. A lot of players like to
gamble. It depends on the level of the game. As the blinds climb, the game
gets harder.

~~~
Semaphor
For anyone wondering, Black Friday seems to refer to this:
[https://en.wikipedia.org/wiki/United_States_v._Scheinberg](https://en.wikipedia.org/wiki/United_States_v._Scheinberg)

------
valuearb
I once had to write a version that worked for multiple games. Holdem, Omaha,
Omaha 8 or better, Ace to Five, Deuce to Seven, and Badugi. I did it using
inheritance, having high and low hand classes. The low ball games just reverse
ordinary logic, but Omaha 8 needed both and the 8 or better restrictions. The
Badugi class rewrote everything entirely.

When I finally finished I was asked to add Stud, Badeucy and Badacey. That’s
when I quit.

~~~
notimetorelax
Would you do this in a different way now?

~~~
valuearb
I wouldn’t do it in Objective C again, that’s for sure.

But no, I think the class structure worked well for this. Just too many
esoteric rules in these games. And it’s getting worse from what I hear of the
high stakes games. Archey was just getting popular when I quit and now there
is like a half dozen new games they play. It’s a constant arms race to see who
can master a new set of rules to skin the fish with.

~~~
cheeze
As crazy as it sounds, this is why I'd try to keep it simple and just keep
each implementation separate. Sure I'd save some keystrokes having a base
abstraction and whatnot, but I feel like Poker is one of those "i'll make an
interface" traps that is much more complex than it originally seems

~~~
valuearb
The abstraction is pretty simple, and close to that. IIRC I had base Hand
object that defines a comparison routine that takes a Hand object.

The Hand object has a method that returns Card objects by index with a high to
low order so subclasses can do their comparisons in either 4 or 5 card games.

The you need like a best hand method, so games like Holdem that make best 5
card hands out of 7 cards work. Then a bunch of utility functions.

It’s also useful to have your Card objects have their comparison functions.

------
PaulRobinson
What are you using under the hood?

I’ve been using poker-eval for a few projects but it seems its now
abandonware, with few updates out there.

I’m tempted to port it to Go and/or Rust to keep it alive, but I’m interested
in what else people are using out there for poker hand evaluation.

~~~
Zanni
If you don't need everything that's going on in poker-eval, you should be able
to roll your own two dozen lines of Python.

A poker hand evaluator is problem #54 at Project Euler. [0] Peter Norvig has a
solution there (which you can view after you submit your own correct solution)
that taught me a lot about Python-style and how it differs from C++ (which was
my mindset at the time).

[0] [https://projecteuler.net/problem=54](https://projecteuler.net/problem=54)

~~~
im3w1l
That's very nice, much shorter than mine. array[[i][/i]r] had me scratching my
head for a few minutes, when I realized those were stray italic tags. My only
complaint is he doesn't check for the wheel, but to be fair most solutions
don't seem to.

~~~
Zanni
The wheel is excluded by the problem definition (or rather, not specifically
included). The ace only counts as a high card here.

~~~
dragonwriter
> The wheel is excluded by the problem definition (or rather, not specifically
> included).

Excluded was correct, if only indirectly: a straight is defined as five cards
of consecutive value and aces are explicitly the highest (and not also the
lowest) values, so the wheel is not a valid straight by the definition given.

------
kuroguro
Reminds me of the 2+2 poker hand evaluator - they basically built an insanely
fast giant lookup table that fit in ~100megs of ram IIRC.

The main idea was to do monte-carlo simulations and give you your odds of
winning at any point in the game by dealing random cards for the unknowns.

Interesting read on that and other evaluators as well:

[http://web.archive.org/web/20130116102452/http://www.codingt...](http://web.archive.org/web/20130116102452/http://www.codingthewheel.com/archives/poker-
hand-evaluator-roundup#2p2)

~~~
mypalmike
With a fast evaluator you generally don't need to do Monte Carlo approximation
- you can just brute force all combinations.

------
Gustek
One of my side projects was to make a game where you need to calculate your
odds correctly as fast as possible but main goal was to learn some TypeScript
so I lost interest after I was satisfied.

Anyway, I got at least one "game" done, you need to correctly count your outs.
It is not perfect but covers most cases well.

[https://github.com/GustekDev/poker-odds-
game](https://github.com/GustekDev/poker-odds-game)

------
ChicagoDave
I have an algorithm in C# that converts hands to numerical values from
0.highcard, 1.pair, 2.twopair, 3.trips ... to 9 (royal flush). From there it
can compare the hands and determine the winner(s).

------
tantalor
Calculating odds would be more interesting

~~~
samdwilson
I agree. Not sure how this helps improve poker play.

~~~
Bnshsysjab
I doubt it’s supposed to, it’s to calculate who wins when writing your own
poker implementation. I am not the author, but calculating the winner is non
trivial.

~~~
exdsq
Is it not? The win criteria is well specified so just iterate downwards from
the highest priority win until you find a match?

~~~
Bnshsysjab
Sure, but that gets complicated when comparing two matching hands (flush vs
flush, 2 pair vs 2pair). It’s more than a 50 line problem to solve.

~~~
exdsq
Okay fair it’s more than 50 lines, I guess my definition of non-trivial is
something you can’t quickly think of a design for. I’ll try it later and see
if there’s some gotchas I can’t think of :)

------
crobertsbmw
You want to buy deckofcardsapi.com?

