简体   繁体   中英

Testing for two pairs in Poker Program

Can anyone point me in the direction of logic I should be thinking of when attempting to test if a poker hand of 5 cards has two pairs?

So far what I had before was pairing up each possible pairs of two of the five cards and returning true if two or more of these pairs have equal values. The problem I am having is that if there is three of a single card the method still returns true even if there are not two pairs.

There's 2 main groups of poker hand rankings.

  1. Straights/flushes
  2. Hands that have more than one card of a particular ranking (everything else)

In the everything else category one thing that you will notice is each time you have a stronger hand ranking it includes at least one type of weaker hand ranking when you take a combination of those cards.

For example AAAT9 is a 3 of a kind but it also includes a pair if you take two of the aces out.

The easiest way to find the strength of a hand is therefore to start from the strongest hand first then work downwards in the strengths categories, this matches the actual rules of the game very closely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM