Prog 2: Wumpus Arrows
(bats, arrow, and all arrays are dynamic)

Description


Welcome (again) to
Hunt the Wumpus, a classic text-based adventure game by Gregory Yob from 1972. This is very similar to the first program, except now we are adding superbats and an arrow that can be used to shoot the Wumpus. All arrays must be allocated dynamically, to give us practice in doing that.


Your program must be turned in using Gradescope, where both the test cases and programming style points will be assessed.


(See a copy of his original write-up, and the Wikipedia page. Play a text-based copy on-line. See what one version of this program looked like in BASIC.)


The Wumpus lives in a completely dark cave of 20 rooms. Each room has 3 tunnels leading to other rooms, as indicated in the diagram shown at right:

Running the program looks like the following (Updated as of 9/14), further comment 10/4:

Implementation Details:

The game using the following steps and requirements. User input should be accepted as either upper or lower-case. I suggest that within your program you convert user input to upper-case, to make coding easier.

  1. Implementing the cave system, allowing making moves from room to room. The room connections must be read from a file and stored in the program using a dynamically allocated array. No points will be awarded for this program unless you can at least make moves throughout all the rooms. Attempting to move to an invalid room gives an error message and allows the user to retry.

  2. Initializing the game to have: person, Wumpus, pit1, pit2, bat1, bat2, arrow all in distinct random rooms, where they are allocated in that order. In other words, these 7 rooms with game components must all be distinct from one another, and the person is in an initial random room that contains no hazards.

  3. Implement the 'C' option to cheat and display the locations (in order) of:
    person, Wumpus, pit1, pit2, bat1, bat2, arrow
    This will help you test your program, and will help us test it as well. An arrow value of -1 means the arrow is with the person.

  4. Implement the 'R' reset option to set the values (in order) of:
    person, Wumpus, pit1, pit2, bat1, bat2, arrow
    This will help you test your program, and will help us test it as well.

  5. As you move through the maze, if you enter a room with an arrow you automatically pick it up.

  6. As you enter each room indicate what is present:

      • If this room is next to the Wumpus room, give the message: "You smell a stench."

      • If this room is next to a room with a pit, give the message: "You feel a draft."

      • If this room is next to a room with bats, give the message: "You hear rustling of bat wings."

  7. When you enter a room with the Wumpus in it, if that room is odd-numbered then the Wumpus will move to the lowest-numbered adjacent room. Else it will snap your neck and the game is over!

  8. When the person enters a room with super-bats, the super-bats pick up the person and drop the person into a random new room, and then the super-bats fly to some random room different from the person, the other bats, or those bats' original room.

  9. Implementing the 'S' option for shooting the guided arrow 1 to 3 rooms. Your first input is the number of rooms, followed by the rooms themselves. If a room number is not adjacent to the current arrow location, then the arrow will ricochet to the lowest-numbered adjacent room. Remember that anytime you shoot an arrow, the Wumpus will move to the lowest-numbered adjacent room, regardless of what sort of room the Wumpus is currently in.

Below is a list of the various program messages that should appear, and the conditions under which they appear. You need to know these and copy them exactly as shown so that your output matches the expected output. The ones highlighted in red have to do with hazards (bats, pits, Wumpus). Those in yellow have to do with the arrow. Those in green have to do with displaying cheats and resetting hazard values, to help in testing.


Prog 1 Wumpus Messages

When your program starts you should use malloc to allocate space for the rooms array. Then you should hard-code the instructions to initialize the values of the connections in the rooms array.

So that your output matches the expected output, your program must handle things in the following order. Double-check your program, since the order of checking has changed from the first version!

  • When setting random locations for various game components, assign them in the following order: person, Wumpus, pit1, pit2, bat1, bat2, arrow

  • Each time you choose a random destination for one of the game components when initializing at the beginning of the game, you must ensure that it is not already being used by some other component. If it is, then generate a new random room to try.

  • When checking adjacent rooms to display whether or not hazards are present, check adjacent rooms in ascending numerical order.

      1. First check for Wumpus

      2. Second check for pits

      3. Third check for bats

Respectively display messages when any of these are found. Having this explicit order is necessary so your output matches the expected output when multiple conditions are present.

  • When moving into a room, check for hazards in the following order:

  1. Check for the Wumpus. If it is there, and the room is odd-numbered, then the Wumpus moves to the lowest-numbered adjoining room, else the Wumpus kills the player.

  2. Check for a pit. If it is there, you die.

  3. Check for bats. If present, they move you to a random new room.

    • This version of the game makes some non-random decisions, to help with testing the program. If you want to make a version playable by your friends (which you don't turn in!), then make the following changes:

        1. When the Wumpus is awakened, currently if it is in an odd-numbered room currently the Wumpus moves to its lowest-numbered neighbor.
          Change this so that when the Wumpus is awakened, it moves to a randomly-selected adjacent room 75% of the time, and stays where it is (and kills the player) 25% of the time.

        2. Arrows that ricochet currently move to a room's lowest-numbered adjacent room.
          Change this so that when the arrow ricochets, it moves to a randomly selected adjacent room.

Test Cases
The following sixteen test cases cover various output messages and many of the game conditions. Each test case is worth between 2 to 6 points as follows:
[New order of room numbers has been updated in test cases below as of 9/14.]

Prog 1 Wumpus Messages