Skip to content

Programming Assignment(PA) 1: Can't Stop X

Can't Stop five dice

Introduction

Can't Stop X is a dice game originally developed by Sid Sackson as the game Solitaire Dice. It is played with 5 six sided dice with face values 1-6.

Your goal for this assignment is to create a dice module and develop tests and functions for playing a text based game of Can't Stop Express.

How to Play

We are doing a solo version of the game. You will roll 5 dice then decide how to apply those dice as keepers for each turn. Keeps will be assigned in pairs with pair 1 and pair 2 then a 5th dice assigned to the last single die in each roll. For example if you roll a: [ 1, 6, 3, 5, 2] you might assign keepers as: 1.1.2.2.5 this would give you a total of 7 dice count for pair 1, 8 for pair 2, and 2 as your 5th die.

Keeper Assignment Format:

We will use an input format of #.#.#.#.# where you will use a 1 to indicate the die is a member of the first pair, a 2 to indicate a member of the 2nd pair and a 5 to indicate which fifth die you have chosen. These entries will be separated by a single period.

Fifth dice assignment:

In the first 3 turns you must select a unique 5th die for each round. After turn 3 you must select one of the existing 3 5th die in your list if possible. The fifth dice counts determine the ending of the game. If you reach the COUNT_MAX value for any of the 3 5th dice the game ends. In a regulation game this COUNT_MAX value is 8.

Scoring:

During the game and at the end you score points only after your count for a dice total[2-12] reaches the SCORE_COUNT constant value (In a regulation game this number is 5.). If you start a dice total row you will score -200 until you exceed the SCORE_ COUNT number. After reaching the SCORE_COUNT value in a column, scoring is done by multiplying the scoring factor for the dice total by the count of the dice total. For example: if the 7 dice total # row has a count of 8 then you would score 90 points for the 3 above 5 score count multiplied by the scoring factor of 30 for the dice total of 7. See the Scoreboard section below for details on the pairings of scoring factors to dice totals.

Each dice total has a max of 10 counts.

The Scoreboard looks like this:

Points # Count Score
100 2 0 0
70 3 0 0
60 4 0 0
50 5 0 0
40 6 0 0
30 7 0 0
40 8 0 0
50 9 0 0
60 10 0 0
70 11 0 0
100 12 0 0

Example First Throw: For a roll of 1-3-4-4-6 keepers of 1.1.2.5.2 are selected giving pair 1 value of 4(1+3), pair 2 value of 10(4+6) and fifth dice of 4.

Points # Count Score
100 2 0 0
70 3 0 0
60 4 0 0
50 5 0 0
40 6 0 0
30 7 0 0
40 8 0 0
50 9 0 0
60 10 0 0
70 11 0 0
100 12 0 0
-------- -------- ------- -------
FIFTH DICE/ COUNT
4 1
0 0
0 0

Total score: -400

Example Third throw: For a roll of 1-2-2-4-5 keepers of 2.1.1.2.5 are selected giving pair 1 value of 4(2+2), pair 2 value of 5(1+4) and fifth dice of 5. Remember with this roll we cannot keep the 2 or the 4 since those were already taken in earlier rounds 1 + 2 and each of the first three need to be unique rolls for the fifth die until after round 3, then you must match the 3 selected fifth dice if possible.

Points # Count Score
100 2 0 0
70 3 0 0
60 4 2 -200
50 5 1 -200
40 6 0 0
30 7 0 0
40 8 0 0
50 9 1 -200
60 10 2 -200
70 11 0 0
100 12 0 0
-------- -------- ------- -------
FIFTH DICE/ COUNT
4 1
2 1
5 1

Total score: -800

Example Finished game:

Points # Count Score
100 2 2 -200
70 3 0 0
60 4 6 60
50 5 5 0
40 6 6 40
30 7 0 0
40 8 9 160
50 9 7 100
60 10 9 240
70 11 0 0
100 12 0 0
-------- -------- ------- -------
FIFTH DICE/ COUNT
4 8
2 6
5 7

Total score: -800

Provided Code

Start with the following source files:

dice.py

