Image Image Image




Post new topic Reply to topic  [ 399 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 20  Next
Author Message
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Sun Nov 30, 2008 6:32 am 
Offline
Junior member
User avatar

Posts: 32
Favourite Bot: N/A
And I'd like to say thanks to spears and Indiana for thier discussion of this, as it has lead to me writing better optimized code (I hadnt thought of 'pre-stepping' through the lookup table, with known cards and only iterating the last few) but then I have only been using this evaluator for a few days, so thanks for showing me that technique...


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Sun Nov 30, 2008 12:21 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
I have now added LICENSE.TXT that should generally (with few exceptions, that also allow free use, distribution and modification) make available this source code under GPL v2 (or later).

Please check the attached license for issues, as well as remind me if I forgot to give credit to some member in this thread that had good contribution to the codebase (for now I mentioned myself, spears, adrianxx and timmy).

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Sun Nov 30, 2008 3:04 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
spears wrote:
I'm posting an interim fix here to get you going, but I want to do a bit more investigation and testing before committing.
The distribution is now corrected and contains some new test code.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Dec 16, 2008 4:13 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: ShoveOrFoldBot
Hi!

I downloaded the test-framework provided on the first page of this thread by Indiana and played around with the pokerai.game.eval.spears2p2-package. I got an ArrayIndexOutOfBoundsException in the getRank(Card[] cards) - method whenever I evaluated a 5 or 6-card hand. However, after modifying the procedure to

Code:
public static int getRank(Card[] cards) {
      //System.out.println("Getting rank..");
      //Card[] cards = sevenCardHand.toCards();
      
      
      int rank = 53;
      for (int i = 0; i < cards.length; i++) {
         int c = cards[i].ordinal() + 1;
         rank = handRanks[c + rank];
      }


      if (cards.length < 7 ) rank = handRanks[rank]; // <---- added this line
      
      //System.out.println("Got rank");
      int type = (rank >>> 12) - 1;
      rank = rank & 0xFFF;

      return offsets[type] + rank - 1;
   }


the problem was solved. But then again I don't really know what I am doing there, so I ran a cuple of tests and the results look OK. Is anyone able to confirm this change and the validity of the results?

Cheers,
Riverlucker


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Dec 16, 2008 5:43 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
@riverlucker You may be right, but I can't confirm it. You'd do us a valuable service if you test your theory against one of the other evaluators and report back. You would probably best to test against the spears package, as the rank numbering is either the same or easy to convert to.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 18, 2008 1:22 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: ShoveOrFoldBot
Hi Spears!

there are good and bad news! :)
In order to confirm the correctness of the changes I made, I ran the modified version of your P2P-implementation against your SixCardEvaluator / FiveCardEvaluator. Since your two implementations have a different understanding of ranks, I compared the relative strengths of hands rather than the absolute ranks.

The good news first: In 90% of the cases the numbers matched perfectly.
The bad news: In 10% of the cases, I got another ArrayIndexOutOfBounds-exception, because I always received a zero rank-value after the line
Code:
if (cards.length < 7 ) rank = handRanks[rank];

that caused the exception two lines later.

