Project 1: The Game of Hog
Introduction
Important submission note: For full credit:
Submit with Phase 1 complete by Friday, June 30, worth 1 pt. Submit the complete project by Thursday, July 6. Try to attempt the problems in order, as some later problems will depend on earlier problems in their implementation and therefore also when running ok tests.
You may complete the project with a partner.
You can get 1 bonus point by submitting the entire project by Wednesday, July 5. You can receive extensions on the project deadline and checkpoint deadline, but not on the early deadline, unless you're a DSP student with an accommodation for assignment extensions.
In this project, you will develop a simulator and multiple strategies for the dice game Hog. You will need to use control statements and higher-order functions together, as described in Sections 1.2 through 1.6 of Composing Programs, the online textbook.
When students in the past have tried to implement the functions without thoroughly reading the problem description, they’ve often run into issues. 😱 Read each description thoroughly before starting to code.
Rules
In Hog, two players alternate turns trying to be the first to end a turn with at least GOAL total points, where GOAL defaults to 100. On each turn, the current player chooses some number of dice to roll, up to 10. That player's score for the turn is the sum of the dice outcomes. However, a player who rolls too many dice risks:
Sow Sad. If any of the dice outcomes is a 1, the current player's score for the turn is 1.
- Example 1: The current player rolls 7 dice, 5 of which are 1's. They score 1 point for the turn.
- Example 2: The current player rolls 4 dice, all of which are 3's. Since Sow Sad did not occur, they score 12 points for the turn.
In a normal game of Hog, those are all the rules. To spice up the game, we'll include some special rules:
- Boar Brawl. A player who rolls zero dice scores three times the absolute difference between the tens digit of the opponent’s score and the ones digit of the current player’s score, or 1, whichever is higher. The ones digit refers to the rightmost digit and the tens digit refers to the second-rightmost digit.
Fuzzy Factors. A fuzzy number is any number n where the greatest common divisor (GCD) of n and 100 is greater than 10. Recall that the GCD of a and b is the largest factor that is shared between both numbers (for example, the GCD of 10 and 15 is 5). After a player gains points for their turn, if their resulting score is a fuzzy number, add two times the tens digit of the GCD to the player's score.
Download starter files
To get started, download all of the project code as a zip archive. Below is a list of all the files you will see in the archive once unzipped. For the project, you'll only be making changes to hog.py.
- hog.py: A starter implementation of Hog
- dice.py: Functions for making and rolling dice
- hog_gui.py: A graphical user interface (GUI) for Hog (updated)
- ucb.py: Utility functions for CS 61A
- hog_ui.py: A text-based user interface (UI) for Hog
- ok: CS 61A autograder
- tests: A directory of tests used by ok
- gui_files: A directory of various things used by the web GUI You may notice some files other than the ones listed above too—those are needed for making the autograder and portions of the GUI work. Please do not modify any files other than hog.py.
Logistics
The project is worth 24 points, of which 1 point is for submitting Phase 1 by the checkpoint date of Friday, June 30.
You will turn in the following files:
hog.py You do not need to modify or turn in any other files to complete the project. To submit the project, submit the required files to the appropriate Gradescope assignment.
For the functions that we ask you to complete, there may be some initial code that we provide. If you would rather not use that code, feel free to delete it and start from scratch. You may also add new function definitions as you see fit.
However, please do not modify any other functions or edit any files not listed above. Doing so may result in your code failing our autograder tests. Also, please do not change any function signatures (names, argument order, or number of arguments).
Throughout this project, you should be testing the correctness of your code. It is good practice to test often, so that it is easy to isolate any problems. However, you should not be testing too often, to allow yourself time to think through problems.
We have provided an autograder called ok to help you with testing your code and tracking your progress. The first time you run the autograder, you will be asked to log in with your Ok account using your web browser. Please do so. Each time you run ok, it will back up your work and progress on our servers.
The primary purpose of ok is to test your implementations.
If you want to test your code interactively, you can run
python3 ok -q [question number] -i
with the appropriate question number (e.g. 01) inserted. This will run the tests for that question until the first one you failed, then give you a chance to test the functions you wrote interactively. You can also use the debugging print feature in OK by writing
print("DEBUG:", x)
which will produce an output in your terminal without causing OK tests to fail with extra output.
Graphical User Interface
A graphical user interface (GUI, for short) is provided for you. At the moment, it doesn't work because you haven't implemented the game logic. Once you complete the play function, you will be able to play a fully interactive version of Hog!
Once you've done that, you can run the GUI from your terminal:
python3 hog_gui.py
...