→This assignment is due by Tuesday, November 01, 2022, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B,
L4C
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←
· Instructions · Rubric ·Submission ·
We're going to create a game simulation of several people playing Left-Center-Right. If you aren't familiar with the rules, here's a two minute summary of the game play: LCR Video Explanation.
The requirements for this assignment are more abstractly defined and the implementation is left to your choosing. However, you will need to defend the choices you made in your implementation.
Object Structure
We'll need to create several concepts to the computer:
- A Player
- A Die
- A Game
Player
The Player will have two attributes that track its state:
- A player number represented as an integer (feel free to make this into a
string
and allow your player's to have actual names) - A number of chips represented as an integer
The Player will have several behaviors associated with its state:
- A function to return the player number (or name)
- A function to return the number of chips the player currently has
- A function to give a single chip to another player. This function will decrement the callee's chips by one and increase the target's chips by one
- A function to give a single chip to the center. This function will decrement the callee's chips by one
The Die
We'll take a simple approach to a die. We'll simulate it by generating a random number. Our game will use an 8-sided die so you'll want to generate a random number in the range [0, 7]. The possible values map to the following outcomes:
- 0 - keep your chip
- 1 - keep your chip
- 2 - keep your chip
- 3 - give one chip to the player on your left
- 4 - give one chip to the player on your right
- 5 - give one chip to the center
- 6 - reverse the direction of play
- 7 - skip one player
The Game
The game is where the all the logic will be kept. We'll use a Circular Doubly Linked List to keep track of all the players. The game will need to track several values:
- The number of players (which corresponds to the size of our list)
- Which player is the current player to roll
- Which direction the game is moving
- The number of chips in the center
The gameplay will be implemented with the following pseudocode:
- Prompt the user for how many players are playing
- Create a Circular Doubly Linked List of Players
- Give each player 3 chips to start
- Player 1 will go first
- While there are at least two players with chips
- Determine how many dice the current player will roll
- If the player has 3 or more chips, they will roll 3 dice
- Otherwise, the player rolls a number of dice equal to their number of chips
- For each die rolled
- If the die is a keep value, nothing happens
- If the die is a pass left value, current player gives one chip to the player on their left (this will correspond to the next player)
- If the die is a pass right value, current player gives one chip to the player on their right (this will correspond to the previous player)
- If the die is a center value, current player gives one chip to the center
- If the die is a reverse value, reverse the current direction the game is moving
- If the die is a skip value, increment a counter to track how many players to skip
- If play is moving clockwise
- move to the next player
- For the number of skips to apply
- Move to the next player
- If play is moving counterclockwise
- move to the previous player
- For the number of skips to apply
- Move to the previous player
- Determine how many dice the current player will roll
- When only one player has chips left, print out who wins!
As this is a simulation, once we start the program it will run automatically by itself until the end of the game is reached. To inform the user what is occurring, print a message to the standard out with what is occurring. An example run of the game is shown below:
> ./A5
How many players are playing: 2
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 7 - skip! skipping 1 players
Rolled a 0 - keep!
Rolled a 4 - give right - Player #2 has 4 chips - Player #1 has 2 chips
Player #1 has 2 chips left
Rolling 2 dice
Rolled a 1 - keep!
Rolled a 3 - give left - Player #2 has 5 chips - Player #1 has 1 chips
Player #2 has 5 chips left
Rolling 3 dice
Rolled a 0 - keep!
Rolled a 3 - give left - Player #1 has 2 chips - Player #2 has 4 chips
Rolled a 4 - give right - Player #1 has 3 chips - Player #2 has 3 chips
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 2 - keep!
Rolled a 5 - give center - Center has 1 chips - Player #1 has 2 chips
Rolled a 5 - give center - Center has 2 chips - Player #1 has 1 chips
Player #2 has 3 chips left
Rolling 3 dice
Rolled a 6 - reverse!
Rolled a 7 - skip! skipping 1 players
Rolled a 7 - skip! skipping 2 players
Player #1 has 1 chips left
Rolling 1 dice
Rolled a 6 - reverse!
Player #2 has 3 chips left
Rolling 3 dice
Rolled a 7 - skip! skipping 1 players
Rolled a 0 - keep!
Rolled a 4 - give right - Player #1 has 2 chips - Player #2 has 2 chips
Player #2 has 2 chips left
Rolling 2 dice
Rolled a 5 - give center - Center has 3 chips - Player #2 has 1 chips
Rolled a 3 - give left - Player #1 has 3 chips - Player #2 has 0 chips
Player #1 wins with 3 chips left after 8 turns
The two player game shows some features of the circular linked list. Left and Right correspond to the same player. Reverse has no apparent effect. Skipping one player returns to the same player.
Another play with more players is shown below.
> ./A5
How many players are playing: 3
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 2 - keep!
Rolled a 7 - skip! skipping 1 players
Rolled a 3 - give left - Player #2 has 4 chips - Player #1 has 2 chips
Player #3 has 3 chips left
Rolling 3 dice
Rolled a 3 - give left - Player #1 has 3 chips - Player #3 has 2 chips
Rolled a 6 - reverse!
Rolled a 0 - keep!
Player #2 has 4 chips left
Rolling 3 dice
Rolled a 0 - keep!
Rolled a 1 - keep!
Rolled a 1 - keep!
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 2 - keep!
Rolled a 1 - keep!
Rolled a 0 - keep!
Player #3 has 2 chips left
Rolling 2 dice
Rolled a 0 - keep!
Rolled a 7 - skip! skipping 1 players
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 6 - reverse!
Rolled a 7 - skip! skipping 1 players
Rolled a 3 - give left - Player #2 has 5 chips - Player #1 has 2 chips
Player #3 has 2 chips left
Rolling 2 dice
Rolled a 0 - keep!
Rolled a 3 - give left - Player #1 has 3 chips - Player #3 has 1 chips
Player #1 has 3 chips left
Rolling 3 dice
Rolled a 3 - give left - Player #2 has 6 chips - Player #1 has 2 chips
Rolled a 0 - keep!
Rolled a 6 - reverse!
Player #3 has 1 chips left
Rolling 1 dice
Rolled a 6 - reverse!
Player #1 has 2 chips left
Rolling 2 dice
Rolled a 2 - keep!
Rolled a 3 - give left - Player #2 has 7 chips - Player #1 has 1 chips
Player #2 has 7 chips left
Rolling 3 dice
Rolled a 5 - give center - Center has 1 chips - Player #2 has 6 chips
Rolled a 6 - reverse!
Rolled a 7 - skip! skipping 1 players
Player #3 has 1 chips left
Rolling 1 dice
Rolled a 4 - give right - Player #2 has 7 chips - Player #3 has 0 chips
Player #2 has 7 chips left
Rolling 3 dice
Rolled a 5 - give center - Center has 2 chips - Player #2 has 6 chips
Rolled a 3 - give left - Player #3 has 1 chips - Player #2 has 5 chips
Rolled a 5 - give center - Center has 3 chips - Player #2 has 4 chips
Player #1 has 1 chips left
Rolling 1 dice
Rolled a 0 - keep!
Player #3 has 1 chips left
Rolling 1 dice
Rolled a 5 - give center - Center has 4 chips - Player #3 has 0 chips
Player #2 has 4 chips left
Rolling 3 dice
Rolled a 5 - give center - Center has 5 chips - Player #2 has 3 chips
Rolled a 7 - skip! skipping 1 players
Rolled a 6 - reverse!
Player #1 has 1 chips left
Rolling 1 dice
Rolled a 7 - skip! skipping 1 players
Player #1 has 1 chips left
Rolling 1 dice
Rolled a 2 - keep!
Player #2 has 3 chips left
Rolling 3 dice
Rolled a 1 - keep!
Rolled a 0 - keep!
Rolled a 4 - give right - Player #1 has 2 chips - Player #2 has 2 chips
Player #1 has 2 chips left
Rolling 2 dice
Rolled a 3 - give left - Player #2 has 3 chips - Player #1 has 1 chips
Rolled a 0 - keep!
Player #2 has 3 chips left
Rolling 3 dice
Rolled a 2 - keep!
Rolled a 4 - give right - Player #1 has 2 chips - Player #2 has 2 chips
Rolled a 0 - keep!
Player #1 has 2 chips left
Rolling 2 dice
Rolled a 0 - keep!
Rolled a 1 - keep!
Player #2 has 2 chips left
Rolling 2 dice
Rolled a 3 - give left - Player #3 has 1 chips - Player #2 has 1 chips
Rolled a 7 - skip! skipping 1 players
Player #1 has 2 chips left
Rolling 2 dice
Rolled a 5 - give center - Center has 6 chips - Player #1 has 1 chips
Rolled a 3 - give left - Player #2 has 2 chips - Player #1 has 0 chips
Player #2 has 2 chips left
Rolling 2 dice
Rolled a 5 - give center - Center has 7 chips - Player #2 has 1 chips
Rolled a 5 - give center - Center has 8 chips - Player #2 has 0 chips
Player #3 wins with 1 chips left after 25 turns
Hints
- Be very careful with passing objects to a function. If you pass an object to a function by value, then the copy constructor is called and any manipulations to the target will result in the copy being modified. The argument will remain unmodified. When dealing with objects as parameters, we'll want to be using either pass-by-reference or pass-by-pointer.
- Be very careful with returning objects from a function. If you return an object from a function by value, then the copy constructor is called and any manipulations to the returned value will result in the copy being modified. The original will remain unmodified. When dealing with objects as return value, we'll want to be returning a pointer to the object.
- The pseudocode gives you hints to the structures to use and tests to perform.
- Every run will be random. Initially, you may choose to not seed the RNG so you have repeatable dice rolls to ensure the different outcomes are being handled appropriately. Once we are sure the individual outcomes are correct, then we can seed the RNG with the current time as appropriate.
- For this simulation, the Players correspond to the Nodes in our list. The Left-Center-Right game is a modified LinkedList of Players containing other properties to keep track of the game state (current player, direction, etc.).
Exit Interview
When completed, create a README.txt
file and respond to the following questions:
- How did you structure your Player?
- How did you structure your Game?
- How did you make use of classes and functions? What went where?
Extra Credit
Very often games give an indication how long it will take to complete a game. Now that we have a simulation in place, we can begin running some simulations to calculate some statistics. Modify your program to ask the user how many games they wish to simulate. After each game, track how many turns it took to complete. After all games have finished, print the average number of turns per game.
We can now compute this statistic for a variety of number of players. Add to your README.txt
a table of the following form:
# Players | # Turns
----------|--------
2 |
3 |
4 |
5 |
10 |
20 |
And fill in the average number of turns. Answer the following two questions in your README.txt
- How many simulations did you need to run to reach a stable average?
- What is the relationship between the number of players and the number of turns? Linear? Quadratic? Exponential? Other?
Testing
The graders will build your program with the Makefile you provide to match your code structure.
Best Practices To Follow
- One clear and consistent coding style used (such as K&R, 1TBS, or Allman).
- Course naming scheme is followed for variable, function, class, and other identifiers. See the course style guide for more specifics.
- Code is self-documenting. Variables sensibly named, function names descriptive of their purpose.
- Keep your headers clean. Put the absolute minimum required in your headers for your interface to be used. Anything that can go in a source file should. Don't
#include
any system headers in your .h files that aren't absolutely required in that file specifically. Avoidusing namespace
in headers. - Implement the Big-3 as appropriate.
- Use
const
wherever possible:- If you declare a variable that is never modified, it should be
const
. - If your function takes a parameter and does not modify it, it should be
const
. - If a member function does not modify the callee, it should be
const
. - If you are pointing at a value that does not change, it should point at a constant value (e.g.
const T*
). - If the pointer itself is never modified, it should be a constant pointer (e.g.
T* const
).
- If you declare a variable that is never modified, it should be
- Don't leak memory. Every allocation using
new
needs to have a correspondingdelete
. - Use appropriate inheritance access. Only expose necessary members to derived classes.
- Use
override
andfinal
wherever possible and/or appropriate on derived classes. - Don't use global variables unless absolutely necessary. Instead, encapsulate them and design your interfaces effectively. If there is no way around using a global variable, be prepared to defend and justify its usage.
- Program flow uses structural blocks (conditionals/loops) effectively, appropriately, and efficiently.
- Code compiles and links without any errors or warnings.
- Program runs without any run time errors. Exceptions are properly caught, user input is validated appropriately, and program exits successfully.
Grading Rubric
Your submission will be graded according to the following rubric.
Points | Requirement Description |
15 | All labs completed and submitted L4A, L4B, L4C |
5 | Player class created and implemented correctly |
5 | Circular Doubly Linked List created and implemented correctly |
12 | Each of the eight die rolls handled correctly |
8 | Game play runs correctly |
5 | Game ends under correct conditions |
+4 | A4 Extra Credit Completed. |
5 | Best practices are followed:
|
55 | Total Points |
→This assignment is due by Tuesday, November 01, 2022, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B,
L4C
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.
It is critical that you follow these steps when submitting homework.
If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work.
Submission Instructions
Here are step-by-step instructions for submitting your homework properly:
-
Make sure you have the appropriate comment header block at the top of every source code file for this set. The header
block should include the following information at a minimum.
Be sure to fill in the appropriate information, including:/* CSCI 200: Assignment 4: A4 - Wild Left-Center-Right Simulation
* * Author: XXXX (INSERT_NAME) * Resources used (Office Hours, Tutoring, Other Students, etc & in what capacity): * // list here any outside assistance you used/received while following the * // CS@Mines Collaboration Policy and the Mines Academic Code of Honor * * XXXXXXXX (MORE_COMPLETE_DESCRIPTION_HERE) */- Assignment number
- Assignment title
- Your name
- If you received any type of assistance (office hours - whose, tutoring - when), then list where/what/who gave you the assistance and describe the assistance received
- A description of the assignment task and what the code in this file accomplishes.
Additionally, update theMakefile
for A4 to generate a target executable namedA4
.
- File and folder names are extremely important in this process.
Please double-check carefully, to ensure things are named correctly.
- The top-level folder of your project must be named
Set4
- Inside
Set4
, create 4 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g.L4A
,L4B
,L4C
, andA4
). - Copy your files into the subdirectories of
Set4
(steps 2-3), zip thisSet4
folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas. - For example, when you zip/submit
Set4
, there will be 4 sub-folders calledL4A
,L4B
,L4C
, andA4
inside theSet4
folder, and each of these sub-folders will have the associated files.
- The top-level folder of your project must be named
- Using Windows Explorer (not to be confused with Internet Explorer), find the files
named
main.cpp, Makefile, README.txt, *.h, *.hpp, *.cpp
.
STOP: Are you really sure you are viewing the correct assignment's folder? - Now, for A4, right click on
main.cpp, Makefile, README.txt, *.h, *.hpp, *.cpp
to copy the files. Then, return to theSet4/A4
folder and right click to paste the files. In other words, put a copy of your homework'smain.cpp, Makefile, README.txt, *.h, *.hpp, *.cpp
source code into theSet4/A4
folder.
Follow the same steps for each lab to put a copy of each lab's deliverable into theSet4/L4
folders. Do this process forSet4/L4A
(linked_list_functions.cpp
),Set4/L4B
(LinkedList.h, LinkedList.cpp
),Set4/L4C
(Node.hpp, LinkedList.hpp, main.cpp, Makefile
).
STOP: Are you sure yourSet4
folder now has all your code to submit?
The structure of the submission is as follows:- Set4/
- A4/
- main.cpp
- Makefile
- README.txt
- *.h
- *.hpp
- *.cpp
- L4A/
- linked_list_functions.cpp
- L4B/
- LinkedList.h
- LinkedList.cpp
- L4C/
- Node.hpp
- LinkedList.hpp
- main.cpp
- Makefile
- A4/
- Set4/
- Now, right-click on the
"Set4"
folder.- In the pop-up menu that opens, move the mouse
"Send to..."
and expand the sub-menu. - In the sub-menu that opens, select
"Compressed (zipped) folder"
.
STOP: Are you really sure you are zipping aSet4
folder with sub-folders that each contain amain.cpp
file in it?
- In the pop-up menu that opens, move the mouse
- After the previous step, you should now see a
"Set4.zip"
file.
- Now visit the Canvas page for this course
and click the
"Assignments"
button in the sidebar.
- Find Set4, click on it, find the
"Submit Assignment"
area, and then click the"Choose File"
button.
- Find the
"Set4.zip"
file created earlier and click the"Open"
button.
STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?
- WAIT! There's one more super-important step. Click on the blue
"Submit Assignment"
button to submit your homework.
- No, really, make sure you click the
"Submit Assignment"
button to actually submit your homework. Clicking the"Choose File"
button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!
- Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set4"
folder
and only the "Set4"
folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment"
button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy.
→This assignment is due by Tuesday, November 01, 2022, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B,
L4C
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←