Project 2
How does it rank?

Overview

In this project, you will continue with modeling the game of poker. In the previous project, you identified and counted the occurrences of different kinds of poker hands. In this project, you'll take it one step further and directly compare hands.

Objectives

Ranking the hands

The kinds of hands we are dealing with are the same ones we had in the previous project. Here they are again, listed in order from most valuable to least valuable (see cardplayer.com for the definitions):

  1. flush
  2. two pair
  3. pair
  4. high card (all other hands)

So, a flush is better than 2 pair, which is better than a pair, etc... However, in a real game of poker, two players might have the same kind of hand. In those cases, we need to decide who has the best hand (or decide that there's a tie). The ranks of the cards determine the relative worth of two hands of the same kind. So, for example:

The Mission

In this project, you will make a simple game that repeatedly:

  1. Draws two new hands from a deck,
  2. Shows the hands to the player, asking them which is worth more (or if they have the same value),
  3. If the player was correct, they get one point and can continue.
  4. If the player is incorrect, the game is over and the total score should be indicated.
  5. The game is also over if there are not enough cards left to play another round.

Project Requirements

A required function

To support the game described above, you need a function that can take two hands and compare them. Here's the function signature and the docstring explaining its behavior:

def compare_to(hand_a, hand_b):
    """
    Determines which of two poker hands is worth more, returns positive,
    negative, or zero depending on the comparison.

    :param hand_a: The first hand to compare
    :param hand_b: The second hand to compare
    :return: a negative number if hand_a is worth LESS than hand_b, zero if
    they are worth the SAME, and a
    positive number if hand_a is worth MORE than hand_b
    """

Your function should have exactly this signature.

Required refactoring

In addition to the satisfying the program requirements, you must also refactor your code from Project 1 for use in Project 2 (make a copy into Project 2 so you can always go back to the version you had in Project 1).

If your Project 1 did not effectively use information hiding to divide the program into separate python files, you should refactor so it does.

Any poor variable and function names should also be fixed.

In addition to these "fixing" refactorings, you should also refactor to change the internal representation for a single card:

Unit Testing

Your compare_to function must be thoroughly unit tested, using the approaches we've discussed in class and lab. Recall that a test case is:

Leave test functions in your code so that I can see them and run them.

Your test functions should print "PASS" or "FAIL" to indicate whether compare_to has computed the correct answer.

Some guidance

Turn it in

Turn in the project by compressing the project folder and emailing it to me. Be sure you have the honor code pledge written at the top of each python source file.

Please remember to name your project using your last name and without spaces (like CassProject2) when you create it in PyCharm.