CS 115 Program 2 Twenty-One Spring 2021


Due Dates:
Design: Friday, April 9, midnight
Phase I, Text version source: Sunday, April 18, midnight
Phase II, Graphical version source: Sunday, April 25, midnight

Assignment total points = Design (20 points) + Runs test cases (20 points) + Implementation Phase I (70 points) + Implementation Phase II (65 points) + Style and documentation (15 points) = 190 points

Submit all program materials (.py files) with the Canvas link.

Educational Goals: The goals of this program are that the student should use the concepts of

You are going to write a program that will play a dice game called Twenty One.

This program will be done in TWO phases. Design and implementation will be done with console (Shell) output first (Phase I). Then the graphics elements will be added for Phase II.

The Rules of the game

Sample Run WITHOUT the graphics:

Don't get to 21!

Each player tries not to get to 21
Each player has 3 passes, which allow them to not roll on a round.

Who is player 1? Bob
Who is player 2? Tim

Round 1:
Player Bob (P)ass or (R)oll? P
Bob passed the roll
Player Tim (P)ass or (R)oll? R
Tim rolled a 1

Bob total roll 0 passes 2       |        Tim total roll 1 passes 3


Round 2:
Player Bob (P)ass or (R)oll? R
Bob rolled a 2
Player Tim (P)ass or (R)oll? R
Tim rolled a 3

Bob total roll 2 passes 2       |        Tim total roll 4 passes 3


Round 3:
Player Bob (P)ass or (R)oll? R
Bob rolled a 6
Player Tim (P)ass or (R)oll? R
Tim rolled a 6

Bob total roll 8 passes 2       |        Tim total roll 10 passes 3


Round 4:
Player Bob (P)ass or (R)oll? P
Bob passed the roll
Player Tim (P)ass or (R)oll? R
Tim rolled a 1

Bob total roll 8 passes 1       |        Tim total roll 11 passes 3


Round 5:
Player Bob (P)ass or (R)oll? R
Bob rolled a 1
Player Tim (P)ass or (R)oll? P
Tim passed the roll

Bob total roll 9 passes 1       |        Tim total roll 11 passes 2


Round 6:
Player Bob (P)ass or (R)oll? R
Bob rolled a 4
Player Tim (P)ass or (R)oll? R
Tim rolled a 5

Bob total roll 13 passes 1      |        Tim total roll 16 passes 2


Round 7:
Player Bob (P)ass or (R)oll? R
Bob rolled a 5
Player Tim (P)ass or (R)oll? R
Tim rolled a 5

Bob total roll 18 passes 1      |        Tim total roll 21 passes 2

Bob won!

Sample Run where second player uses all his passes early
Note that after he uses all his passes, he has no option of Pass or Roll, the program automatically rolls without asking.
Note the input validation in Round 2


Don't get to 21!

Each player tries not to get to 21
Each player has 3 passes, which allow them to not roll on a round.

Who is player 1? Sam
Who is player 2? Tom

Round 1:
Player Sam (P)ass or (R)oll? R
Sam rolled a 6
Player Tom (P)ass or (R)oll? P
Tom passed the roll

Sam total roll 6 passes 3       |        Tom total roll 0 passes 2


Round 2:
Player Sam (P)ass or (R)oll? X
Invalid response, P or R please
Player Sam (P)ass or (R)oll? a
Invalid response, P or R please
Player Sam (P)ass or (R)oll? R
Sam rolled a 3
Player Tom (P)ass or (R)oll? P
Tom passed the roll

Sam total roll 9 passes 3       |        Tom total roll 0 passes 1


Round 3:
Player Sam (P)ass or (R)oll? r
Sam rolled a 4
Player Tom (P)ass or (R)oll? p
Tom passed the roll

Sam total roll 13 passes 3      |        Tom total roll 0 passes 0


Round 4:
Player Sam (P)ass or (R)oll? R
Sam rolled a 4
Tom rolled a 3

Sam total roll 17 passes 3      |        Tom total roll 3 passes 0


Round 5:
Player Sam (P)ass or (R)oll? R
Sam rolled a 2
Tom rolled a 4

Sam total roll 19 passes 3      |        Tom total roll 7 passes 0


Round 6:
Player Sam (P)ass or (R)oll? R
Sam rolled a 6

Sam total roll 25 passes 3      |        Tom total roll 7 passes 0

Tom won!

Testing

Link to the tables of test cases.

Design

Decide on what steps you will need to perform to solve this problem. Put it in Python form as comments. Save this Python file as "design2.py". See this page about how to write control structures in a design.
Follow this for the design of the 2 functions below This is one of the "Useful Readings" in the Quick Links on main page. Note that you should NOT consider the graphics part of the problem when you are doing the individual design.

A rough design for the main function:

#Prolog - 3 P's as usual
    #title / instructions
    #get players' names
    #do setup = initialization, etc.
    #
    #while neither player has lost
    #   display the round number
    #   do player 1's turn
    #   if player 1 didn't lose,
    #       do player 2's turn
    #   display results of the turns (names, roll totals and pass counts)
    #   
    #announce who won

Your design MUST include these two functions as well as the main function. They must be defined to do the jobs given and they must be called somewhere in the program. NOTE: neither of these functions has anything to do with winning or losing. That (winning and losing) is decided in the main function. All these functions do are the jobs described below.

Phase I Implementation

Implement the design with SHELL input/output (input/print), NOT graphics

Write a Python program to implement your design. You may have the help of ONE student, Make sure you reference each other if you do so. You can get help from Dr. Keen and ALL the TAs. Start with a copy of the Python file you have that has the design in it and write your Python code between the commented lines of the design. Make sure you eliminate any syntax and semantics errors. Verify that the program provides the correct behavior.

PLEASE put in the line "seed(25)" as the first line of your main function when you turn it in.

This makes it easier for us to run the test cases. Submit your individual source code (.py file) with the Canvas link.

Phase II Implementation

Now that you have your logic working correctly, implement the program again as a graphics program.

You can use these gifs of dice faces or you can choose others. They must be called 1.gif, 2.gif, 3.gif, etc. The gif for the "pass" move must be named 0.gif.

The description of the graphics part is here.