TheFuzz
TheFuzz

Reputation: 2623

OOP style question

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.

Upvotes: 0

Views: 130

Answers (3)

John Parker
John Parker

Reputation: 54425

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. ;-)

Upvotes: 0

GManNickG
GManNickG

Reputation: 503805

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.

Upvotes: 2

ufukgun
ufukgun

Reputation: 7209

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..

Upvotes: 0

Related Questions