However, I found a very obscure pattern for that: Whenever I evaluated a 5/6-hand that contained the Ace of Spades (the card with the highest ordinal number as per your package's definition) AND at least 3 cards of Spades, I received this error. In all other cases it was fine. Since the P2P-algorithm works like a black box for me with zero understanding how it performs its calculations, I could only think of one quick-and-dirty solution for this: I swapped the suits of the cards whenever I found this pattern above.

Here's my change in Hand.java :
Code:
   public static Hand parse(String s) {
   
      if (s.length() < 14 && s.matches("((.)*s(.)*){3,}?") &&  s.matches("(.)*As(.)*"))
      {
         char replaceWith = s.matches("((.)*d(.)*){3,}?") ? 'c' : 'd'; 
         s = s.replace(replaceWith, 'x').replace('s', replaceWith).replace('x', 's');
      }   
      
      
      Hand result = new Hand();
      int noCards = s.length()/2;
      for (int i = 0; i < noCards; i++) {
         result.plus(Card.parse( s.substring(2*i, 2*i+2)));
      }
      return result;
   }


After this modification, I was able to match all results from around 2.000 random 5 and 6 card-hands, using the relative-strength metric and comparing it to the results of the SixCardEvaluator/FiveCardEvaluator.

I know that the modification in Hand.java is far from being optimal, because firstly it is bad for the performance and secondly it only works if you instantiate your Hand-object via Hand.parse(String)!

Can anyone come up with a more decent solution to this problem?

Cheers,
Riverlucker


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 18, 2008 1:59 pm 
Offline
PokerAI fellow
User avatar

Posts: 1239
Favourite Bot: my bot
@Riverlucker Thanks for trying.

You may be surprised to learn that my understanding of this code isn't great either: I just cobbled a bunch of stuff together from the 2+2 forum, cactus kev etc. The best explanation I found was by Darse on the PokerAcademy forum. Most of the handRanks array represents "states" in the "parsing" of a hand. The same cards in a different order will lead to the same state. When 7 cards are "parsed" the rank rather than a state is reached.

I'd say the problem lies either in calculation of handRanks, or how handRanks is used. It seems that we should be able to resolve this by comparing this implementation with the C implementation, which is said to work for 5 and 6 cards. I'm sorry to say this is just not a priority for me right now. I rarely use anything except a 7 card evaluator, and prefer Steve Brecher's code because of the lower memory requirement.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 18, 2008 2:04 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: ShoveOrFoldBot
Spears,
Thanks for your explanation.

Can you tell me which impl of Steve Brecher you are using? the one that is included in Indiana's test package runs like a dog for me, and is outperformed by both your implementations.

Also, how come you rarely use 5 and 6 card evaluators? For a Holedem Bot - assuming you are working on one - I don't see what else you would at Flop- or Turn-stage

Cheers,
Riverlucker


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 18, 2008 6:30 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Riverlucker wrote:
Can you tell me which impl of Steve Brecher you are using? the one that is included in Indiana's test package runs like a dog for me, and is outperformed by both your implementations.


Huh ?!

1) There is only one impl of Steve Brecher's in the archive
2) It's VERY FAST - almost as fast is the winner (see OP).

If you have doubts - maybe you just run the benchmark code over few of the imlpementations and post the results for comparison.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 18, 2008 8:46 pm 
Offline
New member
User avatar

Posts: 8
Favourite Bot: ShoveOrFoldBot
Hi!

Just tried Steve Brecher's algorithm again and I stand corrected, it does perform very well. Thanks for the hint.
However, while validating its results against Spears' algorithm, I stumbled accross an error in Steve Brechers's algorithm, in his 6-card evaluator to be precise. Somehow it does not seem to recognize a straight...

Code:
      CardSet board = new CardSet();
      board.add(new Card("3s"));
      board.add(new Card("5h"));
      board.add(new Card("6h"));
      board.add(new Card("Ts"));
            
      CardSet pockets = new CardSet();
      pockets.add(new Card("As"));
      pockets.add(new Card("2s"));

      CardSet hisPockets = new CardSet();
      hisPockets.add(new Card("4s"));
      hisPockets.add(new Card("7s"));
      
      CardSet myHand = new CardSet(board);
      myHand.addAll(pockets);
      
      CardSet hisHand = new CardSet(board);
      hisHand.addAll(hisPockets);

      System.out.println(HandEval.hand6Eval(HandEval.encode(myHand)));
      System.out.println(HandEval.hand6Eval(HandEval.encode(hisHand)));


Did anyone experience this problem as well?


Cheers,
Riverlucker


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Fri Dec 19, 2008 10:34 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
RiverLucker wrote:
Just tried Steve Brecher's algorithm again and I stand corrected, it does perform very well. Thanks for the hint.
However, while validating its results against Spears' algorithm, I stumbled accross an error in Steve Brechers's algorithm, in his 6-card evaluator to be precise. Somehow it does not seem to recognize a straight...


Ups.

How can we once and for all test all the evaluators for bugs? What I once did was generatings thousands of pairs of hands - and then checking with two different evaluators if they are classified in the same way (by their strength). This works for any two evaluators that returns int as hand strength.

I have tested only 7 card hands, thou ...

