Poker-AI.org http://poker-ai.org/phpbb/ |
|
Java 7-Card Poker Hand Evaluators http://poker-ai.org/phpbb/viewtopic.php?f=24&t=2390 |
Page 1 of 2 |
Author: | spears [ Thu Mar 14, 2013 1:43 pm ] | ||
Post subject: | Java 7-Card Poker Hand Evaluators | ||
Back in 2007 Indiana organised a contest for Java 7-Card Poker Hand Evaluators. This resulted in one of the longest threads on the old forum, now archived here The code from the contest wasn't saved in the archive so it's attached below.
|
Author: | birchy [ Sat Mar 16, 2013 3:06 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
I wonder if it would be worth having a "downloads" section for libraries like this? I know we can use the search function to find these posts but I'm sure the search function doesn't always spit out the results we expect it to? Or at least it didn't on pokerai.org. |
Author: | Coffee4tw [ Sun Mar 17, 2013 1:15 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Excellent idea. Goes on the to-do list. |
Author: | HontoNiBaka [ Mon Apr 08, 2013 4:34 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Thanks for uploading the evaluators again. I was just trying to replace my naive hand evaluator with the RayW evaluator and rewriting my equity method, but my JUnit tests fail. Am I using it correctly? getEval() returns the corresponding integer value for a Card object. Code: public static double riverEquity(HoleCards hero, Range range, Board board) {
double win = 0; double runs = 0; // VillainRange Range villainRange = range.cardRemoval(board.getBoardCards()); villainRange = villainRange.cardRemoval(hero.getCard1()); villainRange = villainRange.cardRemoval(hero.getCard2()); // All boardcards LinkedList<Card> boardCards = board.getBoardCards(); // u Values for the board in the lookup table int u0 = Generator.handRanks[53 + boardCards.get(0).getEval()]; int u1 = Generator.handRanks[u0 + boardCards.get(1).getEval()]; int u2 = Generator.handRanks[u1 + boardCards.get(2).getEval()]; int u3 = Generator.handRanks[u2 + boardCards.get(3).getEval()]; int u4 = Generator.handRanks[u3 + boardCards.get(4).getEval()]; // heroValue int h1 = Generator.handRanks[u4 + hero.getCard1().getEval()]; int h2 = Generator.handRanks[h1 + hero.getCard2().getEval()]; for (HoleCards villainCards : villainRange) { // Villain Value int v1 = Generator.handRanks[u4 + villainCards.getCard1().getEval()]; int v2 = Generator.handRanks[v1 + villainCards.getCard2().getEval()]; System.out.print(h2 + " "); System.out.println(v2); if (h2 > v2) { win++; runs++; } else if (h2 < v2) { runs++; } else { win = win + 0.5; runs++; } } return win / runs; } |
Author: | Blub478 [ Mon Apr 08, 2013 6:04 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Unfortunatly, I don't have any experience using Java. Is there anyone using this evaluator as a compiled library and is willing to publish it? |
Author: | Sharkfacepoker [ Sat Jun 29, 2013 1:46 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
HontoNiBaka wrote: Thanks for uploading the evaluators again. I was just trying to replace my naive hand evaluator with the RayW evaluator and rewriting my equity method, but my JUnit tests fail. Am I using it correctly? getEval() returns the corresponding integer value for a Card object. Code: public static double riverEquity(HoleCards hero, Range range, Board board) { double win = 0; double runs = 0; // VillainRange Range villainRange = range.cardRemoval(board.getBoardCards()); villainRange = villainRange.cardRemoval(hero.getCard1()); villainRange = villainRange.cardRemoval(hero.getCard2()); // All boardcards LinkedList<Card> boardCards = board.getBoardCards(); // u Values for the board in the lookup table int u0 = Generator.handRanks[53 + boardCards.get(0).getEval()]; int u1 = Generator.handRanks[u0 + boardCards.get(1).getEval()]; int u2 = Generator.handRanks[u1 + boardCards.get(2).getEval()]; int u3 = Generator.handRanks[u2 + boardCards.get(3).getEval()]; int u4 = Generator.handRanks[u3 + boardCards.get(4).getEval()]; // heroValue int h1 = Generator.handRanks[u4 + hero.getCard1().getEval()]; int h2 = Generator.handRanks[h1 + hero.getCard2().getEval()]; for (HoleCards villainCards : villainRange) { // Villain Value int v1 = Generator.handRanks[u4 + villainCards.getCard1().getEval()]; int v2 = Generator.handRanks[v1 + villainCards.getCard2().getEval()]; System.out.print(h2 + " "); System.out.println(v2); if (h2 > v2) { win++; runs++; } else if (h2 < v2) { runs++; } else { win = win + 0.5; runs++; } } return win / runs; } I have not used Rays code however I did notice that win = win +0.5 only works if you have two players. If you have more than two players then you'll need to keep a count of each player that participated on that particular tie. for example win = win + 1 / NumberOfTiesCount |
Author: | iKNOWpoker [ Wed Aug 07, 2013 4:46 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
The OP should probably link to the zip from this post. http://www.poker-ai.org/archive/www.pok ... 913#p28913 It seems to be the latest version. I'm glad I just found this as I wasn't aware of some of the evaluators included there. |
Author: | bulgrozpok [ Thu Oct 17, 2013 8:32 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Hi all, Sorry for noob question, but I wonder how exactly RayW evaluator works. 3 specific questions: - what is the correspondance between integers and cards ? I'm asking this because in StableEvaluator it is given 2c = 1, 2d = 2 etc... but in Card class which is in the same package, 2c = 0 ... - the value returned by StableEvaluator.handRanks array : the greater the better ? Or the other way round (like Cactus Kev evaluator that orders hands from 1 (strongest) to 7,462 (weakest) ) - does it work for 5 , 6 and 7 cards ? Thanks. |
Author: | spears [ Fri Oct 18, 2013 11:06 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
bulgrozpok wrote: Hi all, Sorry for noob question, but I wonder how exactly RayW evaluator works. 3 specific questions: - what is the correspondance between integers and cards ? I'm asking this because in StableEvaluator it is given 2c = 1, 2d = 2 etc... but in Card class which is in the same package, 2c = 0 ... - the value returned by StableEvaluator.handRanks array : the greater the better ? Or the other way round (like Cactus Kev evaluator that orders hands from 1 (strongest) to 7,462 (weakest) ) - does it work for 5 , 6 and 7 cards ? Thanks. - viewtopic.php?f=24&t=2448 - handRanks array contains ints that in some cases encode a state, and in others a rank and hand type - http://poker-ai.org/archive/pokerai.org ... &start=170 |
Author: | bulgrozpok [ Sat Oct 19, 2013 8:51 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
spears wrote: - handRanks array contains ints that in some cases encode a state, and in others a rank and hand type So I have to do this to retrieve handCategory : Code: int handCategory = handRanks >> 12 (taken from CTW). Is it the same instruction in java ?And after that, the higher handCategory the better ? And if handCategory is the same, I have to do this : Code: int rankWithinCategory = handRanks & 0x00000FFF (taken from CTW). Also, is it the same instruction in java ?And after that, the higher rankWithinCategory the better ? In fact, I'm a bit confused because I was trying to build upon jSim and developping a generic multirange evaluator that would be able to take any of the "raw" evaluators (RayW, SteveBrecher, mykey, supersonic and the like...). It seemed possible because all those evaluators had basically the same signatures like SomeClass.eval(long key) or SomeClass.eval(int[] hand). Some glue code and an interface in the multirange evaluator would have done the job. But what if the returned values of those evaluators are not comparable between them. I thought the rule 'the greater the returned value the better the hand' would be true amongst all the evaluators...but I'm not so sure now. And if this rule is wrong it means i have to develop a common system of classification for all the evaluators which will not be easy. |
Author: | spears [ Sat Oct 19, 2013 1:33 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Download eval.zip. Choose either pokerai.game.eval.spears2p2 (pretty, slow) or pokerai.game.eval.twoplustwo (ugly, fast), but don't confuse the two because IIRC there is a difference in convention. In pokerai.game.eval.spears2p2 many of your questions are answered in Tester.main() and StateTableEvaluator.getRank() pokerai.game.eval.twoplustwo is similar. Close reading of Evaluator.main() (63 loc) should tell you all you need to know. Well I don't think it is all that hard to create the generic multirange evaluator that you have in mind using http://en.wikipedia.org/wiki/Adapter_pattern, but you do need to know the "raw" evaluators input and and output conventions before writing it. But what is the point of this thing? If you have enough memory, and most people do these days, an evaluator based on pokerai.game.eval.twoplustwo is the fastest there is. Even that isn't a huge issue because you will probably need preflop, flop, turn and river lookup tables anyway. |
Author: | bulgrozpok [ Sat Oct 19, 2013 4:17 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Thanks for your reply. I'm a bit confused. I thought RayW (the fastest evaluator in town) was in spears2p2 package and that the difference with standard spearsevaluator was in the way to access data (by using handRanks[] array). What you are saying is that RayW is in fact in twoplustwo package ? If so, is there a reason that this has not been added in all the PerformanceTest that are under pokerai.game.eval package ? |
Author: | iKNOWpoker [ Sat Oct 19, 2013 4:30 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
I'd recommend you to download the zip from this post: http://www.poker-ai.org/archive/www.pok ... 913#p28913 . And have a look at the pokerai.game.eval.tests package for working performance tests. |
Author: | bulgrozpok [ Sat Oct 19, 2013 5:06 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
I've done that because I spoke of PerformanceTest in my previous post. |
Author: | iKNOWpoker [ Sat Oct 19, 2013 5:51 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
You spoke of "PerformanceTests that are under pokerai.game.eval package". I am speaking of EnumerationPerfomanceTest and RandomPerformanceTest in the package pokerai.game.eval.tests. Did you really download the zip from my link? It differs from the archive in the op of this thread. |
Author: | bulgrozpok [ Sat Oct 19, 2013 6:41 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
I have that zip file too installed in netbeans, but there is no reference of twoplustwo package. I've rapidly browsed the code and StateTableEvaluator seems to be very close to Generator. For the moment i'm testing with specific hand values. And I've an ArrayIndexOutOfBoundsException in the following case : Code: Card[] cards = Card.parseArray("AdAcTh4c2c"); StateTableEvaluator.getRank(cards); but there is no problem when retrieving rank with HR[HR[u4+c5]]. Is it normal ? |
Author: | spears [ Sat Oct 19, 2013 7:39 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
bulgrozpok wrote: I'm a bit confused. I thought RayW (the fastest evaluator in town) was in spears2p2 package and that the difference with standard spearsevaluator was in the way to access data (by using handRanks[] array). They are fundamentally the same. spears2p2 attempted to make it all nice and pretty with Card and Hand classes and the StateTableEvaluator.getRank methods. But as the comment on that method says it also makes it slow. bulgrozpok wrote: What you are saying is that RayW is in fact in twoplustwo package ? Yes. Ray Wooton was the chief brain behind all this, though there were other important contributions. None of these were mine. Read the 2p2 thread for a great example of crack programmers at work together. bulgrozpok wrote: If so, is there a reason that this has not been added in all the PerformanceTest that are under pokerai.game.eval package ? Haven't a clue. Ask Indiana Now I've spent as much time helping people use it as I did writing it. |
Author: | spears [ Sat Oct 19, 2013 8:09 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
bulgrozpok wrote: I have that zip file too installed in netbeans, but there is no reference of twoplustwo package. I've rapidly browsed the code and StateTableEvaluator seems to be very close to Generator. For the moment i'm testing with specific hand values. And I've an ArrayIndexOutOfBoundsException in the following case : Code: Card[] cards = Card.parseArray("AdAcTh4c2c"); StateTableEvaluator.getRank(cards); - twoplustwo is definitely in eval.zip above. - Generator isn't referenced anywhere so don't worry about it - "AdAcTh4c2c" is only 5 cards. StateTableEvaluator only works with 7 cards - Why does anyone ever want a 5 or 6 card evaluator? |
Author: | bulgrozpok [ Sat Oct 26, 2013 6:06 pm ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Thank you spears for your patience and time. My range evaluator is now working |
Author: | spears [ Sun Oct 27, 2013 8:10 am ] |
Post subject: | Re: Java 7-Card Poker Hand Evaluators |
Page 1 of 2 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |