Search code examples
javadata-structurespoker

How can I generate all unique card pairs from a list of cards?


I am implementing a hand strength evaluator, which is to evaluate all possible pairs from the remaining 47 cards, after dealing one hand and the flop.

I have implemented the evaluator, but I'm missing all the possible combinations for which to compare. I am tempted to create a class for Hand, which consists of two cards, and store each combination in a set, HashSet. Which data structure should i choose? If HashSet is best, then how can i force each instantiation of Hand to be unique?


Solution

  • HashSet seems reasonable although since ordering might matter later you might want to consider a TreeSet. If you implements the equals and compareTo/Comparable methods in Hand the Set will force uniqueness.