0

I want to model pokerhands. The mathematical background and getting it into c++ is pretty insane.

A standard 52 card deck lets you make 1326 combinations of two cards. However one could bin those cards into 169 categories, which contain isomorph hands: Pairs (e.g. TT), suited (AsKs), and offsuiteds (AcKd). This is a subset of the common agnostic poker language to describe a set of pokerhands (TT+, 22-55, A9s+ etc.)

Well that said, my problem is to model the homomorphism between the 169 hands and the 1326 hands via inheritance. Imho a Hand1326 id derived from Hand169. Hence classes look like

struct Hand169 {
  int rank1, rank2;
//private:
//bool suited;
};

struct Hand1326 : Hand169 {
  int suit1, suit2;
};

But now the problem is, that the Hand169 should have information about suitedness (bool suit), which would be redundant in Hand1326, because suit1 and suit2 implicitely offers this information. The information about pair or not is implicitely given trough rank1 and rank2.

Is there a better way to model this, without the redundance?

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
  • Why model two cards as a hand instead of two cards as two cards held in a hand? Then you can move all the details to the cards and write higher order functions that use them in the hand abstraction. – HonkyTonk Dec 31 '13 at 16:01
  • I don't think creating that many classes is really a good approach – Sebastian Negraszus Dec 31 '13 at 16:01
  • Possible duplicate of [How can I iterate throught every possible combination of n playing cards](http://stackoverflow.com/questions/5076695/how-can-i-iterate-throught-every-possible-combination-of-n-playing-cards) – Paul Sweatte Jul 06 '16 at 16:20
  • Why do you have a class for every hand instead of, say, a class to represent a Card, then an array to represent a hand? – Nic Jul 06 '16 at 16:32
  • You must have got me wrong. There are simply those two classes. One represents the card by their ranks and suitedness and the other by the real two cards (rank and color). – ManuelSchneid3r Jul 06 '16 at 21:42

0 Answers0