I will get back to that (don't have time right now) - but anyone is welcomed to post some class that does extensive testing for correctness of the evaluators.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Need coding help with RayW's enumerator
PostPosted: Tue Dec 23, 2008 9:47 am 
Offline
New member
User avatar

Posts: 3
Favourite Bot: oldie (mine)
hi guys, i'm not so great at c++ but need the evaluator, anyway, i'd appreciate some help.

i'm trying to enum "AA" against every hand for heads-up and i get 90%-10%, although i think it should be 85%-15%. can someone confirm AA has 85% equity?

win 88152082
loss 8791075
tie 2941243
total 99884400

here are my loops, any ideas where i went wrong?

//assuming first 5 cards are common, ph (hero score) versus pe (enemy score) diverge at
//cards 6 and 7. HR is RayW's lut.

Code:
int h0=49, h1=50; //AA. also made sure h0<h1
int win=0, loss=0, tie=0, total=0;
int c0, c1, c2, c3, c4, c5, c6;
int p0,p1,p2,p3,p4,ph,pe;

int h0=13, h1=17;
int win=0, loss=0, tie=0, total=0;
int c0, c1, c2, c3, c4, c5, c6;
int p0,p1,p2,p3,p4,ph,pe;

for (c0=1; c0<53; c0++){
   if (c0==h0){c0++;}
   if (c0==h1){c0++;}
   p0=HR[53+c0];
   for (c1=c0+1; c1<53;  c1++) {
      if (c1==h0){c1++;}
      if (c1==h1){c1++;}
      p1=HR[p0+c1];
      for (c2=c1+1; c2<53; c2++){
         if (c2==h0){c2++;}
         if (c2==h1){c2++;}
         p2=HR[p1+c2];
         for (c3=c2+1; c3<53; c3++){
            if (c3==h0){c3++;}
            if (c3==h1){c3++;}
            p3=HR[p2+c3];
            for (c4=c3+1; c4<53;  c4++) {
               if (c4==h0){c4++;}
               if (c4==h1){c4++;}
               p4=HR[p3+c4];
               ph=HR[p4+h0];
               ph=HR[ph+h1];

               for (c5=c4+1; c5<53; c5++){
                  if (c5==h0){c5++;}
                  if (c5==h1){c5++;}
                  for (c6=c5+1; c6<53; c6++){
                     if (c6==h0){c6++;}
                     if (c6==h1){c6++;}

                     pe=HR[p4+c5];
                     pe=HR[pe+c6];
                     if(ph>pe) win++;
                     if(pe>ph) loss++;
                     if(pe==ph) tie++;
                     total++;
                  }
               }
            }
         }
      }
   }
}


Top
 Profile E-mail  
 
 Post subject: Re: Need coding help with RayW's enumerator
PostPosted: Tue Dec 23, 2008 5:53 pm 
Offline
Junior member
User avatar

Posts: 29
Favourite Bot: none
kidzero wrote:
hi guys, i'm not so great at c++ but need the evaluator, anyway, i'd appreciate some help.

i'm trying to enum "AA" against every hand for heads-up and i get 90%-10%, although i think it should be 85%-15%. can someone confirm AA has 85% equity?



There are a few problems I see in your code.

1) Is there some reason h0, and h1 are defined twice? It looks like the 13, 17 are representing something other than AA


2) c5, and c6 are representing your opponents pocket cards, but in your implementation, they must be greater than the highest board card. That restriction does not represent reality.

3)
x in [0,1,2,3,4,5,6]
y in [0,1]

The test "if (cx == hy){ cx++;}" is bad.
if hy = 52, cx would be increased to 53, but the loop would still continue with this invalid value

Should use something like

Code:
for ( c0 = 1; c0 < 53; c0++} {
  if (!((c0 == h0) || (c0 == h1))) {


All things considered, you would more likely be better off using an array of used card flags so your tests don't get too ugly.

Code:
for ( c0 = 1; c0 < 53; c0++) {
  if (!used[c0]) {
    used[c0] = 1;
    for (c1 ....... ) {
    ....
    }
    used[c0] = 0;
  }
}


Also, if the table is initialized properly h0 does not have to be less than h1.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Dec 23, 2008 7:42 pm 
Offline
New member
User avatar

Posts: 3
Favourite Bot: oldie (mine)
mykey, thanks for the reply!

1) it was a bad snippet--i clipped somthing that was not the actual code i ran. the one i ran did not have 13, 17 (i did that to test 5-6 s, i think.)

2) i'm not sure if this is true. they are nested and enumerated cards are passed up if they match board cards. also to convice you that it might be right, 50c7 is 99884400, and my total count is the same. 50 because i removed 2 cards for hero's pockets. 7 more are dealt out and the last two are given to enemy.

3) yeah, i will fix that later. right now, i can always avoid 51 and 52. i just wanted to check enumeration first.

