tags:

views:

98

answers:

3

Right now I'm writing a program that will determine the value of a hand of cards. five in total. i have a cardHand object. I'm planning to write an object that compares two objects together in order to determine which hand has a higher value. the two objects that will be compared are objects that contain the possible hand values (one pair, three of a kind... etc).

would stackoverflow see this as a fit method of OOP?

PS: i do know that the algorithm is floating around on the internet but im trying to do this by my self first for the XP.

A: 

Shouldn't each hand object have an innate value? You could then have another object (the dealer?) compare the values of each hand. The dealer could also be used to instantiate each hand object.

Then again, maybe I'm taking the whole 'modelling the problem domain' approach a bit too far. ;-)

middaparka
A: 

define the rules that decides which hand is higher.

rule1 > rule2 > rule3...

compare from the biggest one.

decide if hand fits with rule1 than it is hand1.

decide if hand fits with rule2 than it is hand2.

..

if they are in the same rule, make an algorithm like that inside every rule.

it is just an idea... you may think about it..

ufukgun
i think i thought it is poker??
ufukgun
+2  A: 

What you'll want to do is something like this:

  • Create a card class. Add an operator< to this class so you can determine the sorting of individual cards.
  • Create a card collection (hand) class that stores a collection of these cards. Define an operator< for this class as well, to determine the sorting of hands.

If you store your cards in an std::multiset in the hand, your cards will group themselves together automatically.

That is, if you insert 2, 7, 3, 4, 3 they will be in this order: 2, 3, 3, 4, 7. This will help you determine things like pairs and tuplets.

GMan
+1 way to go. Use operator overloading where sensible to allow for "standard handling" of your objects. Or in other words: make your objects as indistinguishable as possible from basic objects. That way lies the bliss of common handling and understanding.
Don Johe