0

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?

Skogen
  • 721
  • 1
  • 11
  • 30
  • 2
    If you number your cards 0..51, you need only 52 bits to represent any subset of cards. Hence, a `long` with its 64 bits is sufficient. A set of all pairs would then be a hash set of `long`s, with two bits set (one for each card number from the pair). – Sergey Kalinichenko Sep 10 '12 at 15:19

2 Answers2

2

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.

John B
  • 32,493
  • 6
  • 77
  • 98
0

I would number the cards or place them in a List.

If you use a list you can do

Set<Card> inHand = ...
for(int i=0;i<list.size();i++) {
  Card card1 = list.get(i);
  if (inHand.contains(card1)) continue;

  for(int j=i+1;j<list.size();j++) {
      Card card2 = list.get(j);
      if (inHand.contains(card2)) continue;

      // process card1 and card2
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130