Domanda

I have an assignment in which I need to identify a hand of Texas Hold Em

Here is the assignment: http://www.scribd.com/doc/142850594/proj1

And here is my code: http://pastebin.com/Ts387iDw

What I don't quite understand is how to get the program to read from the file ,with the hands in it, or how I should get it to sort through and identify the hand.

If someone told me to design a program like this from scratch with no guidelines, what I would have done is assign all 52 cards a uniquie ID, then define a type of hand like a royal flush, and use an if statement to see if the IDs match up to the defined type of hand. However, I just have a gut feeling that this is considerably less efficient than the manner my professor demonstrated in the assignment (he is the professor after all). Any help is appreciated, thanks!

È stato utile?

Soluzione

So, you have two problems:
1. Reading the hands from the file
2. Identifying the ranks of hands

For the first problem you need:
1. Read the file line-by-line
2. Parse the strings. You can notice, the cards have the same pattern within a hand: it is a letter plus 1 or 2 digits followed by other cards. In this case you can split the string manually based on the switch between digits and letters.

For the second problem there is no common ways. In most cases you need to check each possible rank manually.

Altri suggerimenti

Reading the hands from the file shouldn't be difficult, but there's way more to identifying hands than even your assignment implies, and your professor's own example function is wrong. Poker hands don't care about the order of cards, so his function to recognize a royal flush (with an R :-) will fail 119 out of 120 times. You could partly fix this by sorting the hands first, but then you need special case code for wheels (A2345 straight). Also, identifying the "type" of hand is only the first step in determining which of two hands wins. Finally, all this applies only to standard 5-card poker hands, and doesn't apply to Texas Hold'em, where you'll need to do best 5 of 7 cards. Google "poker hand evaluator" and you'll find more information than you could possibly imagine. A good place to start for C++ is Pokerstove on Github (or my own onejoker).

I suspect your professor doesn't really understand what's involved, and would be quite happy to see half-assed solutions like his own just to see that you could produce code that does something resembling the actual job.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top