Search code examples
c++ooppoker

How to identy a Poker hand in c++


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!


Solution

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