The dice module will work with a list of 5 string die face values. This module will need to work with not just our Can't Stop Dice number of dice (5) but with any number from 1–10 dice. The module will contain two functions:

  1. roll_dice – This function will take two parameters. The first will be an int for the number of dice in the list. The second parameter will be a random seed integer, with a default value of 0. Note it is possible to pass None as a parameter, which should result in a random seed value. This function will return a list of n dice values (each die has a int face value between 1 - 6). If the number of dice is out of range 1–10 then a single die of value 6 will be returned as a list of 1 item. If no parameters are provided, then a list of 5 dice values should be returned (having been generated using a seed of 0).

  2. are_valid – This function takes a dice parameter which is a list of from 1–10 dice rolls. This function will check the length of the list to make sure it is between 1 and 10 and check if the values of all dice in the list are between 1 and 6. Return True if all these conditions are met, False otherwise.

test_cantstopx.py

You should write unit tests for cantstopx.py. Rather than writing one very long test_cantstopx function, you should write several smaller tests to handle distinct cases and the sub-functions in the canstopx file. The provided file contains some testing functions to get you started.

Notice that the names of these functions describe the situations they are designed to test. For example, the name test_set_fifth_die_valid:

  • test - This makes it clear that this is a testing function
  • set_fifth_die - this is the function being tested
  • valid - this is the situation being tested.

You should properly document your tests and your cantstopx.py file. Docstrings for test functions are generally not required.

Categories that you should test include (this is a template for your test_cantstopx.py file):

  • Test set_fifth_die valid and invalid scenarios
  • Test valid_keeper_format valid and invalid scenarios
  • Test validate_keepers valid and invalid scenarios
  • Test score_keepers valid and invalid scenarios
  • Test get_keepers valid and invalid scenarios(can we do this?)
  • Test print_scoreboard

cantstopx.py

This module contains a simple terminal-based Cant Stop X function called play_game(). Once you have completed cantstopx.py you can call this function to try out your code. See the docstring for each function for details on how to code that function. You may also add in helper functions to accomplish subtasks.

This driver will import and make calls to the dice.py module and use the roll_dice function to return dice rolls. It may not be very useful for systematically testing your solution. The main mechanism for running your code for this project will be the test_cantstopx.py file described above.

Sample print_scoreboard for sample call:

counts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
scores = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
fifth_dice = [1, 5, 2]
fifth_count = [1, 1, 1]
rnd = 3
print(print_scoreboard(counts, scores, fifth_dice, fifth_count, rnd))
POINTS |  #  | COUNT | SCORE - Round:3
  100     2     0       0
   70     3     0       0
   60     4     0       0
   50     5     0       0
   40     6     0       0
   30     7     0       0
   40     8     0       0
   50     9     0       0
   60    10     0       0
   70    11     0       0
  100    12     0       0
FIFTH DICE/COUNT:
1 1
5 1
2 1

Part A - Readiness Quiz, dice.py (20 points)

1) Readiness Quiz (10 points) in Canvas.

Before the deadline for Part A you should read this document carefully, then look at the starter code provided above. Once you have a clear understanding of the expectations for this assignment, complete the readiness quiz in Canvas (10 points). The grading for this quiz will be all or nothing: your score on the quiz will be 0 if you miss any questions.

If you do not successfully complete the readiness quiz, you cannot receive any credit for Part A or Part B.

2) Complete the dice.py file (10 pts) and submit this to Gradescope by the deadline for your section.

Be sure to test your dice module carefully for correctness AND style before submitting into gradescope; You will be limited to 10 submissions for Part A code.

Part B - Code (70 points - 10 points will be given for instructor grading)

Upload only your cantstopx.py file to Gradescope. You should not include dice.py or test_cantstopx.py in your submission.

Before uploading your submission to Gradescope, be sure to complete the following steps:

  • Test your solution carefully.
  • Make sure that canstopx.py works as expected with your finished code.
  • Review the course style guide to ensure that your code meets the style requirements.
  • Run flake8 and eliminate all warnings.
  • Review and update comments as needed.

You are limited to a maximum of 10 submissions into Gradescope for Part B.

Programming Assignment Attribution

Provide a short statement describing any assistance that you received on this assignment, either from another student, an online source, an AI-enabled tool, or any other source.

Acknowledgments

This assignment page, is licensed under the Creative Commons Attribution-Share-Alike License 3.0.