Image Image Image




Post new topic Reply to topic  [ 399 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 20  Next
Author Message
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 7:30 am 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
What simple modfication?

There is no *u0 in Java.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 9:30 am 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
Just for the record, the state table evaluator java was lifted from http://forumserver.twoplustwo.com/showthreaded.php?Cat=0&Number=9765615&page=0&vc=1
and http://forumserver.twoplustwo.com/showthreaded.php?Cat=0&Number=9774228&page=0&vc=1 and then I added my port of Cactus Kev's 5 card evaluator. This credit is shown in the source.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 10:13 am 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
Adrian wrote:
No, not always, sometimes it returns a valid hand number.
For example if you put: c1=Ac, c2=Kc, c3=Qc, c4=Jc, C5=Tc, C6=Tc --> You get an Invalid Hand
But if you put c1=Ac, c2=Kc, c3=Qc, C4=Jc, C5=Td, now you are in state AcKcQcJcT, so the suit of the ten was lost. So if C6=Td then you get a valid state, the state AcKcQcJcTT that has hand value Straight Ace high.


Nicely explained. It's a shame though because it means you have to test for valid hands elsewhere, and that introduces a cost. But overall I guess it doesn't matter, because hand evaluation is no longer the rate limiting step.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 10:30 am 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
To get a 5 card evaluator

Adrian wrote:

Yes, replace the loops from the main function with this:

Code:

   for (c0 = 1; c0 < 53; c0++) {
      u0 = HR[53+c0];
      for (c1 = c0+1; c1 < 53; c1++) {
         u1 = HR[u0+c1];
         for (c2 = c1+1; c2 < 53; c2++) {
            u2 = HR[u1+c2];
            for (c3 = c2+1; c3 < 53; c3++) {
               u3 = HR[u2+c3];
               for (c4 = c3+1; c4 < 53; c4++) {
                  u4 = HR[u3+c4];
                  handTypeSum[HR[u4+0] >> 12]++;
                  count++;
//                  for (c5 = c4+1; c5 < 53; c5++) {
//                     u5 = HR[u4+c5];
//                     for (c6 = c5+1; c6 < 53; c6++) {
//                        handTypeSum[HR[u5+c6] >> 12]++;
//                        count++;
//                     }
//                  }
               }
            }
         }
      }
   }



You'll get the results from Cactus Kev:



I get an ArrayBoundsException. This is just for interest... personally I don't need this feature.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 2:56 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
indiana wrote:
What simple modfication?
There is no *u0 in Java.

I've posted the C (or C++ version) I don't know Java, but you can not declare a pointer to an integer?


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 3:09 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
spears wrote:
To get a 5 card evaluator

Adrian wrote:

Yes, replace the loops from the main function with this:

Code:

   for (c0 = 1; c0 < 53; c0++) {
      u0 = HR[53+c0];
      for (c1 = c0+1; c1 < 53; c1++) {
         u1 = HR[u0+c1];
         for (c2 = c1+1; c2 < 53; c2++) {
            u2 = HR[u1+c2];
            for (c3 = c2+1; c3 < 53; c3++) {
               u3 = HR[u2+c3];
               for (c4 = c3+1; c4 < 53; c4++) {
                  u4 = HR[u3+c4];
                  handTypeSum[HR[u4+0] >> 12]++;
                  count++;
//                  for (c5 = c4+1; c5 < 53; c5++) {
//                     u5 = HR[u4+c5];
//                     for (c6 = c5+1; c6 < 53; c6++) {
//                        handTypeSum[HR[u5+c6] >> 12]++;
//                        count++;
//                     }
//                  }
               }
            }
         }
      }
   }



You'll get the results from Cactus Kev:

I get an ArrayBoundsException. This is just for interest... personally I don't need this feature.


The Java version that you pointed thru the link has the following code in the main loop:
Code:
                                   handRank = handRanks[u5 + c6];
                                   handEnumerations[handRank >>> 12]++;
                                   equivalencyEnumerations[handRank >>> 12][handRank & 0xFFF]++;
                                   numHands++;

Did you tried with:
Code:
                                   handRank = handRanks[u3+c4];
                                   handEnumerations[handRank >>> 12]++;
                                   equivalencyEnumerations[handRank >>> 12][handRank & 0xFFF]++;
                                   numHands++;

Remember, I'm posting C++ code, you have to translate it to Java.
Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 3:16 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
Verbatim copy of the code that barfs up ArrayIndexOutOfBoundsException:

Code:
      for (c0 = 1; c0 < 53; c0++) {
          u0 = handRanks[53 + c0];
          for (c1 = c0 + 1; c1 < 53; c1++) {
              u1 = handRanks[u0 + c1];
              for (c2 = c1 + 1; c2 < 53; c2++) {
                  u2 = handRanks[u1 + c2];
                  for (c3 = c2 + 1; c3 < 53; c3++) {
                      u3 = handRanks[u2 + c3];
                      for (c4 = c3 + 1; c4 < 53; c4++) {
                         handRank = handRanks[u3 + c4];
                           handEnumerations[handRank >>> 12]++;
                           equivalencyEnumerations[handRank >>> 12][handRank & 0xFFF]++;
                           numHands++;
                      }
                  }
              }
          }
      }


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 3:22 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
Adrian20XX wrote:
I don't know Java, but you can not declare a pointer to an integer?
No pointers to any type available to programmer in Java; non primitives are references.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 3:39 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
spears wrote:
Adrian20XX wrote:
I don't know Java, but you can not declare a pointer to an integer?
No pointers to any type available to programmer in Java; non primitives are references.

Well, at least you can remove:
Code:
                           numHands++;

And add before the loop:
Code:
      numHands=133784560; // C(52;7)

There is no point in incrementing 133 million times an integer to compute a value you can compute outside the loop.
Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 3:41 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
spears wrote:
Verbatim copy of the code that barfs up ArrayIndexOutOfBoundsException:

Code:
      for (c0 = 1; c0 < 53; c0++) {
          u0 = handRanks[53 + c0];
          for (c1 = c0 + 1; c1 < 53; c1++) {
              u1 = handRanks[u0 + c1];
              for (c2 = c1 + 1; c2 < 53; c2++) {
                  u2 = handRanks[u1 + c2];
                  for (c3 = c2 + 1; c3 < 53; c3++) {
                      u3 = handRanks[u2 + c3];
                      for (c4 = c3 + 1; c4 < 53; c4++) {
                         handRank = handRanks[u3 + c4];
                           handEnumerations[handRank >>> 12]++;
                           equivalencyEnumerations[handRank >>> 12][handRank & 0xFFF]++;
                           numHands++;
                      }
                  }
              }
          }
      }


My guess is that should be a problem of the port to Java, it works perfectly on C++, as all the states of 5 and 6 cards have the current hand value stored on position 0.
Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 4:59 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
spears wrote:
Adrian wrote:
No, not always, sometimes it returns a valid hand number.
For example if you put: c1=Ac, c2=Kc, c3=Qc, c4=Jc, C5=Tc, C6=Tc --> You get an Invalid Hand
But if you put c1=Ac, c2=Kc, c3=Qc, C4=Jc, C5=Td, now you are in state AcKcQcJcT, so the suit of the ten was lost. So if C6=Td then you get a valid state, the state AcKcQcJcTT that has hand value Straight Ace high.


Nicely explained. It's a shame though because it means you have to test for valid hands elsewhere, and that introduces a cost. But overall I guess it doesn't matter, because hand evaluation is no longer the rate limiting step.

I would not say this introduces an extra cost, and I'll explain why.

Let's say you are evaluating AA against AKs pre-flop. Your higher level function that will traverse this hand spaces will discard for example the combo AcAd AcKc, and you do not want these two hands to go to the 7 cards evaluator and waste time doing not less than C(48;5)=1712304 calls (I think we can say C(49;5)=1906884 calls) to the 7 cards evaluator just to find out you have repeated Ac, and that all these calculations that were done with duplicated cards have to be discarded.

And let's say you are evaluating AcAd against KhKd. You here want to generate the C(48;5) combos that do not have repeated cards, you do not want to generate the C(52;5)=2598960, just to discard the 886656 combos that have one of the cards that are in the hole of a player.

And the correct combos can be sent, and in the reality they are actually sent, in both cases without any problem, it's part of the enumeration of the higher level function to generate the relevant combos to be evaluated.

So for me, there is a previous contract between the 7 card evaluator and the caller that it will get not duplicated cards. Not because the 7 cards evaluator does not detect the repeated cards always, but because the caller wants to get peak performance for the higher function that he is performing, and so the caller can assure the evaluator that he will never send repeated cards.

Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 5:55 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
Adrian20XX wrote:
I would not say this introduces an extra cost, and I'll explain why.


Having thought about it a bit more I agree. The cost outside this block is going to be the same or less than it is inside the block.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Apr 01, 2008 7:17 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Uploaded all the new code, and updaetd the OP with the latest results.
I have to catch up with your latest discussions thou.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Jump to state 3
PostPosted: Wed Apr 02, 2008 1:03 am 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
Hi,

I've just implemented the improvement I call "Jump to state 3", it is giving me a very small improvement (around 2.3%), but I'm still using the benchmark that computes also the hand types from the hand values, so I think you'll get a better improvement for the Sums only benchmark, but as I said before, in my view we are now close to the optimal version 7 cards evaluator using the LUT.

This is the code that is needed for the jump to state 3.
Still C or C++, you will not get Java from me for a long time.

BTW, as we are getting to a time for the calculation in which even a slightly event of the operating system like automatically updating a picture I have on vista on my left side might affect the timings, does any one of you that uses VM for day to day use imagine how we can use them in order to test the program in a more "stable" environment, like a VM with something like DOS? Does this make sense to you?

TIA & Regards ...

Code:
   int c0, c1, c2, c3, c4, c5, c6;
//   int u0, u1, u2, u3, u4, u5;
   int u3, u4, u5;
//   int *u0, *u1, *u2, *u3, *u4, *u5;
   int u2calculated;

   count = 133784560;

   u2calculated=73140-53;   // u2calculated=HR[HR[HR[53+1]+2]+3]-53;

   QueryPerformanceCounter(&timings);               // start High Precision clock

   for (c0 = 1; c0 < 53; c0++) {
//      u0 = HR[53+c0];
      for (c1 = c0+1; c1 < 53; c1++) {
//         u1 = HR[u0+c1];
         for (c2 = c1+1; c2 < 53; c2++) {
//            u2 = HR[u1+c2];
            u2calculated+=53;
//            if (u2!=u2calculated) {
//               printf("ERROR, Adrian F'd up, u2!=u2 calculated, u2=%d, u2calculated=%d\n",u2,u2calculated);
//            }
            for (c3 = c2+1; c3 < 53; c3++) {
//               u3 = HR[u2+c3];
               u3 = HR[u2calculated+c3];
               for (c4 = c3+1; c4 < 53; c4++) {
                  u4 = HR[u3+c4];
                  for (c5 = c4+1; c5 < 53; c5++) {
                     u5 = HR[u4+c5];
                     for (c6 = c5+1; c6 < 53; c6++) {
                        handTypeSum[HR[u5+c6] >> 12]++;
                     }
                  }
               }
            }
         }
      }
   }


Top
 Profile  
 
 Post subject: Re: Jump to state 3
PostPosted: Wed Apr 02, 2008 6:47 am 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
Adrian20XX wrote:
Hi, I've just implemented the improvement I call "Jump to state 3"

I've just realized this jump to state 3 is only good for the benchmark and can not be used in real cases (I think computing the number of the combination c0, c1, c2 will be more expensive than the lookups), I will work on a new one.
Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Wed Apr 02, 2008 8:00 pm 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
indiana wrote:
This is a contest for 7-card HoldEm Java Hand Evaluators...

(1) Spears adaptation of RayW LUT hand evaluator, http://pokerai.org/pf3, http://forumserver.twoplustwo.com
--- Hands per second: 142779680, hands 133784560, checksum 1528972275512, total time: 937
Remarks-1: There is one time evaluation tables loading for 1.547 seconds
Remarks-2: Using about 20M of memory, Holdem 7-cards only

I think you missed the number 1 here, it's 120MB, not 20MB.
Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Wed Apr 02, 2008 10:12 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Adrian20XX wrote:
I think you missed the number 1 here, it's 120MB, not 20MB.
Regards ...


Just measured this more reliably and it's even more about ~140M
Thanks

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Apr 03, 2008 12:11 am 
Offline
Senior member
User avatar

Posts: 223
Favourite Bot: N/A
indiana wrote:
(1) Spears adaptation of RayW LUT hand evaluator, http://pokerai.org/pf3, http://forumserver.twoplustwo.com
--- Hands per second: 142779680, hands 133784560, checksum 1528972275512, total time: 937
Remarks-1: There is one time evaluation tables loading for 1.547 seconds
Remarks-2: Using about ~140Mb of memory

Just measured this more reliably and it's even more about ~140M
Thanks

In some way this is inconsistent, the remark 1 considers that the table is already generated and it is loaded from disk. So if it's loaded from disk you don't need the array for the IDs, and only you need memory for HR:
int HR[32487834];
So, it requires 32487834*4/1024/1024=123.9 MB = 124MB
indiana wrote:
Remarks-2: Using about ~140Mb of memory, and works for Holdem 7-cards evaluations only

It's ironic, you don't put the message that is only good for Holdem on Cactus Kev for example (that is true) altough I know you didn't made it on pourpose just because now the other evaluators are almost irrevelevant, but you put this legend here that if it is not false at least it is very confusing, and I think you didn't fully understand the power of the LUT.
The LUT is only an efficient way to store hand values for not more than 7 cards. Note that RayW solution does not have it's own evaluator, this is the reason it requires to use an external evaluator (in this case the evaluator from Cactus Kev) to assign a value to a hand.
As I said, it's a way to acces the value for a hand that has been calculated in an elected way, doing suit compression in order to discard the irrelevant suits and keeping only the relevant suits at each point, and the value in the 7-th access (also in the access 5-th and 6-th).

Beside that, it works out of the box for Holdem 5 or 6 cards (there should be a problem with the porting to Java that is preventing spears to calculate 5 cards hands).

So for example, you can do Omaha Hi with it, just have to call it a lot of times and get the maximum.

And the most important thing of all this thread, you can achieve the dream of your life, having a state of the art lightning speed evaluator, and using at the same time your lovers code (Steve's) !!! :-)

This is a joke obviously, but at the same time it is not, because now you can use a faster method (the LUT) to evaluate hands for any other game that you have an external evaluator, even low or hi/low games, you just have to "plug" the external evaluator that is good for your game instead of Cactus Kev evaluator. So, as Steve's code is a particular case of an external evaluator, bingo, you got all the same games supported by Steve supported by the LUT.

And this is why I think the assertion that it is good only for Holdem is false (beside it was already false for Omaha Hi, or any high game with kickers, or a 5 or 6 card game high with kickers).

Regards ...


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Apr 03, 2008 1:27 am 
Offline
Senior member
User avatar

Posts: 465
Favourite Bot: Mine, of course!
I would like to thank Indiana and all of those who contributed evaluators and spent time helping out on this evaluation! This has been very helpful! I hope that I can return the favor in the future, because I have benefit from your efforts and am very grateful.


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Apr 03, 2008 8:03 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Adrian20XX wrote:
In some way this is inconsistent, the remark 1 considers that the table is already generated and it is loaded from disk. So if it's loaded from disk you don't need the array for the IDs, and only you need memory for HR:
int HR[32487834];
So, it requires 32487834*4/1024/1024=123.9 MB = 124MB

I simply measured how much memory is free before and after the initialization. So 140M is taken. If these arrays are kept staticly, then they will allocate the required memory. If they are not needed we have to clean them up, I can try this out. But to be honest 124 vs 140 isn't a big deal.

Adrian20XX wrote:
It's ironic, you don't put the message that is only good for Holdem on Cactus Kev for example (that is true) altough I know you didn't made it on purpose just because now the other evaluators are almost irrevelevant, but you put this legend here that if it is not false at least it is very confusing, and I think you didn't fully understand the power of the LUT. The LUT is only an efficient way to store hand values for not more than 7 cards. Note that RayW solution does not have it's own evaluator, this is the reason it requires to use an external evaluator (in this case the evaluator from Cactus Kev) to assign a value to a hand.

First, the other evaulators are not irrelevant, 140Mb (or 125) of memory is a serious thing. If you run VMWare setups for yur bots you can usually run them with 200M in total. If only the hand evaluator takes 150 of this, this is an issue. I think RayW did a great job, but Steve B (joiking or not) did that too :). And btw, saving/loading results from the files system like the current impl might also be problematic (or at least not nice) for bot environments.

Second thing is, remember that one key difference between this thread and 2+2 (e.g.) is that I put in focus working and availble for immediate download source code. Theoretical discussions are of course great, but at the end if the spears port of RayW works for holdem and not for stud or omaha low, it runs for holdem.

I understand very well the power of lookup tables, I have to admit that I did not realized that you can put in whatever values an external evaluator will calculate (this looks very good! - but doesn't change the point), and that the bug with 5 and 6 cards can be only in the java port. But this is what anyone looking at OP can download now. And everyone is encouraged to continue to submit working improvements and extensions of the existing code!

With all that said, I will try how to add in the OP comments something that encourages the the people to look and improve/extend further, instead of to choose Steve B as alternative for cases that the attached spears/RayW code does not handle now.

Adrian20XX wrote:
This is a joke obviously, but at the same time it is not, because now you can use a faster method (the LUT) to evaluate hands for any other game that you have an external evaluator, even low or hi/low games, you just have to "plug" the external evaluator that is good for your game instead of Cactus Kev evaluator. So, as Steve's code is a particular case of an external evaluator, bingo, you got all the same games supported by Steve supported by the LUT.


I would love if someone do this, and uploads it here. I will certainly come back to this when I have some more free time ...

P.S. Adrian, if you are comfortable with C++ I can add and maintain also the cpp version of it in the archive. I'll try to get this up and running.

_________________
indiana


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 399 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 20  Next


Who is online

Users browsing this forum: Google and 8 guests


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:
Jump to: