Project 3: Yahtzee

Submission Details

Due: 4/26

Submit via Gradescope:

4 files in total

  • Dice.py

  • ScoreCard.py

  • Turn.py

  • YahtzeeGame.py

  • A PDF that contains your self-assessment & reflection

Instructions

For this last project, you'll be programming a version of the dice game Yahtzee!

As a class, we'll spend time on the design-implementation process.

  • During 4/14's class, we'll play Yahtzee in small groups and get familiar with the game and scoring.

  • During 4/19's class, we'll preview a design and stubs with starter code.

  • During 4/22's class, we'll have open office hours [on zoom] for additional support.

Self-assessment & Reflection (reproduced from the Syllabus for reference)

Homeworks are an opportunity to engage with the material and practice your programming skills. To support you, solutions will be available on moodle. It is your responsibility to engage with them in a way that strategically moves your learning forward. You should:

  • Attempt the homework without looking at the solutions.

  • Review the solutions; if you were stuck, you may revise your homework. You may find yourself iteratively reviewing and revising to best support your learning.

  • When you submit your homework, you will be required to complete a self-assessment and reflection:

  1. Give yourself an assessment mark on the initial attempt:

✘ if you did not complete it

✓- if you completed it, but were very far from the solution

✓ if you completed it and essentially had the solution

✓+ if you completed it correctly, including precise communication

? if you are unsure as to whether or not you completed it

  1. Provide a short reflection as to why you earned that mark, such as:

  • I did not understand how to get started, and it was too close to the deadline to visit support hours.

  • I got stumped by a bug where my program entered an infinite loop.

  1. If you used the solutions to revise your work, describe what you needed to change, as in:

    • I modified the style of my conditional when I saw a simpler approach in the solutions.

    • I was so stuck that the majority of my submission is based on the solutions.

  2. Ask specific questions on portions that are still confusing, such as:

    • Why does it cause an error when I returned "1" instead of 1?

[Optional] Provide one hint for the homework (to your past self or future student).

Learning goals

As with previous projects, we will give you a design to implement. You'll continue practicing:

  • writing function definitions from high-level descriptions

  • type-hinting and using mypy to make sure types are consistent

  • the iterative process of writing a little code, running your program and debugging

Be strategic!

As a project:

  • You will not have access to solutions for this project.

  • The Gradescope autograder will not reveal the tests for your project until after the deadline.
    This is because it is important for you to understand how to test your code.

Be intentional around your approach to working on the project:

  • Start early!

  • Ask questions!

  • Leave time for questions by... starting early :)

  • When you're stuck, pause and evaluate what could be going on. Remember the self-regulated learning cycle!

    • Do you have a plan?

    • Are you evaluating your plan? How will you test your code as you go?

    • How will you revise? What will you do when you're confused? Stuck?

Sample runs

Here are some sample runs for reference!

Sample run - first few turns

Welcome to Yahtzee!

Start the turn!

