evaluating strength of a poker hand

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #16
    Some thoughts on the above code...
    • If the cards() array holds numbers, it should be of numeric format (preferably Long as mentioned above). Using the Val() function all the time adds heaps of processing overhead.
    • With 7 cards, couldn't you have 3 pair? (As you can see, I'm not a poker player)
    • Don't a straight or a flush (or a straight flush) outrank four of a kind?
    • You might save a little time by using a faster sort method. It looks as though you've coded a bubble sort. This is about the most commonly-written technique, because it's so simple and intuitive. But it's also one of the slowest available. Depending on the circumstances, of course - sorting is a complex subject. You might want to have a look at the Wikipedia article on sorting algorithms
    • For reasons of readability, I'd recommending you stick with either single-line or multi-line IF...END IF syntax, don't mix them. For example, line see 46 and lines 63-66. I believe the latter is much easier to follow.
    • Since you've already checked for three or four of a kind, in the pair-checking you might save a bit of time by skipping ahead one card after you detect a pair.
    • Is the sequence of the checks correct? Since you're stopping as soon as your detect something, presumably you need to check in reverse order of strength so that you always detect the strongest hand present. As I said I'm not a poker player (or even much of a fan) but it doesn't look to me as though this is what happens here.
    • I think the full-house (and three of a kind) check could be improved quite simply. Do the initial checking for three of a kind using the original array. If found, then if necessary copy the cards to your second array and continue checking. Given that the majority of hands (I assume) won't contain three of a kind, this would usually skip a lot of the overhead.
    • If you're really looking to squeeze out every last processor cycle, there are further tweaks which may sound silly. For example, define a Const One as Long = 1 and use that everywhere in place of the literal value 1. Similarly for other commonly-used numbers. Believe it or not, it can be slightly faster to access a constant like this than a literal.
    • You can't quote 15,000 hands a second then talk about once in 72,000 hands as though it's a rare thing. That's an average of about once every 4-5 seconds. Basically, in programming you usually need to take into account what is possible, not just what is likely.
    • Even if you stick with the bubble sort, I think we can tweak it slightly for performance. There's no need to loop through the entire array each time 'round the While loop. Depending on which direction your values "bubble", you can start or stop a bit further along the array each time to reduce overhead.
    • I think there are still areas where we can rewrite these checks to reduce processing - possibly by combining some of the checks. A bit will depend on the sequence of strengths I mentioned above, though.
    • Some checks such as for pairs you might be able to incorporate into other places, such as the sort. Since you're already looping through the whole array (and the last time through the sort loop, they are in sequence) you might be able to skip one entire loop in the majority of cases, at the expense of some unnecessary checking in cases where there's a stronger hand. (In other words, if you hit a flush, you no longer care that you earlier found a pair. But this usually won't happen). The idea is that you cut down on the work which is almost always done, at the expense of some extra overhead in the rare cases.

    Comment

    • bnashenas1984
      Contributor
      • Sep 2007
      • 257

      #17
      thanks Killer42 for helping.. I really appreciate
      As I said I'm just a beginer in programming.. I'll read your post and do like you say... I hope my program gets faster

      I'll post the answer about what happens

      Thanks again
      B...

      Comment

      • bnashenas1984
        Contributor
        • Sep 2007
        • 257

        #18
        Hi Killer42
        I'v read your post .. It really helped. After some changes I could reach 22.800 h/s ( with 3.06 Intel processor ) which is 7.300 hands more than the previous program.
        The order I check the hands should be as it is.So I skip checking weaker possibilities as soon as I find one. For example if I find a (Two pair) then I don't need to check for (one pair). Like you said it increases the speed of evaluating.
        And in my system there is no need to check for (Royal flush) and (Straight flush ) because the probablity to get them is 1 in more than 100,000 hands
        Here is the order of strengths in poker with probablity of getting each one of them

        Royal flush (Best) (1 in 650,000 hands)
        Straight flush (1 in 72,000 hands)
        Four of a kind (1 in 4,200 hands)
        Full house (1 in 700 hands)
        Flush (1 in 510 hands)
        Straight (1 in 250 hands)
        Three of a kind (1 in 48 hands)
        Two pair (1 in 21 hands)
        One pair (1 in 2.4 hands)

        And if none of them happens then the person with highest card wins. But we can forget that one because people who use a poker calculator don't risk their money with having a high card

        (Quote: With 7 cards, couldn't you have 3 pair? ) The answer to this question is ,Yes you can get 3 pair but only 2 of them will be counted. The probablity of getting 3 pair might be less than (Three of a kind) So it must be stronger but not in poker rules

        After reading your post I realized that there must be many ways to increase the speed , even with changing whole checking parts.
        So I'll work more on your opinions. It seems that there are many facts in programming that I don't know about

        Thanks again for posting

        B...

        Comment

        • daniel aristidou
          Contributor
          • Aug 2007
          • 494

          #19
          Just a question ...what are you developing this game for...and more importantly who?.....by not checking for a royal flush......you might be viewed by the players as..kinda cheating at you own game....Please note this is not an accusation...ju st pointing out.. if i was betting using this game and got a royal flush i would gamble alot on it... so by not checking.....so meone could lose alot

          Comment

          • bnashenas1984
            Contributor
            • Sep 2007
            • 257

            #20
            Originally posted by daniel aristidou
            Just a question ...what are you developing this game for...and more importantly who?.....by not checking for a royal flush......you might be viewed by the players as..kinda cheating at you own game....Please note this is not an accusation...ju st pointing out.. if i was betting using this game and got a royal flush i would gamble alot on it... so by not checking.....so meone could lose alot
            Hi daniel and thank you for posting
            As I said in my previous posts I'm not making a poker game..
            You know that there is many poker calculators to download. Those programs are to help a player to see his/her chance to win. Some people call it "Cheating" but I don't think it is.. Because it just shows the probablity of winning and it's never at 100%.
            what these programs do is that they check thousands of different possibilities to find out if the person is more a loser or a winner.
            You have 2 cards in your hand and there is 5 cards that all of player can see so there is 45 cards left.
            This program checks (45 * 45) differert possibilities to find out strength of your hand comparing with other players
            If you use it after 4th card of flop then it will be (45 * 45 * 45)
            or after 3rd card of flop will be (45 * 45 * 45 * 45)

            Do you think it's cheating?

            Thanks / B...

            Comment

            • daniel aristidou
              Contributor
              • Aug 2007
              • 494

              #21
              well at maths yes.... in the game no....
              well actually kind of...i don't know
              I believe its up to the opponent to decide whether they accept an opponent using a possibility calculator...So rry for the confusion

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #22
                Originally posted by bnashenas1984
                ...find out if the person is more a loser or a winner.
                Oh, I get it. Like on, say, World Poker Tour where they show the percentage chance each player has of winning the pot.

                Cool !

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #23
                  One other question. When you achieved 22,800 hands per second, was this running in the IDE (Integrated Development Environment) or compiled? Because you'll find that you get the best performance out of your program once it's compiled, to native code, with all optimisations turned on under the "Compile" properties tab.

                  (Not sure how familiar you are with VB, so I'll point out that compiling it won't make any difference to what happens if you run it again from the editor. You'll have to go to Windows Explorer and run the Exe file that was created - that's the "real" compiled code.)

                  Comment

                  • bnashenas1984
                    Contributor
                    • Sep 2007
                    • 257

                    #24
                    Ok .. I found a way to make this programs 9 times faster..
                    I changed the whole system
                    In my new program there is no need to sort cards for checking. I just put them in an array like "dim cards(13)" without suits

                    By the way .. I don't know why but when I run the exe file it's 2 times faster than running from the visual basic compiler..

                    And I have another question :P .. Actually I posted this question and got no answer.
                    Any suggestion will be helpful

                    You may have seen some programs that read values from external windows...
                    For example when you open a poker calculator while you are playing poker the calculator reads your cards from the poker program.. (Those are two different programs)
                    Does anyone have any idea how it can be possible?

                    Thanks

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #25
                      Excellent! I knew there had to more efficient ways to do the job, but haven't had time to look into it in depth.

                      As for picking up info from the poker program, well... that's another story entirely. Communication between programs is a big subject area. There are tons of techniques which may be in use. The simplest would be if the poker program exposes its workings through an automation interface.

                      If the poker program in question isn't designed to share information with other programs, then you may have a very difficult task.

                      I'd suggest you try some searches on this sort of topic. Or even read your VB documentation. You might want to include search terms such as...
                      • API
                      • automation
                      • OLE
                      • ActiveX
                      • COM

                      Comment

                      Working...