Poker-AI.org

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

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Sep 25, 2014 11:50 pm 
Offline
New Member

Joined: Fri Jul 11, 2014 4:29 pm
Posts: 8
I've built a poker simulator, and every time I run few million hands, straights are consistently under detected by around 9/10th's of a full percentage point. That doesn't sound like much, but every other hand hits to an accuracy of about 1/1000th's of a percent from where it would be expected. So I can only assume there is a bug in my straight detection.

I've verified that the wheel is detected, so I don't think it's that. But who knows. The code is in C#, and I would really appreciate it if someone could look through it and let me know if they see anything wrong, or if there are better ways to do it. Thanks!

The general idea is that I sort the cards in ascending order by value, then I count sequential orders up to 5. Values are from 0 - 12, 12 being an ace. Here's the code:

Code:
        static bool isStraight(List<Card> cards, out List<Card> bestHand)
        {
            bestHand = null;
            int straightCount = 1,
                lastIndex = -1;
            bool isWheel = false;
            var sorted = (from x in cards orderby x.Value ascending select x).ToList();
            for (int i = 0; i < sorted.Count; i++)
            {
                Card card = sorted[i];
                if (i > 0) // Skip first card because we're starting straight count at 1 already
                {
                    if (card.Value == sorted[i - 1].Value + 1) // Check the previous card to see if we add 1 to it, it matches the current value
                    {
                        if (++straightCount >= 5)
                        {
                            lastIndex = i;
                        }
                    }
                    else
                    {
                        straightCount = 1;
                    }
                }
                if (straightCount == 5)
                {
                    break;
                }
            }
            // Check for wheel
            if (straightCount < 5)
            {
                if (sorted.Last().Value == 12)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        Card card = sorted[i];
                        if (i == 0)
                        {
                            if (card.Value == 0)
                            {
                                if (++straightCount >= 5)
                                {
                                    lastIndex = i;
                                }
                            }
                        }
                        else if (card.Value == sorted[i - 1].Value + 1)
                        {
                            if (++straightCount >= 5)
                            {
                                lastIndex = i;
                            }
                        }
                        else
                        {
                            straightCount = 1;
                        }
                    }
                    if (straightCount >= 5) { isWheel = true; }
                }
            }
            bool result = straightCount >= 5;
            if (result)
            {
                bestHand = new List<Card>();
                if (isWheel)
                {
                    bestHand.Add(cards.Where(x => x.Value == 12).First()); // add the ace
                    bestHand.AddRange(sorted.GetRange(lastIndex - 3, 4));
                }
                else
                {
                    bestHand.AddRange(sorted.GetRange(lastIndex - 4, 5));
                }
            }
            return result;
        }


Top
 Profile  
 
PostPosted: Fri Sep 26, 2014 12:12 am 
Offline
Senior Member

Joined: Mon Mar 11, 2013 10:24 pm
Posts: 216
Just get a hand evaluator, generate all random hands and boards, call your function with the generated hand/board and the evaluator and check if both say that you have a straight. If there is a difference, you have a specific hand/board and can just debug step by step through your code to see what's going on.


Top
 Profile  
 
PostPosted: Fri Sep 26, 2014 1:47 am 
Offline
New Member

Joined: Fri Jul 11, 2014 4:29 pm
Posts: 8
That's a good idea. Can you recommend one that I can can use with automation?


Top
 Profile  
 
PostPosted: Fri Sep 26, 2014 6:14 am 
Online
Site Admin
User avatar

Joined: Sun Feb 24, 2013 9:39 pm
Posts: 642
Maybe you can use http://poker-ai.org/archive/www.pokerai ... ?f=3&t=353 or http://www.codeproject.com/Articles/122 ... d-Analysis


Top
 Profile  
 
PostPosted: Sat Sep 27, 2014 9:50 pm 
Offline
Junior Member

Joined: Thu May 23, 2013 11:35 pm
Posts: 23
see if it works for this case: {2,2,3,4,4,5,6}
a way to solve it is remove duplicates before processing


Top
 Profile  
 
PostPosted: Mon Sep 29, 2014 4:57 pm 
Offline
Veteran Member

Joined: Mon Mar 04, 2013 9:40 pm
Posts: 269
Another way to do this quickly is use Timmys evaluator that is available in the archives somewhere. It has a hand state function in which you can just pass the board and your hand and it will tell you if you have a str8 or not. I have used this on all my bots and it works pretty well.


Top
 Profile  
 
PostPosted: Mon Sep 29, 2014 5:02 pm 
Offline
New Member

Joined: Fri Jul 11, 2014 4:29 pm
Posts: 8
algonoob wrote:
see if it works for this case: {2,2,3,4,4,5,6}
a way to solve it is remove duplicates before processing



Wow, thank you! That appears to be the problem! It's detecting that pattern as a two pair. Thank you for the suggestion, and great catch!! :D


Top
 Profile  
 
PostPosted: Mon Sep 29, 2014 5:03 pm 
Offline
New Member

Joined: Fri Jul 11, 2014 4:29 pm
Posts: 8
shalako wrote:
Another way to do this quickly is use Timmys evaluator that is available in the archives somewhere. It has a hand state function in which you can just pass the board and your hand and it will tell you if you have a str8 or not. I have used this on all my bots and it works pretty well.



I like writing everything myself, but I think it would be good to incorporate something like this as a way to test the accuracy of it. I'm definitely going to check it out, thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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:
Powered by phpBB® Forum Software © phpBB Group