4) thanks or the suggest, i will look it through. i had the code cleaner before but got the same error, and in trying to debug and decided to assign everything explicitly.

5) h0 has to be less. it's because of the hacky way i implemented the cx++... if h0=5 and h1=4, it will test h1 second and and increment cx++, but now cx == h0 and h0 is a used card.



mykey1961 wrote:
kidzero wrote:
hi guys, i'm not so great at c++ but need the evaluator, anyway, i'd appreciate some help.

i'm trying to enum "AA" against every hand for heads-up and i get 90%-10%, although i think it should be 85%-15%. can someone confirm AA has 85% equity?



There are a few problems I see in your code.

1) Is there some reason h0, and h1 are defined twice? It looks like the 13, 17 are representing something other than AA


2) c5, and c6 are representing your opponents pocket cards, but in your implementation, they must be greater than the highest board card. That restriction does not represent reality.

3)
x in [0,1,2,3,4,5,6]
y in [0,1]

The test "if (cx == hy){ cx++;}" is bad.
if hy = 52, cx would be increased to 53, but the loop would still continue with this invalid value

Should use something like

Code:
for ( c0 = 1; c0 < 53; c0++} {
if (!((c0 == h0) || (c0 == h1))) {


All things considered, you would more likely be better off using an array of used card flags so your tests don't get too ugly.

Code:
for ( c0 = 1; c0 < 53; c0++) {
if (!used[c0]) {
used[c0] = 1;
for (c1 ....... ) {
....
}
used[c0] = 0;
}
}


Also, if the table is initialized properly h0 does not have to be less than h1.


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Tue Dec 23, 2008 8:16 pm 
Offline
Junior member
User avatar

Posts: 29
Favourite Bot: none
kidzero wrote:
mykey, thanks for the reply!

2) i'm not sure if this is true. they are nested and enumerated cards are passed up if they match board cards. also to convice you that it might be right, 50c7 is 99884400, and my total count is the same. 50 because i removed 2 cards for hero's pockets. 7 more are dealt out and the last two are given to enemy.





While 50c7 is 99,884,400, thats the right answer to the wrong question.

You want 50c5 * 45c2 (2,118,760*990) = 2,097,572,400

Is there any time your code is currently comparing the hero's AA vs an opponent's 22?


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Wed Dec 24, 2008 7:13 am 
Offline
New member
User avatar

Posts: 3
Favourite Bot: oldie (mine)
Mykey,

you're right, it does not. i fixed it, thank you for your help!


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 25, 2008 2:42 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
By the way, I can confirm that Steve Brecher's evaluator is buggy for 6 card hands.
For both 5 and 7 card hands it works fine (verified).

I have e-mailed Steve about that. If he suggest a hint, or a fix, then we can just integrate it, otherwise I might look into that (and anyone is free, of course).

So far, it seems it does not recognize both flushes and straights correctly for 6 card hands.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Thu Dec 25, 2008 7:12 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
OK - Steve replied and pointed to a fix. I will integrate it as soon as possible. I also Steve's archive here.

Steve Brecher by e-mail wrote:
Yes, I introduced a bug during the C -> Java port. I corrected this last spring, but it seems that the corrected version wasn't properly uploaded to my site. Now the corrected version is available at
http://www.stevebrecher.com/cgi-bin/dow ... n.java.zip

(note: brecware.com and stevebrecher.com are the same site)


Attachment:
HoldEmShowdown_SteveBrecher.java.zip [39.57 KB]
Downloaded 132 times

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Fri Jan 02, 2009 2:34 pm 
Offline
Junior member
User avatar

Posts: 21
Favourite Bot: mine
Is the new code verified for 6 card evaluations?

Also, running from Java, would it be faster to use something like Steve's code or JNI?

Buddha


Top
 Profile  
 
 Post subject: Re: 7-card Hand Evaluators
PostPosted: Fri Jan 02, 2009 3:10 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
For our older approximations, Steve's code is as fast as the C implementaton of pokereval. So basically, only the Java (anc C) implementation of RayW (the 2+2) evaluator can beat it.

If the question is if calling via JNI the C version of Steve's code is faster - I don't think so (or I expect to be ignorable difference), that's what most of the experiments and discussions we had concluded.

P.S. At least I haven't yet verified the 6cards Steve's version (i.e. the one containing his fix).

_________________
indiana


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 399 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 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: