>I am building a poker applicaiton. 
>
>Has anyone dealt with determining the value of a hand? 
>
>I have the feeling I am making it even more complicated than necessary.

Everybody seems to be advocating a database-based approach.  I wouldn't try to 
assign a value to each hand at all, you need a function that compares hands 
similar to the way humans do.

1.  tokenize the hand so you know what you're dealing with

for 9-9-10-J-2 you have "a pair of 9s", "a single J", "a single 10", and a 
single "2" in that order

for K-K-K-10-10 you have "a full house, K's over 10's" (one token)

comparing those hands, the full house token beats the pair of 9's token.  If 
you had
9-9-J-J-2 vs 9-9-J-J-3, you'd compare the tokens in order - pair of J's vs pair 
of J's are equal, so check the next token..  pair of 9's vs pair of 9's are 
equal so check the next token..  Single 3 beats single 2.

I'd write a class with functions to compare two tokens and tell you which one 
is greater than the other, or if they're equal.  Then I'd write individual 
functions to compare like tokens (ie so the class can tell that a K high flush 
beats a 7-high flush).  You'll also obviously need a function to do the 
tokenization of the original hand.  Then you just compare tokens in descending 
order to determine which hand is better.

It actually sounds like a fun project.  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:259625
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to