Homework 1, Beetle .
Short Description:
Write a program that simulates players playing the game of Beetle
Goals
When you finish this homework, you should have:- Written a object-oriented C++ program that simulates the game of Beetle.
Formal Description
The game Beetle is a parlor game which has been turned into the commercial game Cootie. For this homework you should implement an object-oriented version of Beetle.Game Rules
Please note, I am using the Wikipedia page for these rules. You can find other versions in other places. The version described on this page is the version you should be implementing.Beetle is played using a single die. On their turn a player repeatedly rolls the die, and collects a piece of a beetle if they can. When a player rolls a piece that they do not have the pre-requisite for, or have reached the limit of, their turn is over.
The goal is to be the first player to assemble a complete beetle.
For this game:
| Roll | Item | Limit | Rule |
|---|---|---|---|
| 1 | Eye | 2 | Must have a head. |
| 2 | Antenna | 2 | Must have a head. |
| 3 | Leg | 6 | Must have a body. |
| 4 | Wing | 2 | Must have a body. |
| 5 | Head | 1 | Must have a body. |
| 6 | Body | 1 | Must be the first part obtained. |
- A player must roll a 6 to start assembling a beetle.
- After this a player succeeds on a roll of 3-5 until they reach the limit of each of those parts.
- After a player rolls a 5, they also succeed on a roll of 1-2 until they reach the limit of each of those parts.
Example
The first player rolls a 2, but they don't have a head so their turn ends.The second player rolls a 6, and obtains a body, they then roll a 2, but they need a head for an antenna, so their turn ends.
The third player rolls a 6, and obtains a body, they then roll a 5 and obtain a head. On the next roll they roll another 6, but they have exceeded their body limit, so the turn ends.
At the end of the first round, the first player has no items, the second player has a body and the third player has a body and a head.
Implementation Details
Your game should start by asking for the number of players, 2-4. After this it should simulate a game of beetle for those players.At the beginning of each round, you should print information about the state of each player. (See the example below)
As the round progresses, you should print detailed information about what is happening (See the example below)
The winner is the first player to complete a beetle, and the game ends instantly when this occurs.
Example output
Your output should follow this example fairly closely
Please enter the number of players (2-4) => 1
I'm sorry, you should have between 2 and 4 players.
Please enter the number of players (2-4) => 3
We will be playing with 3 players.
Round 1:
Player 1: Body 0, Head 0, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
Player 2: Body 0, Head 0, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
Player 3: Body 0, Head 0, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
Player 1 rolls a 2: antenna, but they don't have a head so the turn ends.
Player 2 rolls a 6: body, a body is added.
Player 2 rolls a 2: antenna, but they don't have a head so the turn ends.
Player 3 rolls a 6: body, a body is added.
Player 3 rolls a 5: head, a head is added.
Player 3 rolls a 6: body, but don't need another body so the turn ends.
Round 2:
Player 1: Body 0, Head 0, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
Player 2: Body 1, Head 0, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
Player 3: Body 1, Head 1, Wings: 0, Legs: 0, Antenna: 0 Eyes: 0
...
Round 7:
Player 1: Body 1, Head 1, Wings: 1, Legs: 6, Antenna: 2 Eyes: 2
Player 2: Body 1, Head 1, Wings: 1, Legs: 6, Antenna: 2 Eyes: 2
Player 3: Body 1, Head 1, Wings: 2, Legs: 4, Antenna: 2 Eyes: 2
Player 1 rolls a 1: wing, a wing is added.
Player 1 completes their beetle, they win.
Further details
- Please assume that each player has their own independent die. You must use the die class developed in the lectures for this item.
- You should have at least two additional objects, correctly implemented in this program. They should each be in a separate header and implementation file.
- If you employ AI to solve this problem, you must include this information at the top of your main program file. Please include the way you used AI and the percent of the project accomplished by AI.
- If you work with others to solve this problem, you must include this information (names of others) at the top of your main program file.
- Your program must compile without errors or warnings on prog1.
- Your program must compile without errors or warnings with the following flags -Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2.
- You may want the following in your make file
CXX = g++-14 CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2
Attribute
I used ChatGPT to review the assignment. It definitely cleaned up the problem, but I deliberately did not remove some of the ambiguity from my original statement. If you have a question about the assignment, and you probably should, you should ask in class well before the assignment is due.ChatGPT said:
One thing I would not changeI like your choice of Beetle.
It is actually a pretty good first object-oriented programming problem because the domain naturally contains objects and relationships:
Game →Players → Beetles → Parts
and it has enough state and rules to prevent students from writing a trivial "class with three getters and setters" exercise.
The biggest opportunity is to make the object responsibilities more explicit. Right now the assignment tells them what the program must do very well, but gives them somewhat less guidance about what should belong in which object. ...
Required Files
You should submit a single tar or zip file containing all files required to build your project. This includes- Source code files (.cpp and .h)
- A Makefile that will build the program by typing
make.