→This assignment is due by Tuesday, February 11, 2025, 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.←
Jump To: Rubric Submission
For this assignment you will recreate a modified version of the game Hunt the Wumpus.
Hunt the Wumpus
In the game, the Hero is trying to hunt the Wumpus in a dark cave and shoot it with one of his arrows. Every turn the Hero and Wumpus move. If the Hero and Wumpus end in the same location, then the Hero gets eaten by the Wumpus and the game ends with the Hero losing. The Hero must shoot the Wumpus with an arrow from a distance. Beware! There are also two Pits hiding in the cave. If the Hero falls into the pit, then the game ends as well. Flying around the cave are two Bats. If the Hero moves into a space with a Bat, then the Bat picks up the Hero to a new random location.
(Note: This is mostly how the game is played. For our purposes the gameplay has been slightly modified and simplified.)
World Representation
Locations
We will not actually represent our full world. We only need to represent each object in our world by its current (x, y)
location. The world will be bound within the ranges of [1, X]
and [1, Y]
. That is, the value of a coordinate
can never be outside this range. The following object's need to have their location's tracked: Hero, Wumpus, two Pits, and two Bats.
Movement
Movement in the world will correspond to the four cardinal directions (North, East, South, West). One unit in any direction will change the corresponding location coordinate by one. For consistency, the world will be oriented to modify positions as follows:
- North -> Y + 1
- South -> Y - 1
- East -> X + 1
- West -> X - 1
Game Play Flow
The execution follows as below.
World Setup
Begin by prompting the user for the size of the world to create. Ensure that each dimension is larger than 5.
Generate a random position for the Hero within the world.
Generate a random position for the Wumpus within the world. Ensure the Wumpus does not start at the same location as the Hero.
Generate a random position for the first Pit within the world. Ensure the Pit does not start at the same location as the Hero.
Generate a random position for the second Pit within the world. Ensure the Pit does not start at the same location as the Hero or the other Pit.
Generate a random position for the first Bat within the world. Ensure the Bat does not start at the same location as the Hero.
Generate a random position for the second Bat within the world. Ensure the Bat does not start at the same location as the Hero or the other Bat.
Game Play
Until the game ends, perform the following steps each turn:
- Print the Hero's current location.
- Check if the Hero and Wumpus are at the same location. If so, the game ends and the Wumpus eats the Hero.
- Check if the Hero and a Pit are at the same location. If so, the game ends and the Hero falls into the Pit.
- Check if the Hero and a Bat are at the same location. If so, the Hero moves to a new random location in the world. (Note: it's possible the Bat moves the Hero onto the Wumpus or a Pit or another Bat. That's ok.)
- Otherwise if Hero is on an empty square
- Check if the Wumpus is next to the Hero. If so, print a message noting a fowl smell coming from nearby.
- Check if a Pit is next to the Hero. If so, print a message noting there's a breeze blowing across the Hero's face.
- (Note: it's possible the Hero is next to multiple other things. If that's the case, print out the appropriate number of statements based on what is nearby.)
- Prompt the user if they wish to shoot an arrow or move to a new square.
- If they wish to shoot, prompt the user which direction they wish to shoot. If the Wumpus is within 5 units along that direction, then the Hero wins and the game ends. Otherwise, print a message nothing the arrow fell to the ground.
- Otherwise if they wish to move, prompt the user which direction they wish to move. Move the Hero. If the Hero moved onto the Wumpus's location, then the gamne ends.
- Move the Wumpus one random direction.
- Move each Bat one random direction.
An example game play demonstrating the different game play scenarios is below:
Enter the world size x (>5): 2
Enter the world size x (>5): 7
Enter the world size y (>5): 5
Enter the world size y (>5): 6
You are at (4, 5)
What do you wish to do - (s)hoot or (m)ove: m
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: S
You are at (4, 6)
What do you wish to do - (s)hoot or (m)ove: m
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: S
You cannot go that way
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: t
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: w
You are at (3, 6)
What do you wish to do - (s)hoot or (m)ove: M
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: n
You are at (3, 5)
You sense a breeze blowing across your face.
What do you wish to do - (s)hoot or (m)ove: e
What do you wish to do - (s)hoot or (m)ove: 3
What do you wish to do - (s)hoot or (m)ove: s
Which direction do you wish to shoot - (E)ast, (S)outh, (W)est, (N)orth: n
Your arrow falls to the ground
You are at (3, 5)
What do you wish to do - (s)hoot or (m)ove: m
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: N
You are at (3, 4)
There's a fowl smell coming from nearby.
What do you wish to do - (s)hoot or (m)ove: m
Which direction do you wish to move - (E)ast, (S)outh, (W)est, (N)orth: N
You are at (3, 3)
A Bat picks you up and flies you to a new location!
You are at (6, 5)
What do you wish to do - (s)hoot or (m)ove: s
Which direction do you wish to shoot - (E)ast, (S)outh, (W)est, (N)orth: w
Game Over - Your arrow hits the wumpus!
Code Structure & Functions
We will want to implement this program in a procedural style using functions. These functions will be declared in a separate
wumpus_functions.h
file with their implementations defined in a corresponding wumpus_functions.cpp
file.
Create, and use, the following functions:
-
- Name:
gen_rand_pos()
- Input:
- integer corresponding to world size along X dimension
- integer corresponding to world size along Y dimension
- pointer to an integer for the generated X coordinate
- pointer to an integer for the generated Y coordinate
- Output: none
- Description: Generates random values within the ranges
[1, X]
and[1, Y]
.
- Name:
-
- Name:
check_same_location()
- Input:
- integer corresponding to object one's X coordinate
- integer corresponding to object one's Y coordinate
- integer corresponding to object two's X coordinate
- integer corresponding to object two's Y coordinate
- Output: boolean
- Description: Returns true if
(X1, Y1)
equals(X2, Y2)
.
- Name:
-
- Name:
check_if_neighboring()
- Input:
- integer corresponding to the Hero's X coordinate
- integer corresponding to the Hero's Y coordinate
- integer corresponding to object's X coordinate
- integer corresponding to object's Y coordinate
- Output: boolean
- Description: Returns true if the object's coordinate is one unit away from the Hero's coordinate along any cardinal direction.
- Name:
-
- Name:
hero_choice()
- Input: none
- Output: character
- Description: Prompts the user to enter if the Hero should shoot an arrow or move. Validates the user input to return only one
value of either
s
for shoot orm
for move.
- Name:
-
- Name:
hero_shoot()
- Input:
- integer corresponding to Hero's X coordinate
- integer corresponding to Hero's Y coordinate
- integer corresponding to Wumpus's X coordinate
- integer corresponding to Wumpus's Y coordinate
- Output: boolean
- Description: Prompts the user to enter which cardinal direction the Hero wishes to shoot. Validates the user input to only allow
one of
N
,E
,S
, orW
. Returns true if the Wumpus is within 5 units from the Hero's position along the desired direction.
- Name:
-
- Name:
move_hero()
- Input:
- integer corresponding to world size along X dimension
- integer corresponding to world size along Y dimension
- pointer to an integer for Hero's X coordinate
- pointer to an integer for Hero's Y coordinate
- Output: None
- Description: Prompts the user to enter which cardinal direction the Hero wishes to shoot. Validates the user input to only allow
one of
N
,E
,S
, orW
. If the user is not next to the edge of the world, then moves the Hero one unit along the desired direction. If user is next to the edge of the world and cannot move that direction, then informs the user to choose a new direction.
- Name:
-
- Name:
move_object()
- Input:
- integer corresponding to world size along X dimension
- integer corresponding to world size along Y dimension
- pointer to an integer for object's X coordinate
- pointer to an integer for object's Y coordinate
- Output: none
- Description: Chooses a random direction for object to move. If object is not next to the edge of the world, then moves the object one unit along the desired direction. If object is next to the edge of the world and cannot move that direction, then chooses a new random direction to attempt to move.
- Name:
-
- Name:
play_game()
- Input: none
- Output: None
- Description: Simulates the game play as laid out above.
- Name:
Requirements
The user will be semi-cooperative. They will enter the type of value the program expects, but may not enter the correct expected value.
The function declaration and definitions must be split into separate files as appropriate.
Mark parameters that do not change in the scope of the function constant as appropriate.
Hints
Implement and test your functions one at a time.
Due to the procedural style, your main.cpp
is nothing more than calling play_game()
.
In fact, it's given to you below!
All the specifics and details are abstracted away. The actual game play consists of creating a few variables and then
calling the functions in the appropriate order
int main() {
play_game();
return 0;
}
Grading Rubric
Your submission will be graded according to the following rubric:
Points | Requirement Description |
0.5 | Submitted correctly by Tuesday, February 11, 2025, 11:59 PM |
0.5 | Project builds without errors nor warnings. |
2.0 | Best Practices and Style Guide followed. |
0.5 | Program follows specified user I/O flow. |
0.5 | Public and private tests successfully passed. |
2.0 | Fully meets specifications. |
6.00 | Total Points |
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.
Zip together your main.cpp, wumpus_functions.h, wumpus_functions.cpp, Makefile
files and name the zip file A2.zip
. Upload this zip file to Canvas under A2.
→This assignment is due by Tuesday, February 11, 2025, 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.←