CSCI 200 - Spring 2025
Foundational Programming Concepts & Design

A2 - Hunt the Wumpus

→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:


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:

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:
      1. integer corresponding to world size along X dimension
      2. integer corresponding to world size along Y dimension
      3. pointer to an integer for the generated X coordinate
      4. pointer to an integer for the generated Y coordinate
    • Output: none
    • Description: Generates random values within the ranges [1, X] and [1, Y].

    • Name: check_same_location()
    • Input:
      1. integer corresponding to object one's X coordinate
      2. integer corresponding to object one's Y coordinate
      3. integer corresponding to object two's X coordinate
      4. integer corresponding to object two's Y coordinate
    • Output: boolean
    • Description: Returns true if (X1, Y1) equals (X2, Y2).

    • Name: check_if_neighboring()
    • Input:
      1. integer corresponding to the Hero's X coordinate
      2. integer corresponding to the Hero's Y coordinate
      3. integer corresponding to object's X coordinate
      4. 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: 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 or m for move.

    • Name: hero_shoot()
    • Input:
      1. integer corresponding to Hero's X coordinate
      2. integer corresponding to Hero's Y coordinate
      3. integer corresponding to Wumpus's X coordinate
      4. 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, or W. Returns true if the Wumpus is within 5 units from the Hero's position along the desired direction.

    • Name: move_hero()
    • Input:
      1. integer corresponding to world size along X dimension
      2. integer corresponding to world size along Y dimension
      3. pointer to an integer for Hero's X coordinate
      4. 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, or W. 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: move_object()
    • Input:
      1. integer corresponding to world size along X dimension
      2. integer corresponding to world size along Y dimension
      3. pointer to an integer for object's X coordinate
      4. 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: play_game()
    • Input: none
    • Output: None
    • Description: Simulates the game play as laid out above.


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:

PointsRequirement Description
0.5Submitted correctly by Tuesday, February 11, 2025, 11:59 PM
0.5Project builds without errors nor warnings.
2.0Best Practices and Style Guide followed.
0.5Program follows specified user I/O flow.
0.5Public and private tests successfully passed.
2.0Fully meets specifications.
6.00Total 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.←