-
Notifications
You must be signed in to change notification settings - Fork 13
PokerHand.as
Analyzes a sequence of 2 private cards and 3 community cards for the highest poker hand combination. Usually instantiated by the PokerHandAnalyzer class.
The PokerHand class analyzes permutations of supplied cards and creates a numerically ranked list of the best hands found. This is accomplished by computing values based on two pieces of supplied XML configuration data: the <cards>
node and the <hands>
node.
[to complete]
After sorting and grouping card the numeric rank of a hand is calculated as follows:
(matched hand points * _handPointsMultiplier) + (matched card facevalue * _matchMultiplier) + card facevalue ...
The first and largest portion calculates the points of the hand found by multiplying the "points" attribute value of the associated node. For example, if the player has a full house the "matched hand points" value would be 7 based on the associated data:
<hand name="Full House" rank="23" points="7" aces="high" groupby="facevalue" match="facetext:*,*,*;facetext:*,*" />
This points value is multiplied by the _handPointsMultiplier value, a class constant currently set to 1000000. In the above example the first portion of the calculation will produce a value of 7000000.
The second part of the calculation is repeated for every card that matches the hand pattern. In the case of a full house this would include all 5 cards but other combinations may have fewer cards. For example, a pair would only calculate this value for 2 cards. Each matched card is multiplied by the _matchMultiplier class constant, currently set to 1000.
In the example of a full house using three aces and two queens would we use the facevalue value from the associated data nodes:
<card name="Ace of Spades" facevalue="1;14" facetext="ace" color="black" suit="spades" class="AceOfSpades" />
<card name="Ace of Hearts" facevalue="1;14" facetext="ace" color="red" suit="hearts" class="AceOfHearts" />
<card name="Ace of Diamonds" facevalue="1;14" facetext="ace" color="red" suit="diamonds" class="AceOfDiamonds" />
<card name="Queen of Diamonds" facevalue="12" facetext="queen" color="red" suit="diamonds" class="QueenOfDiamonds" />
<card name="Queen of Clubs" facevalue="12" facetext="queen" color="black" suit="clubs" class="QueenOfClubs" />
Because the hand definition defines aces as having a high value (aces="high") we use the second facevalue number defined for aces in our calculation. The above example would therefore be calculated as:
(14 * 1000) + (14 *1000) + (14 * 1000) + (12 * 1000) + (12 * 1000) = 66000
The final part of the calculation simply adds the facevalue values of any non-matched cards supplied to the PokerHand instance. In the above example there are no un-matched cards since all 5 cards make up the full house. In the case of a pair, however, the 3 non-matched cards would simply be added to the overall total without including any multipliers. Any non-matching aces are considered low.
The final numeric hand rank is the sum of all three calculations above. In the full house example the final hand rank would be:
7000000 + 66000 = 7066000
Source code and inline documentation: https://github.com/monicanagent/cypherpoker/blob/master/GameEngines/PokerCardGame/src/PokerHand.as