Modelling homomorphism with inheritance

473 views Asked by At

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?

0

There are 0 answers