13 ms·
Show HN: A simple Poker API to calculate the winning hand/s
- PaulRobinson 6y agoWhat 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.
- dberg 6y agoIm using a two plus two hand evaluator i found in Java. Curious as well couldn’t find good open source ones
- dave7 6y agoThe Twoplustwo evaluator is open source ("GPL, use as you like" specifically) Third party repo: https://github.com/tangentforks/TwoPlusTwoHandEvaluator https://github.com/tangentforks/TwoPlusTwoHandEvaluator Original statement of license: https://forumserver.twoplustwo.com/showpost.php?p=1482536&postcount=125 https://forumserver.twoplustwo.com/showpost.php?p=1482536&po...
- GFuller 6y agoThis is actually a side-project of a side-project, so I wanted to have a go at building the algo myself for a bit of fun/learning. I’m using Ruby under the hood...
- Zanni 6y agoIf 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 6y agoThat'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 6y agoThe wheel is excluded by the problem definition (or rather, not specifically included). The ace only counts as a high card here.
- im3w1l 6y agoFair enough. I think the problem statement does not have enough information by itself (especially concerning how rank is used to break ties for two pairs), and so it invites people to fill in the blanks using their knowledge of the game.
- dragonwriter 6y ago> 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.
- MauranKilom 6y agoIt's not apparent to me which part of evaluating poker hands would need to be updated over time... Just rebuilding for new framework versions?
- tylerchilds 6y agoEvaluating quality source code: 1. Does it have a badge that says "build passing"? 2. Does it have a bunch of stars on GitHub? 3. Does it have a commit in the past week? If so, wrap that in an npm package and publish it. Otherwise, it's AbAnDoNwArE.
- muzakthings 6y agoFor Python I'd recommend: https://github.com/worldveil/deuces https://github.com/worldveil/deuces
- markc 6y agoHere's an implementation in Clojure that scores hands and selects a winner. It handles low vs high ace in straights. https://gist.github.com/mchampine/dca965226148dfd19d5e4d7f3d4600c5 https://gist.github.com/mchampine/dca965226148dfd19d5e4d7f3d... Most of it was done for a weekly Clojure programming challenge run by Eric Normand in his PurelyFunctional.tv newsletter. You can see all the entries at https://gist.github.com/ericnormand/fbc9b6386a66c1ece590930db07ac604 https://gist.github.com/ericnormand/fbc9b6386a66c1ece590930d...
- joeleong 6y agohttps://github.com/andrewprock/pokerstove https://github.com/andrewprock/pokerstove
- tantalor 6y agoCalculating odds would be more interesting
- samdwilson 6y agoI agree. Not sure how this helps improve poker play.
- Bnshsysjab 6y agoI 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 6y agoIs it not? The win criteria is well specified so just iterate downwards from the highest priority win until you find a match?
- Bnshsysjab 6y agoSure, 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.
- 40four 6y agoI had the same initial reaction as the other person. Should be easy right? I think you’re right though, there are probably many more steps to getting this right than it seems on the surface. I kind of want to take your 50 line challenge however :) I always loved playing poker, might be a fun exercise.
- exdsq 6y agoOkay 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 6y agoYou want to buy deckofcardsapi.com?
- eximius 6y agoI have a sudden urge to extend this to calculating probabilities and to buy a pair of smart glasses.
- calvinmorrison 6y agoBasically you do that when you play poker. Knowing hand odds, pot sizes, number of players, are all numbers you use to do on the fly calculations and use to aid risk/reward assessment while on the table
- gexla 6y agoThis 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 6y agoFor 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
- metroholografix 6y agoI played online during the golden years (2003-2010), made a lot of money but also witnessed the progression of the game from shooting fish in a barrel to becoming significantly more demanding, even at low stakes. I started playing one table at a time, then two and ended up at 4 (6max NL holdem). One thing that always bothered me, especially when the HUDs + pokertracker became necessities, was that no poker site allowed you to switch usernames in order to nullify playing history that your opponents had accumulated. Eventually, this ruined the game for me as it completely changed the dynamics and took away a lot of possibilities and excitement. I also saw limit holdem be completely destroyed by algorithms and bots, long before it became so obvious that most stopped playing it altogether. I don't play these days but I'm wondering as to what extent shorthanded NL is being algorithmically exploited.
- ChicagoDave 6y agoI 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).
- valuearb 6y agoI 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 6y agoWould you do this in a different way now?
- valuearb 6y agoI 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 6y agoAs 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 6y agoThe 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.
- Gustek 6y agoOne 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
- kuroguro 6y agoReminds 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.codingthewheel.com/archives/poker-hand-evaluator-roundup#2p2 http://web.archive.org/web/20130116102452/http://www.codingt...
- mypalmike 6y agoWith a fast evaluator you generally don't need to do Monte Carlo approximation - you can just brute force all combinations.