Poker-AI.org

Poker AI and Botting Discussion Forum
It is currently Mon Nov 13, 2023 12:30 pm

All times are UTC




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Mar 14, 2013 1:43 pm 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
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.


Attachments:
eval.zip [378.42 KiB]
Downloaded 2798 times
Top
 Profile  
 
PostPosted: Sat Mar 16, 2013 3:06 pm 
Offline
Junior Member
User avatar

Joined: Sun Mar 10, 2013 11:38 pm
Posts: 34
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.

_________________
www.bespokebots.com


Top
 Profile  
 
PostPosted: Sun Mar 17, 2013 1:15 am 
Offline
Site Admin
User avatar

Joined: Thu Feb 28, 2013 5:24 pm
Posts: 230
Excellent idea. Goes on the to-do list.

_________________
Cheers.


Top
 Profile  
 
PostPosted: Mon Apr 08, 2013 4:34 am 
Offline
Veteran Member

Joined: Wed Mar 20, 2013 1:43 am
Posts: 267
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;
   }


Top
 Profile  
 
PostPosted: Mon Apr 08, 2013 6:04 am 
Offline
Junior Member

Joined: Sun Apr 07, 2013 9:09 pm
Posts: 25
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?


Top
 Profile  
 
PostPosted: Sat Jun 29, 2013 1:46 am 
Offline
Junior Member

Joined: Sat Jun 29, 2013 1:43 am
Posts: 11
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


Top
 Profile  
 
PostPosted: Wed Aug 07, 2013 4:46 am 
Offline
Junior Member

Joined: Thu Mar 07, 2013 1:14 am
Posts: 12
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.


Top
 Profile  
 
PostPosted: Thu Oct 17, 2013 8:32 pm 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
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 ... :shock:
- 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.


Top
 Profile  
 
PostPosted: Fri Oct 18, 2013 11:06 am 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
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 ... :shock:
- 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


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 8:51 am 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
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.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 1:33 pm 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
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.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 4:17 pm 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
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 ? :o
If so, is there a reason that this has not been added in all the PerformanceTest that are under pokerai.game.eval package ?


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 4:30 pm 
Offline
Junior Member

Joined: Thu Mar 07, 2013 1:14 am
Posts: 12
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.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 5:06 pm 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
I've done that because I spoke of PerformanceTest in my previous post.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 5:51 pm 
Offline
Junior Member

Joined: Thu Mar 07, 2013 1:14 am
Posts: 12
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.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 6:41 pm 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
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 ?


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 7:39 pm 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
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 ? :o

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.


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 8:09 pm 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
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?


Top
 Profile  
 
PostPosted: Sat Oct 26, 2013 6:06 pm 
Offline
New Member

Joined: Tue May 14, 2013 7:59 am
Posts: 7
Thank you spears for your patience and time.
My range evaluator is now working ;)


Top
 Profile  
 
PostPosted: Sun Oct 27, 2013 8:10 am 
Offline
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group