[ 5 4 2 5 2 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,c,d,e

[ *5* 4 *2* *5* *2* ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,c,d,e

Ready to score: [ *5* 2 *2* *5* *2* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 6

(C) Threes: 0

(D) Fours: 0

(E) Fives: 10

(F) Sixes: 0

(G) Three of a kind: 16

(H) Four of a kind: 0

(I) Full house: 25

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 16


Which will you check off? [A/B/C/...] I

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 1 3 5 2 1 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,e

[ *1* 4 4 1 *1* ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ *1* 4 4 1 *1* ] with 1 rolls remaining.

Score Card

------------

(A) Ones: 3

(B) Twos: 0

(C) Threes: 0

(D) Fours: 8

(E) Fives: 0

(F) Sixes: 0

(G) Three of a kind: 11

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 11


Which will you check off? [A/B/C/...] A

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 4 2 4 5 4 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] N

[ 4 4 4 3 6 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] S

Ready to score: [ 4 4 4 3 6 ] with 1 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: 0

(C) Threes: 3

(D) Fours: 12

(E) Fives: 0

(F) Sixes: 6

(G) Three of a kind: 21

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 21


Which will you check off? [A/B/C/...] G

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 1 6 4 6 1 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] q

Sample run - attempt to choose checked-off combo

Welcome to Yahtzee!

Start the turn!

[ 2 5 5 5 6 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b,c,d

[ 1 *5* *5* *5* 4 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] n

Ready to score: [ 5 *5* *5* *5* 6 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 0

(C) Threes: 0

(D) Fours: 0

(E) Fives: 20

(F) Sixes: 6

(G) Three of a kind: 26

(H) Four of a kind: 26

(I) Full house: 0

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 26


Which will you check off? [A/B/C/...] e

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives: *20*

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house:

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 4 2 5 4 6 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ 4 2 5 4 6 ] with 2 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 2

(C) Threes: 0

(D) Fours: 8

(E) Fives: *20*

(F) Sixes: 6

(G) Three of a kind: 0

(H) Four of a kind: 0

(I) Full house: 0

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 21


Which will you check off? [A/B/C/...] e

Score Card

------------

(A) Ones: 0

(B) Twos: 2

(C) Threes: 0

(D) Fours: 8

(E) Fives: *20*

(F) Sixes: 6

(G) Three of a kind: 0

(H) Four of a kind: 0

(I) Full house: 0

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 21


Which will you check off? [A/B/C/...] e

Score Card

------------

(A) Ones: 0

(B) Twos: 2

(C) Threes: 0

(D) Fours: 8

(E) Fives: *20*

(F) Sixes: 6

(G) Three of a kind: 0

(H) Four of a kind: 0

(I) Full house: 0

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 21


Which will you check off? [A/B/C/...] m

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives: *20*

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house:

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance: *21*


Start the turn!

[ 3 2 4 6 5 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] q

Sample run - end of game


Start the turn!

[ 5 4 6 3 4 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ 5 4 6 3 4 ] with 2 rolls remaining.

Score Card

------------

(A) Ones: *4*

(B) Twos: *4*

(C) Threes: *6*

(D) Fours: *8*

(E) Fives: *10*

(F) Sixes: *12*

(G) Three of a kind: *26*

(H) Four of a kind: *13*

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: 0

(L) Yahtzee: *0*

(M) Chance: *16*


Which will you check off? [A/B/C/...] k

Score Card

------------

(A) Ones: *4*

(B) Twos: *4*

(C) Threes: *6*

(D) Fours: *8*

(E) Fives: *10*

(F) Sixes: *12*

(G) Three of a kind: *26*

(H) Four of a kind: *13*

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *0*

(L) Yahtzee: *0*

(M) Chance: *16*


Final score: 154

Sample run - entire game

Welcome to Yahtzee!

Start the turn!

[ 2 2 6 2 4 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,b,d

[ *2* *2* 5 *2* 5 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ *2* *2* 5 *2* 5 ] with 1 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 6

(C) Threes: 0

(D) Fours: 0

(E) Fives: 10

(F) Sixes: 0

(G) Three of a kind: 16

(H) Four of a kind: 0

(I) Full house: 25

(J) Small straight: 0

(K) Large straight: 0

(L) Yahtzee: 0

(M) Chance: 16


Which will you check off? [A/B/C/...] I

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight:

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 4 6 1 2 5 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,b,e

[ *4* *6* 3 2 *5* ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ *4* *6* 3 2 *5* ] with 1 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 2

(C) Threes: 3

(D) Fours: 4

(E) Fives: 5

(F) Sixes: 6

(G) Three of a kind: 0

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: 30

(K) Large straight: 40

(L) Yahtzee: 0

(M) Chance: 20


Which will you check off? [A/B/C/...] k

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind:

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 6 4 4 1 2 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b,c

[ 2 *4* *4* 5 4 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] e

Ready to score: [ 6 *4* *4* 3 *4* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 0

(C) Threes: 3

(D) Fours: 12

(E) Fives: 0

(F) Sixes: 6

(G) Three of a kind: 21

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: 0

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 21


Which will you check off? [A/B/C/...] g

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight:

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 3 1 4 2 2 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] s

Ready to score: [ 3 1 4 2 2 ] with 2 rolls remaining.

Score Card

------------

(A) Ones: 1

(B) Twos: 4

(C) Threes: 3

(D) Fours: 4

(E) Fives: 0

(F) Sixes: 0

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: 30

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 12


Which will you check off? [A/B/C/...] j

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes:

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 3 3 1 5 1 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,b

[ *3* *3* 3 2 2 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] c

Ready to score: [ *3* *3* *3* 4 5 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 0

(C) Threes: 9

(D) Fours: 4

(E) Fives: 5

(F) Sixes: 0

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 18


Which will you check off? [A/B/C/...] c

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes: *9*

(D) Fours:

(E) Fives:

(F) Sixes:

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 6 2 5 6 2 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,d

[ *6* 4 6 *6* 2 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] c

Ready to score: [ *6* 5 *6* *6* 2 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 0

(B) Twos: 2

(C) Threes: *9*

(D) Fours: 0

(E) Fives: 5

(F) Sixes: 18

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 25


Which will you check off? [A/B/C/...] f

Score Card

------------

(A) Ones:

(B) Twos:

(C) Threes: *9*

(D) Fours:

(E) Fives:

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 2 1 5 1 6 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b,d

[ 4 *1* 5 *1* 1 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] e

Ready to score: [ 2 *1* 2 *1* *1* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: 3

(B) Twos: 4

(C) Threes: *9*

(D) Fours: 0

(E) Fives: 0

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 7


Which will you check off? [A/B/C/...] a

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes: *9*

(D) Fours:

(E) Fives:

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 5 4 4 3 3 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b,c

[ 6 *4* *4* 5 5 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] n

Ready to score: [ 4 *4* *4* 1 5 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: 0

(C) Threes: *9*

(D) Fours: 12

(E) Fives: 5

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 18


Which will you check off? [A/B/C/...] d

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes: *9*

(D) Fours: *12*

(E) Fives:

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 6 3 5 1 4 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] n

[ 5 5 2 2 5 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,b,e

Ready to score: [ *5* *5* 2 3 *5* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: 2

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: 15

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 20


Which will you check off? [A/B/C/...] e

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance:


Start the turn!

[ 2 3 6 5 6 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a

[ *2* 4 5 4 5 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] n

Ready to score: [ *2* 5 3 4 1 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: 2

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: 15


Which will you check off? [A/B/C/...] m

Score Card

------------

(A) Ones: *3*

(B) Twos:

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance: *15*


Start the turn!

[ 1 2 3 5 3 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b

[ 2 *2* 5 5 2 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] e

Ready to score: [ 3 *2* 5 6 *2* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: 4

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 0

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: *15*


Which will you check off? [A/B/C/...] b

Score Card

------------

(A) Ones: *3*

(B) Twos: *4*

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind:

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance: *15*


Start the turn!

[ 1 1 5 6 3 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] a,b

[ *1* *1* 3 3 1 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] e

Ready to score: [ *1* *1* 1 3 *1* ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: *4*

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: 7

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: *15*


Which will you check off? [A/B/C/...] h

Score Card

------------

(A) Ones: *3*

(B) Twos: *4*

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: *7*

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee:

(M) Chance: *15*


Start the turn!

[ 4 2 3 3 6 ] with 2 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] c,d

[ 2 3 *3* *3* 5 ] with 1 rolls remaining.

a b c d e

Which dice to keep? [(N)one/(S)top/a,c,d,...] b

Ready to score: [ 6 *3* *3* *3* 4 ] with 0 rolls remaining.

Score Card

------------

(A) Ones: *3*

(B) Twos: *4*

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: *7*

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: 0

(M) Chance: *15*


Which will you check off? [A/B/C/...] L

Score Card

------------

(A) Ones: *3*

(B) Twos: *4*

(C) Threes: *9*

(D) Fours: *12*

(E) Fives: *15*

(F) Sixes: *18*

(G) Three of a kind: *21*

(H) Four of a kind: *7*

(I) Full house: *25*

(J) Small straight: *30*

(K) Large straight: *40*

(L) Yahtzee: *0*

(M) Chance: *15*


Final score: 199

4/14 class time

Let's play Yahtzee together to get familiar with the problem!

  • Work an example

  • Try more examples

  • Use OOP to start coming up with a design

    • A Dice class

    • A ScoreCard class

...

4/19 class time

It turns out that there is a fair amount to the game, so we're giving you some starter code to reduce the overhead. There is nothing that you haven't seen before in it, but it would take more time than we have and require some careful specifications to help with the auto-grading.

We'll spend class time practicing the design-implementation process.

Docstring comments for documentation

Remember how we've been asking you to write docstring comments after each declaration with the """ style?

You'll see that the stubs we provide include docstring comments as well.

This allows us to generate documentation! Let's try it out by running the following code in interactive Python.

  • Start interactive python by typing python3 at a command prompt.

import Dice

help(Dice)

Type q to exit the documentation.

Mistake in starter code!

Update the playGame method to actually return the score or you will get a mypy error!

def playGame( self ) -> int:

""" Play Yahtzee! This will prompt the player to play one turn

as long as there are combos left. When the game ends, returns

the final score. """


print( "Welcome to Yahtzee!" )


# while there are combos not yet checked off

while self.__scoreCard.numRemainingCombos() > 0:

# play a turn

self.playTurn()


# final score

finalScore:int = self.__scoreCard.totalScore()

print( f"Final score: {finalScore}")


# return the final score

return finalScore

Tips to be successful in the project

  • Resist the temptation to write the entire program all at once! Otherwise, the debugging process becomes so much more difficult and time-consuming!

    • Work with the function "stubs" provided by the starter code; you may decide to come up with additional ones as you think more carefully about the ScoreCard methods. Perhaps there are repeated behaviors you'd like to reuse?

    • Use mypy to check types before running your program.

    • Implement one function at a time, then test. You have seen guidance for this throughout the class (refer back to examples, homeworks and the project).

  • Have pen and paper with you to help you think through the logic, particularly for scoring the "lower half" of the score card.

    • Work examples! What do you expect the parameters to be? What do you expect the result to be?

    • Test your code with these examples by writing small test functions and hard-coding the Dice values.

      • Remember that you have also seen how to set a random seed to obtain repeated behavior.

  • Remember the debugging strategies:

    • Print statements help you peek at memory during program execution.

    • Tracing your program on paper helps you understand when the execution doesn't match your intended logic.

Design overview

We'll spend time on 4/19 going over the design.

Dice class

Instance properties

  • __value:int to track the value (should be 1,2,...6)

  • __keeper:bool to track whether or not this dice is a keeper (a True value means it cannot change its value)

Dice Documentation

class Dice(builtins.object)

| Represents a single 6-sided dice that can be rolled

| to a value 1,2,...,6. Can be a "keeper" where the value

| does not change if a roll is attempted.

|

| Methods defined here:

|

| __init__(self)

| Constructor creates a new dice that has

| not been rolled and is not a keeper.

|

| __str__(self) -> str

| Returns a string representation of this dice with the value;

| if it is a keeper, enclose it in asterisks.

|

| getValue(self) -> int

| Get the value of this dice (e.g., what number is showing).

| -1 means the dice has not yet been rolled.

|

| isKeeper(self) -> bool

| Returns True if the dice is a keeper (cannot be rolled).

|

| keep(self) -> None

| Keep this dice so its value cannot change.

|

| release(self) -> None

| Release this dice so it can be rolled.

|

| roll(self) -> None

| Try to roll the dice; if it's not a keeper, roll and update the value.

Turn class


Turn documentation

class Turn(builtins.object)

| Represents a Turn of Yahtzee, where a player has 5 dice they can roll

| up to 3 times. After each roll, they can choose to keep some/all of the dice.

|

| Methods defined here:

|

| __init__(self)

| Constructor creates a new Turn object that tracks dice and rolls remaining.

|

| __str__(self) -> str

| Return a string representation of this turn.

|

| getDice(self) -> list

| Get a list of the dice.

|

| getDiceAt(self, index: int) -> Dice.Dice

| Get the (single) dice at the index.

|

| getNumRemainingRolls(self) -> int

| Get the number of remaining rolls for this turn.

|

| keep(self, diceIndex: int) -> None

| Set the dice at the diceIndex to be a keeper. Assumes

| we start counting at 0, so that we have diceIndex valued at 0,1,2,3,4.

|

| release(self, diceIndex: int) -> None

| Release the dice at the diceIndex so it can be rolled. Assumes

| we start counting at 0, so that we have diceIndex valued at 0,1,2,3,4.

|

| reset(self) -> None

| Reset the turn so there are 3 rolls remaining and all dice

| are released.

|

| rollDice(self) -> None

| Roll the dice if there are rolls remaining;

| if any are keepers, they will not change value.

| Updates the number of rolls remaining accordingly.

ScoreCard class

CORRECTION for starter code!

ScoreCard documentation

class ScoreCard(builtins.object)

| Represents a score card for yahtzee that can compute values for each

| (unscored) combination and can track which combinations are scored.

|

| Methods defined here:

|

| __init__(self)

| Initialize self. See help(type(self)) for accurate signature.

|

| __str__(self) -> str

| Return a string representation of the score card. Each combo will

| be on its own line with the selector item in front. Scores that are

| checked off will be surrounded by asterisks, and all others will be blank,

| as in

| (A) Ones: *3*

| (B) Twos:

| (C) Threes: *0*

| ...

|

| checkOff(self, comboName: str) -> None

| Check off this combo name (e.g., "1s", "Full house") with its current score.

|

| checkedOff(self, comboName: str) -> bool

| Return true if the combo name (e.g., "1s", "Full house") has

| been scored/checked off.

|

| containsAll(self, values: list, searchElts: list) -> bool

| Checks if every element in searchElts is in the values list

| and returns true if so.

|

| diceToValuesList(self, dice: list) -> list

| Given a list of dice, create a list of ints containing the dice values.

| This convenience method will then allow list methods to be used!

|

| getScore(self, comboName: str) -> int

| Returns the combo's score (does not matter if the combo is checked off or not).

| If the comboName is not in the dictionary, returns -1 as a flag.

|

| numRemainingCombos(self) -> int

| Return the number of combos not yet checked off.

|

| scoreChance(self, dice: list) -> None

| Given the dice list, score chance (sum of values).

|

| scoreDice(self, dice: list) -> None

| Given the dice list, score the upper and lower halves.

|

| scoreFourOfAKind(self, dice: list) -> None

| Given the dice list, score four of a kind.

|

| scoreFullHouse(self, dice: list) -> None

| Given the dice list, score full house (2 of a kind + 3 of a kind).

|

| scoreLargeStraight(self, dice: list) -> None

| Given the dice list, score large straight (5 in order).

|

| scoreLowerHalf(self, dice: list) -> None

| Given the dice list score the lower half of the scorecard

| and enter scores for combos like "Full house" or "Small straight"

| unless it's already checked off.

|

| scoreSmallStraight(self, dice: list) -> None

| Given the dice list, score small straight (4 in order).

|

| scoreThreeOfAKind(self, dice: list) -> None

| Given the dice list, score three of a kind.

|

| scoreUpperHalf(self, dice: list) -> None

| Given the dice list, score the upper half of the scorecard

| and enter scores for "1s", "2s", ..."6s" unless it's already checked off.

|

| scoreYahtzee(self, dice: list) -> None

| Given the dice list, score Yahtzee (all 5 the same).

|

| setScore(self, comboName: str, score: int) -> None

| If the combo has not yet been checked off,

| stores the score as the value for the combo.

|

| toString(self, onlyChecked: bool) -> str

| Return a string representation of the score card. Each combo will

| be on its own line with the selector item in front. Scores that are

| checked off will be surrounded by asterisks, as in

| (A) Ones: *3*

| (B) Twos: 4

| (C) Threes: 0

| ...

| If onlyChecked is True, non checked off values will be blank;

| otherwise, they will show current value (probably from most recent

| dice rolls).

|

| totalScore(self) -> int

| Compute the total score (the total of all checked off combos).

|

Game play

The starter code provides the main game play scaffolding. Your task will be to implement correct functionality by replacing stub definitions.

ScoreCard hints

As you might imagine, scoring can require a little bit of puzzle-solving. If you get stuck, there are some hints here!

Testing as you go

The following code shows how to add some testing code for a particular score (full house). You could add this to ScoreCard.py and run that as its own program to test as you go!

def test():

# we only need this import for testing

from Dice import Dice


# test the scoring for "Full house"

testValues = [2,3,2,3,2]


# make a list of dice and hard-code the values

diceList = []

for testVal in testValues:

# make a new dice object

currentDice:Dice = Dice()


# hard-code its value by "hacking" the "private" variable

# refer to https://sites.google.com/mtholyoke.edu/cs151-02-s22/notes/object-oriented-programming-oop#h.9gz3g9u9w86x

currentDice.__dict__["_Dice__value"] = testVal


# add it to the list

diceList.append( currentDice )

# print the dice to make sure it worked

for singleDice in diceList:

print( singleDice.getValue() )


# now make a new score card object

testCard:ScoreCard = ScoreCard()


# and ask it to score the full house using this list of dice values

testCard.scoreFullHouse( diceList )


# see if it worked

print( testCard.toString(False) )


if __name__ == "__main__":

test()

Three of a kind, Four of a kind, Yahtzee, Full house

  • A list object can count the number of occurrences of a value.

    • To use this, perhaps it will be helpful to have a method that takes in the list of Dice and creates a list of int values?

If you're stuck, you can use the method below.

  • When checking for three of a kind, try this:

    • iterate over the dice values 1,2,...,6

      • count the number of occurrences of that value

      • if it's >= 3, you've found 3 of a kind!

  • When checking for a full house, notice that you need:

    • exactly 2 of one value

    • exactly 3 of another value

Small straight, Large straight

There are many ways to do this, but probably the most straightforward is to think about the possible ways you could get a:

  • Small straight

    • You need to have 1,2,3,4 or 2,3,4,5, or 3,4,5,6 show up as values for the dice

  • Large straight

    • You need to have 1,2,3,4,5 or 2,3,4,5,6 show up as values for the dice

Perhaps it will be helpful to have a method that checks if a list of values is in contained in another list of values...

  • Something like: containsAll( values:list, searchElts:list ) returns True if every element of the searchElts list appears in the values list.

  • The in operator can check if a value is in a list:

vals:list = ["fish", "cat", "twig"]

print( "cat" in vals )

prints out

True

Dice to int list: helper method [solutions]

def diceToValuesList( self, dice:list ) -> list:

""" Given a list of dice, create a list of ints containing the dice values.

This convenience method will then allow list methods to be used! """


valuesList:list = []


# iterate over the dice

for singleDice in dice:

valuesList.append( singleDice.getValue() )

return valuesList