Poker,detect different hands;help!!!

FajlajpFajlajp Member Posts: 666
Hi everybody:)
I'm designing a poker gam at the moment. I'e sucessufully managed to deal the cards,shuffle the cards. Raise,bet,call,fold etc. But I've got stucked at one stage. How to detect diiferent hands like par,two pairs,full house,flush,straight etc.
//Fajlajp
«1

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    You'll have to have a series of attributes that track each hand and make rules for all the possible combinations. This kind of stuff takes a lot of code in GS because we can't code good if and else statements. This would be real simple to write say in Java Script.
  • FajlajpFajlajp Member Posts: 666
    @Fryingbaconstudios.
    I got a tip of tatiang saying this.
    "Each time a card is dealt, update a table cell with the value of the card. You could use two table cells (suit + number) but there's probably a better way to do it, especially if you can take advantage of the new string evaluation behaviors (e.g. first letter of word) in the nightly builds. Then have an algorithm that loops through the "hand" (table cells) and figures out what the hand is. If you see the same number (e.g. 4 of diamonds and 4 of hearts), it's a pair. If all five "cards" have the same suit, it's a flush."
    But I don´t know how to check the numbers and suit. Is it possible and how?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yeah like I said you'd build the algorithm with rule conditions. That's some heavy lifting to do with GS. One could do it. It's just not going to be easy.
  • FajlajpFajlajp Member Posts: 666
    edited July 2013
    Any good algorithms for this? or is just to sit down with pen and paper figuring at all the possible combinations?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Similar to when I did my multi touch and had to build my own. I think with this project you're in uncharted territory, I don't think anyone has built anything like this before with GS.
  • FajlajpFajlajp Member Posts: 666
    That's just good. I get to first to be doing something ;)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yep, I love being out on the edge. I've got a couple firsts under my belt. My AI player in puck it and my extreme multi touch but I know DeepBlueApps has one too but we're the only two I know of. Happy exploring!
  • WingmanappsWingmanapps Member Posts: 458
    edited July 2013
    thinking out loud - not a proven concept.

    - There are 40 possible straight flushes, including the 4 royal flushes
    - There are 624 possible hands including four of a kind
    - There are 3,744 possible full houses
    - There are 5,148 possible flushes, of which 40 are also straight flushes
    - There are 54,912 possible three of a kind hands that are not also full houses or four of a kind
    - There are 123,552 possible two pair hands that are not also three of a kind hands or higher hands
    - There are 1,098,240 possible one pair hands

    So its a given you need to make a dynamic system that can calculate these out comes as you play.

    You need to have atleast 3 values to check from
    Card type (spades,hearts,diamonds,clover)
    Card Value (1,2,3,4,5,6,7,8,9,10,11,12,13)
    Combined hand value.

    Then you need to plot down the rules of each possible hand

    You need to combine those values and reference it to the cards dealt onto the table.
    And then have and Global attribute looking at the combined highest value.
    But making a poker game without understanding poker is even more challenging.

    But as @fryingBaconStudios said. Its more then a big task to make this happen with Gamesalad.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Wow @wingmanapps very nice off the top of your head! Yes this is even more daunting then I had imagined. This would bring GS to a halt trying to crunch all that.
  • FajlajpFajlajp Member Posts: 666
    @wingmanapps
    I think I've came up with a solution thanks to tatiang,socks and fryingbaconstudios. But thank you for helping me out.
    Ps. How did you get 1.098.240 possible one hand pairs. That's not possible.
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Ice Cap made a Poker and Blackjack game with GameSalad. So it can be done, definitely.
  • WingmanappsWingmanapps Member Posts: 458
    But if you want the math

    There are 13 choices for the rank of the pair, and 6 choices for a pair of the chosen rank. There are 220 choices for the ranks of the other 3 cards and 4 choices for each of these 3 cards. We have 13 x 6 x 220 x 4^3 = 1.098.240 hands with a pair.
  • FajlajpFajlajp Member Posts: 666
    @slickzero
    Do you have a link to his game?
  • FajlajpFajlajp Member Posts: 666
    Ohh. I didn´t mean to his game. I mean to his profile because I can´t find it. Does he have one? Could maybe get some help from him :)
  • BoomshackBarryBoomshackBarry Member Posts: 712
    Ice cap isn't a forum member, ice cap games is the name of Gamesalad's game and publishing division. Check the link:

    http://gamesalad.com/blog/gamesalad-debuts-games-and-publishing-arm-ice-cap-games
  • FajlajpFajlajp Member Posts: 666
    @boomshackberry
    Do you know any from this forum that has been involved making the poker app.
  • BoomshackBarryBoomshackBarry Member Posts: 712
    Sorry no, I'd guess that it might have been built by the guys at GS to demonstrate what GS can do, but that's just speculation.
  • FajlajpFajlajp Member Posts: 666
    Hmmm. Could look that up with @codewizard. Maybe he could ask his team.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    You could try but those guys have never shared info about how they make their games. I think they treat it more like competition than most people do on the forums. Although many of us do hold some things back as you are my competition after all.
  • RexCarsalotRexCarsalot Member Posts: 96
    edited July 2013
    @Fajlajp,

    @wingmanapps and @FryingBaconStudios are correct in that this would be a daunting, if not near impossible task to accomplish if one attempts to create rules for 1,098,240 possible one pair hands.

    While the above poker math is certainly true, it seems to me that folks may be, understandably, overthinking this somewhat.

    Having said that, I make this post knowing that I may either be doing this exact same thing, or, on the flip side, not thinking through the problem nearly enough.

    (So, side note: feel free to completely blast me if this post makes no sense whatsoever. It's just stream of consciousness, and even if it was the sum total of my very limited brain power, I can still take it.)

    While I am working on the art design for this particular project with Fajlajp, I am certainly a novice with GameSalad, so take this idea for whatever it's worth. However, it seems to me that the easiest way to work around this problem is to assign numerical values to each of the card rankings and not worry about trying to program rules for every single card combination - which is obviously in the million plus range.

    Before I explain, I should preface my idea by noting that a poker hand has the same hand ranking regardless of the order in which it is arranged by the deal, by a description, or by a picture. So a hand arranged as:

    10s 8d 10d 6c 10c -- is ranked the same as-- 10c 10d 10s 8d 6c,

    even though in the first hand the three of a kind is not immediately obvious.

    Additionally, in terms of starting hands, there are only 169 different combinations, if you assume for example, Qh Qd is the same as Qc Qs - treating all suites as equal in numerical rank.

    Having said that, I would think that it's possible to use something like the so-called "Bill Chen Formula," which he writes about in "The Mathematics of Poker."

    Developed by Bill Chen, a two-time WSOP bracelet winner (at the time of it's development), and founder of billchenpoker.com, he basically developed a mathematical formula to determine if a starting hand is playable by assigning the cards certain numerical values. I think that this idea can be easily converted to GameSalad's logic, to not only use for basic rules programming, but to also create some sort of rudimentary, if not totally easy to beat A.I (see bottom of post).

    Briefly described, the key to Chen's formula is determining one's highest card and scoring it as follows, using the lower card for gap and suited analysis.

    Ace = 10 points
    King = 8 points
    Queen = 7 points
    Jack = 6 points

    10 through 2 = half of face value (i.e. 10 = 5, 9 = 4.5)

    Pairs, multiply score by 2 (i.e. KK = 16), minimum score for a pair is 5 (so pairs of 2 through 4 get a 5 score)

    Suited cards, add two points to highest card score

    Connectors add 1 point (i.e. KQ)
    One gap, subtract 1 point (i.e. T8)
    Two gap, subtract 2 points (i.e. AJ)
    Three gap, subtract 4 points (i.e. J7)
    Four or more gap, subtract 5 points (i.e. A4)

    Sample scores
    AA = 20 points
    98suited = 7.5 points
    K9suited = 6 points

    Of course, I'm just throwing stuff against the wall here, but it seems to me that using either tables, or assigning an invisible actor with a numerical value to each card, as well as an additional modifier for each suit, such as HEARTS = A, DIAMONDS = B, CLUBS = C, SPADES = D, would make determining the winner of a hand much easier.

    *EDIT - The next logical step would be to apply this same principle to the community cards as well, to determine an overall mathematical score.

    As @wingmanapps said:

    "You need to have at least 3 values to check from:
    Card type (spades,hearts,diamonds,clover (sic))
    Card Value (1,2,3,4,5,6,7,8,9,10,11,12,13)
    Combined hand value"*


    With seven possible cards total in Texas Hold-em, the math should be fairly easy.

    Ah Ac vs Ks Kh = 10 + 10 (20) vs 8 + 8 (16) would be the clear winner mathematically pre-flop, however on this particular board ...

    9s 10s Ad / 2s / Qs ...

    The Cowboy hand (K K) takes the pot with 5 spades, or 5 cards with the suit modifier "D" (for spades as described above). *EDIT: On a board with no possible flush, the numerical math would determine the winner.

    This idea needs to be fleshed out more of course, because there situations where a bit more creative thinking may be needed. Such as, if the board is:

    7s 8s Ac 9s 7h,

    a player holding 5s 6s has the nut hand, a 9-high straight flush of spades, this player cannot lose, even though another player maybe holding an Ace high flush - the As Ks, which is numerically higher in the above formula. So, there needs to be an additional (I'm a calling it) "Modifier" for situations such as straight flushes.

    On the same board, the hand 7c 7d would be the second-nut hand, four of a kind sevens; the third-nut hand would be any pair of the remaining three aces, making a full house, aces full of sevens.

    That being said, in situations where two or more players hold non-straight (or Royal) flushes and higher than Wheel/Bicycle (A-5) straights, the highest numerical "kicker" card, whether it be an A, K, Q, etc. would take the pot. The same would go in situations where two or more players hold full houses, sets or two pairs. The cards with the highest value, i.e. 3 Aces vs 3 Kings, or Queens over 10s, vs Jacks over 10s, would be the winner.

    There may need to be a special rule set for situations where one player has an A-5 straight, so that it will always lose to players with straights 2-6 or higher.

    In terms of programming an A.I., the information below (though not strictly from the Chen formula) can be used as a general rule of thumb to determine when an A.I. might come in for a raise. This can be used a staring point for determining player styles using a combination of Loose/Tight, Passive/Aggressive. I personally use Wilson Turbo Software, which uses a system based on this, and I believe it to be the best Poker A.I. currently available. (Although, it does occur to me that I haven't researched similar new products in quite some time.) For general poker knowledge, these numbers are worth mentioning, as they are often seen in conjunction with the Chen formula in many places around the web.

    Early Position
    Raise = Score is 9 or higher
    Call = Score is 8 or higher
    Fold = Score is lower than 8

    Middle Position
    Raise = Score is 9 or higher
    Call = Score is 7 or higher
    Fold = Score is lower than 7

    Late Position
    Raise = Score is 9 or higher
    Call = Score is 6 or higher
    Fold = Score is lower than 6







  • RexCarsalotRexCarsalot Member Posts: 96
    @Fajlajp, on a personal note, will have some art for you by Wednesday at the latest. I'm sure you'll be pleased with what I'm sending you. We will try and arrange a Skype session after you've reviewed the materials.
  • FajlajpFajlajp Member Posts: 666
    Thanks @RexCarsalot
    This was very interesting. But I think I have come I solution.
    And great to hear about the art :)
  • RexCarsalotRexCarsalot Member Posts: 96
    Great. Looking forward to seeing what you've come up with.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    edited July 2013
    You could try but those guys have never shared info about how they make their games. I think they treat it more like competition than most people do on the forums. Although many of us do hold some things back as you are my competition after all.
    I can possibly arrange to make a template out of the logic for the poker game. Though I'm pretty booked with History Fighter and some other templates.
    Like this post if you would want this template.
  • FajlajpFajlajp Member Posts: 666
    @codemonkey
    That would be great!!! It would help me a lot.
    (check your inbox)
    Everybody: Like CodeMonkey´s post so we get a poker logic template.
  • RPRP Member Posts: 1,990
    That's what we used to call the homie hookup. Nice.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I built it. I just need to find some time to strip out some unrelated stuff like iAP and special code.
Sign In or Register to comment.