PA1: Yahtzee Scores (Decisions and Logic)

Due Dates and Submission Details

See submission details below for all due dates and submission details. Note there are multiple submission parts.

Honor Code

This assignment should be completed individually to maximize learning. It is important that you adhere to the Course Policies. Also relevant is the JMU Honor Code.

Objectives

  • Write if statements to make decisions in a program.
  • Use relational and logical operators in expressions.
  • Design one or more functions to simplify the code.
  • Use function calls from a provided driver program.
  • Submit code to the submission system and interpret feedback.

Background

In this program, you will implement the scoring function for Yahtzee — not the entire game, just the part that calculates how many points the dice are worth after the 3 rolls(Playable version at Yahtzee online game that follows these rules - also a finished online calculator verison). Here is an excerpt from the Wikipedia article that explains the scoring rules for the game:

The Yahtzee scorecard contains thirteen boxes divided between two sections: the upper section, and the lower section.

Upper section

In the upper section, each box is scored by summing the total number of dice faces matching that box. For example, if a player were to roll three twos among the five dice, the score for the "TWOS" box would be recorded as 6.

Lower section

The lower section contains a number of poker-themed combinations with specific point values:

Category Description Score Example
Three-Of-A-Kind At least three dice showing the same face Sum of all dice
Four-Of-A-Kind At least four dice showing the same face Sum of all dice
Full House A three-of-a-kind and a pair of a difference face 25
Small Straight Four sequential dice
(1-2-3-4, 2-3-4-5, or 3-4-5-6)
30
Large Straight Five sequential dice
(1-2-3-4-5 or 2-3-4-5-6)
40
Yahtzee All five dice showing the same face 50
Chance Any combination
(often acts as discard box)
Sum of all dice

 

Requirements and Testing

Start with the following source files:

Your main task is to implement the yahtzee.calculate_score function. You should write additional functions to break the problem down into sub-problems. You will also write an add_values function, which returns the total sum of the face values in the dice list. For example, given the dice values [1, 4, 5, 6, 4], add_values(dice) will return 20 (sum of 1+4+5+6+4).

You may also want to write Unit tests for yahtzee.py. Think carefully about how many test cases you will need. Organize your tests into separate methods, rather than write one very long test_calculate_score. It is a good idea to make sure you cover every statement of your program. Here are several examples to get you started:

dice = [1, 2, 3, 4, 5]  # large straight

self.assertEqual(1, yahtzee.calculate_score(dice, yahtzee.ONES))
self.assertEqual(0, yahtzee.calculate_score(dice, yahtzee.THREE_OF_A_KIND))
self.assertEqual(40, yahtzee.calculate_score(dice, yahtzee.LARGE_STRAIGHT))

Unit testing is the recommended way to "run" this assignment. However, you may also refer to driver.py which illustrates how your calculate_score method might be used in an application. This driver class will also let you test your scoring interactively.

Note that this time you will not have a main in your program. main is in the driver. By writing Unit tests you will be able to test each of your methods individually without having a main in your program.

In this assignment, your code should be able to handle invalid categories, but you can assume if the category is  valid, the list of dice contains valid values.

Submission

This assignment has two parts that should be completed in order. By the first deadline you must complete the readiness quiz in Canvas. By the second deadline you must submit your completed code for yahtzee.py through https://gradescope.com .

Part A - See your section's Canvas assignment for due date

Read this entire document and complete the 10 point Readiness Quiz in Canvas.

Part B -See your section's Canvas assignment for due date

Upload your completed yahtzee.py file through https://gradescope.com

You must implement the above in python, creating a file called yahtzee.py. Before uploading your file, be sure to complete the following steps carefully:

    • Verify that your code is working. You should test it with several Unit tests.
    • Make sure all your variables are declared at the beginning of each method, before any other statements.
    • Check that you have inserted the proper Docstring `Author` and `Version` comments in the appropriate header.
    • Run flake8 style checks and eliminate ALL warnings about your code.

Your submission will be graded using the following criteria:

Requirement Points
PART A/B: Readiness Quiz in Canvas + Instructor grading based on style, code quality, comments. 20
PART B: Style  5
PART B: Function calls from Singles 10
PART B: Lower functions(full house, 3 and 4 of a kind; straights) 25
PART B: Lower scoring(chance, yahtzee) 10

 

Don't put off submission until the last possible minute! Any submission system may become bogged down when it receives a large number of submissions. You may have some unanticipated difficulties uploading your code. It is your responsibility to take these possibilities into account and submit early enough to ensure that the submission process is completed before the deadline.

Hints

Often the way something is explained in english may not be the best way to code a solution.

Going Further

Why did we use the colors above (input/output)?

Acknowledgments

This assignment was originally developed by Chris Mayfield and repurposed by Dee Weikle, converted to Python by Alvin Chao.

Back to Top