• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Poker assignment... I need a few tips...

Quickfingerz

Diamond Member
I need tips on this program. I don't need the answer since I am TRYING to be a CS major.


Assignment:
You are to construct a poker hand evaluator. The program will read each hand from a file, determine the best poker hand that can be made
from it, and then rank it with others in the same deal. The first line of the file has two integers: 1) The number of hands in each deal; and 2)
The number of deals stored in the file. Your program will take the name of the file as its command line parameter. The card values are
represented by 2,3,4,5,6,7,8,9,T,J,Q,K,A, with Aces being highest in value. The card suits are represented by S, H, D, C. In poker, all suits have
equal rank.

Further specifications: You may not use any arrays in this program. Instead you should use the vector template from the STL. You must
overload the << and >> operators for your hand class. When presented, the cards must be sorted by value, and then by suit within the same
value, with S > H > D > C.

Suggestions: You will find that by writing card and hand comparison functions to use with the sort and stable_sort algorithms you can save
yourself a lot of work. I also used a multiset and multiset::count to help with analyzing how many cards of each value a hand had. Besides five
Cards, you may wish to have each hand contain some information from its evaluation. This information could then allow a simpler
comparison among the hands. Share ideas with other people in the class about how best to evaluate each hand. Do not write code until you have
a clear design! This is not a huge program (< 300 lines of code including comments), but it is complex. Once you start to write your code,
work in steps. Get your input and output routines working CORRECTLY before dealing with the evaluation routines.

Assignment details may be found here:
http://wwwcsif.cs.ucdavis.edu/~wilson/ecs40/hw/hw8.html
 
Well, the meat is to determine what type of the hand can be constructed from the deal, and choose the highest. Since your professor already listed the ranking, you can do the check in that
order, so if the hand that could fit the description of 4 of a kind, it'll be tag as 4 of a kind and don't need to go through more testing.
(time to analyze how to determine each type of hand...)

and you'll need to learn how to use vector template.. and I think you'll use a lot of the vectors 😀

 
I agree with esung... analyze ye olde hand in order from highest to lowest.

This would be a much more interesting problem if the hands were dealt, then the program had to determine the highest hand that a person could possibly get if the game were played with one draw or two draws. Might take a while to compute 🙂.
 
my tips...

1. define hand rankings

#define STRAIGHT_FLUSH 999
#define FOUR_KIND 998
.
.
.
#you get the point 🙂

2. create a simple struct ( a simple class that does bound check would be prefarable ) that holds a value and suit. If you go with a class than it would be nice to have a method which evaluates the total value of the card mapped to int values ( 2->2 ... 9->9 ... J->11 ... A->14 ). That way in case of a hand tie, you can check the values of individual faces to break it, plus having their value as an comparable integer will make it easier to sort. Additionally create a boolean member that flags the cards use in a hand ( 8S 8D 7H 6D 6C Two Pair ) both eights and sixes are used in a hand, 7 will be used to break ties in case someone has the other 8s 6s pair or another two pair of an equal value)

3. create a hand class, which would have a vector<card> protected member. Here you will dump in input from each line and stuff it in the vector, in a form of the card clas ( or struct ) of course. As soon as the cards a loaded, mark them with the hand rating value ( defined at the top ), which should be fairly simply as you were given their decoding rules. Here it would be nice to compute the face values for the cards that make up the hand, for example two pair [( 6D , 6H ) ( JD, Js )] would have a value of 6+6+11+11=34. That will be used as the first tie breaker, the other one will have to be the highest value of the remaining cards ( you know which ones are those since you marked the hand as they was being loaded ) simply traverse through them and compare the value to the other hands other cards to break the last possible tie. The whole point of comparing will be used in sorting of the hand ratings done just before or during printing to stdout.


allright, thats it for now, tell me something doesn't look right ( i haven't played poker in years so i'm a little rusty in the &quot;comparing the face values&quot; department )
 
shouldn't be it's not that complicate once you work out the algorithm. Yo do have your pseudocode right 😀 ? your professor suggestion is pretty important.

BTW, what defines a line of code in C 😀🙂😛 ?



<< Suggestions: You will find that by writing card and hand comparison functions to use with the sort and stable_sort algorithms you can save yourself a lot of work >>

 
Back
Top