![]() |
card game help
Hi, I have this problem and I am trying to find another solution.
I have a set of 5 cards that constitutes one hand. I need to find the point value for each hand according to the following characteristics: - straight flush (5 cards in sequence*, all of the same suit)-----> 10pts - full house (three of one kind & 2 of another)------------------> 7pts *sequence is 2,3,4,5,6,7,8,9,10,jack,queen,king with ace considered as either before 2 or after king as needed. How can I create a function findvalue(char[5][20])that determines the value of one hand? I could go with a "thousand of if statements" but I want to be more efefctive. please can suggest me an algorithm of what to do? Exmple: nine of hearts queen of hearts ten of hearts jack of hearts king of hearts The value of this hand is 10 or ten of diamonds jack of clubs ten of clubs jack of spades ten of spades The value of this hand is 7 what I have already done is to create a function convrt that gives the numerical value of the card : like 'two"=1, "three"=2, "four"=3........."ace"=13 according to the sequence. Thank you B |
You aren't going to get away with a miracle. You're going to need if/else-if statements or switches. You should rethink your approach and devise, first, your method for characterizing hands (pair, four of a kind, flush). When you can flag a hand as a particular type, you can then assign any value you like. If you line up the hands and consider them logically, you'll find that the tests have some tendency to nest and either lead to or exclude others. If you have two cards of the same value, you don't have a flush. If you don't have a pair, you sure don't have three or four of a kind. If you don't have trips, you don't have a full house. Stuff like that. It helps to sort the cards and work from one 'end', even if you later reposition and display them in a random order. If the second card in a hand isn't like the first, then you don't have a pair of the first. Also, it makes straights easier to detect. Just remember that the ace can go on either end, for a straight. If you're planning to make something like a "Draw Poker" game, you won't want the percentages to be 'real'. You'll need something that is more akin to a slot machine and build your own odds (which doesn't destroy the notion of randomness, incidentally), since getting a royal flush one hand out of 44,000 tries isn't good enough to keep the suckers coming back.
|
this is similar to assignment i just had where you have to take a dollar amount between 0.00 and 1,000,000.00 and convert it to words like on a check. lots of fun.
notice dawei didn't give you a lick of code. that's because the important thing here is to step back, figure out what you need to do, and THEN figure out how you're going to do it, i promise it'll be much easier that way. you usually posess the tools for the implementation of problems you've been given in school or whatever, the important thing is the software design process, albeit simple though it may be. (i thought about mine for about 30 minutes, wrote down some notes, and then fired up visual studio 2005 pro and got drunk...fun times). |
The code belongs to the guy I did the job for ;) .
|
| All times are GMT -5. The time now is 5:09 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC