Results 1 to 12 of 12

Thread: Poker Hands

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Poker Hands

    I'm interested to know if anyone knows of any algorithims for determining a hand in Poker (texas)

    I have a few methods, but I was wondering if there are any standard methods which may be quicker etc!

  2. #2
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Poker Hands

    http://www.vbforums.com/showthread.p...ighlight=poker

    Sorry this is not a direct answer, but near the end of that thread I think there are some links. I hope that helps...
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Poker Hands

    Thanks, i've allready seen that one. I just need to find a method to determine the actuall hand.

    Pino

  4. #4
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Poker Hands

    that what a player gets? Why not just have all the cards either put in a matrix randomly and pic the cards from the top to give to the players? Or you could pick from the matrix randomly but then you have to have another matrix that remembers which ones you picked. So I would assign a 52 card matrix randomly, just make sure there are no double entries...
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Poker Hands

    http://vbforums.com/showthread.php?p...54#post2127354

    The deck of cards is sorted.

    I need an algorithim which works out which is the best hand that a player has based on the 7 cards avalible.

  6. #6
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Re: Poker Hands

    I dont know if this is the best solution, but here is what I would do:
    Code:
    take 3 of the community cards and make the regular poker hand
    
    //check for royal flush (check suit first), since its the best hand
    if the suits are the same for all cards, 
    {
         //it could be either straight flush or flush
         if there is at least a pair of cards that are more than 5 away //ex - (5,J)
              then its a flush
         else //they are in order
              then its a straight flush
              //see if the highest card is an A, then royal flush
    }
    
    else    //there is at least 2 cards of different suit
    {
         count the number of times the cards appear in the hand and store in an array
         
         //check for straight
         loop
             find the first non-zero element, say at X
         end loop
         for(i=X; i<X+5;i++){
              if array[i]==1
                   temp++
              else
                   break
         }
         if temp is 5
              then its a straight
    
         //chech other possibities     
         if there is a value of 4
              then 4-of-a-kind
         else if there is a value of 3 and 2
              then full house
         else if there is a value of 3
              then 3-of-a-kind
         else if there is a value of 2
              then a pair
         else
              start at the end of the array and find the first non-zero element, thats the 
              high card
    }
    Thats the only way I can see this being done relatively easy, unless you want to do it as the cards are turned on the flop and such (which is a lot harder). Also, once you find a valid hand, just return out of the function and call it with another combination of cards and keep track of the hand found, should be 6 of them, and pick the best one.
    Last edited by fartman_900; Jun 6th, 2006 at 11:07 PM.

  7. #7
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Poker Hands

    i am going to revive this thread because i am going to be working on this in the next comming weeks. funny i tried to answer this back in 06, seems i didnt know what i was really talking about, but i got some ideas now.

    Pino you still around? still interested in this?
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Poker Hands

    2006!! - And welcome back good to see you here. I have done any work like this ina while but sure im allways interested.

    What do yuo have in mind?

  9. #9
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Poker Hands

    well i started on the calculator, and everything takes too long.
    My reason for making this is because every poker game i play is too simple for my friend and I, so i want to code one that will beat us more than we can beat it, if possible.

    every card is given a value between 1 and 52 and stored, then all cards delt are converted to num between 1 and 13, then they are put in order, so when you look for a straight or pair or 3 of a kind etc. the num are in order and its simple to ask whats going on

    like if card 2 is one plus card 1 then if card 3 is one plus card 2 etc... looking for straight if it reaches 5 or if it reaches 4 you are on a draw etc...
    if card 1 = card 2 pair if = card 3 3 of kind and so forth.

    also the cards are broke down into 1 2 3 or 4 for suits, so you can read if they have flushes...
    orginal values are kept in array along with the simplified values and the suit values...

    make any sense at all?

    in no way is all this simple because poker is a complex game, and straight draws, gut shot straight draws, flush draws, you need to know all the potential for the computers hand just like we know. Cause sometimes chasing a runner runner draw works out... so all that needs to be coded, but i think this approach is very effective.
    Last edited by damasterjo; Feb 21st, 2010 at 02:56 PM.
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Poker Hands

    Other options you might want to consider to make it more difficult to beat your AI (computer player)....

    1. The ratio/percentage of a type of hand is well defined I believe. One can google and find an odds table. Knowing the odds, your AI player can use those odds to better choose which hand to go with when a choice is needed. In other words. If you have 8 9 9 10 J, is it better to go for a straight, flush (depending on suits), or 3 of a kind?

    2. Though maybe illegal in casinos, your AI player can count cards, especially, when some games show which cards have been played and/or a new deck isn't used for each hand. By counting the cards (remembering which were played), the AI player can again make better choices of which hand to pursue. However, the AI should not count cards that have not been seen, i.e., I wouldn't suggest cheating and have the AI count cards that were tossed in face-side down.

    3. The same principles above can be applied to the other non-AI players too. The AI player can use that information to decide whether to fold or not, thereby staying in the game longer by not wasting chips.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: Poker Hands

    right yeah i will code all of that, i am programing in stages, just figuring an effective way for the computer to know "what" he has. and as far as counting cards, in poker that dosent apply, because every hand is shuffled, know what i mean, and yeah the computer could look all the way to the river after his hand is delt and compare it with yours and know if he will win or not but thats cheap and cheating, so i will be getting into the odds thing, and probably will find a calculator or the formulas, i dont think i could think up the odds all on my own, that seems alot more difficult, but i do want to try the other parts on my own.

    thanks for your input and i would appreciate more, the more support i have for this the faster it will get done
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Poker Hands

    Well to know what one has, a method could be to use classes. You might have a separate class for each type of hand: two-pair, 3 of a kind, flush, etc. The class can have several methods/properties to help determine the decision process, like...
    :: Hand type Ok (i.e., 2 pair class says that 8 9 10 10 8 meets the class requirement) because 2-pair exists
    :: Odds to make Ok (i.e., odds needed to make 2 pair)
    :: Other decision factors as your AI gets smarter
    You also might have a Hand class for each player including the AI. That Hand class would just have exposed index values into your array for each card in the Hand. Each of the below hand-type classes would reference the Hand class so that they can get the card indexes and perform their custom calcs, sorting, etc.

    How to store the cards is a matter of choice really, one can use a Structure where number and suit are members, a class, a collection or a simple array, and other methods.

    If using a single array, something like this may be usable:
    Values are 1 to 13. For Hearts, OR 0. For Spades, OR 16. For Diamonds, OR 32. For Clubs, Or 64. This would keep the array "byte" size. To determine an array item's suit, use AND: If (Card(x) And 32) Then ' Diamonds. Sorting could be done by using only the first 15 bits which would return the value of the card less the suit: (Card(x) And &HF).

    The 1 to 52 array will work too, using Integer division to determine the suit. Card(x)\14 would return 0,1,2,3 depending on the card value btwn 1 and 52. Personal preferences.

    If using the class approach mentioned above, some classes may sort on number while others sort on suit or don't require sorting at all. For example, the Flush class is interested in Suits not Numbers, whereas the 2/3/4 of a kind (individual classes), 2-pair, Straight, & HighCard classes are interested in numbers and not suits. The StraightFlush class may actually contain no custom calcs, but has references to both the Flush & Straight classes. If both of those classes return Ok, then the StarightFlush class returns Ok. Likewise, the FullHouse class could reference the 2/3/4 of a kind classes and return Ok if 2/3 of a kind return Ok and 4 of a kind returns not Ok. Expanding this further. The 4 of a kind class may simply just reference the 2-pair class. If the 2-pair class returns Ok & all 4 numbers of the 2-pair are the same then the 4 of a kind class returns Ok.

    The advantage with classes is flexibility. Whether playing a 5 or 7 card poker game, you can determine which classes to include in the game and which to not include. The classes, each using unique calcs, determine how to process the cards. I do think that if used, each class should comprise of basically the same methods/properties which would allow you to easily build other classes that can reference/use existing classes (i.e., the FullHouse & StraightFlush classes which would be combinations of existing classes).
    Last edited by LaVolpe; Feb 21st, 2010 at 05:30 PM. Reason: expanded some thoughts
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width