Ranking poker hands

Write a program to analyze a number of poker hands and determine which is best. Each hand consists of five cards, and each card has a suit and a value. Your program should read data for any number of hands of five cards each, evaluate the hands, print out each hand and its rank, and which hand is best. It should also include the Sort function given below in the Hints section. This function is given in an incorrect form. Part of your assignment is to test the function (you can do this in the context of your poker program), find the bugs in it and correct them.

The ranks

Hands in poker are ranked by overall value according to the following table (spades are S, hearts H, diamonds D, and clubs are C; the third column gives an example):
straight flush five cards in value order and of the same suit 2D 3D 4D 5D 6D
four of a kind four cards of the same value 7S 7H 7D 7C 13D
full house three cards of one value and two cards of another value 11S 11D 11C 6S 6H
flush five cards of the same suit 2H 4H 5H 7H 12H 13H
straight five cards in value order 2S 3C 4H 5D 6S
three of a kind three kinds of the same value 1S 1H 1C 2H 8C
two pairs two cards of one value and two of another 9S 9H 5S 5C 10D
one pair two cards of one value 8S 8H 4C 5H 13S
no value none of the above 2H 8C 9H 10C 12D

Notice that some categories include others. For eaxmple, a straight flush is both a straight and a flush; a full house is three of a kind, two pairs, and one pair.

Procedure

  1. Write a one or two sentence problem statement.
  2. Write a problem description, including any aspects of the problem that you consider important.
  3. Design a TDSR diagram that shows your analysis of the problem.
  4. Write and compile the program.
  5. Consider how to test this program, and write a brief description of your test suite. Pay special attention to testing the procedure Sort.
  6. Test you program on each of you chosen test files and print out the results. Use a text output file to do this so that the results of multiple runs can be saved.

Hints

  1. Declare:
  2. Think how to input a hand of five cards, as ten integers in five pairs. The suits need to be input as integers as well as the card value.
  3. Design a function for each rank test. For instance, a function to test for a flush might look like this:

    int Flush(handType Hand) {
    ...
    }
    and it could be called like this:

    if (Flush(hand))
    ...

    The reason this works is that the function will return either 0 or 1, depending on whether the hand passed to it is a flush or not.
  4. Use the following function to sort the hand ready for testing for a straight. NOTE that this function will not work as it is given. You will need to test it, debug it and correct the code. Use any of the techniques mentioned in the debugging handout. The declaration of handType is assumed to have a field called Value.
void Sort(handType Hand) {
   int T, I, J;

for (I = 0; I < 5; I++) for (J = I; J <= 4; J++) if (Hand[I].Value > Hand[J].Value) { T = H[I].Value; Hand[I].Value = Hand[J].Value; Hand[J].Value = T; } }

Deliverables

  1. Your design document (problem statement, description and TDSR diagram).
  2. A printout of your program source code.
  3. A description of your test suite, with printouts of your test files.
  4. Printouts of your program running on each of the test files.

Due Date

Hand in your documents to me (RTH) on May 14th. before 5:00 pm.