Prog 5: Wumpus
11/10 Details (shown in blue) added to give the order of handling events, to help you have your output match mine.
11/13 Assessments added, and described and highlighted near the bottom of this page. Extra Credit project added to Codio.
11/16 Description changed (shown below in highlighted green) to show that Wumpus always moves when an arrow is shot, regardless whether Wumpus is in an odd-numbered room or not. Input used for each assessment added to the table listed all the assessments.
Welcome to Hunt the Wumpus, a classic game by Gregory Yob from 1972.
(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 this diagram:
Running the program looks like:
You are in room 13. You smell a stench. 1. Enter your move (or 'D' for directions): d ______18______ / | \ / _9__ \ / / \ \ / / \ \ 17 8 10 19 | \ / \ / \ / | | \ / \ / \ / | | 7 1---2 11 | | | / \ | | | 6----5 3---12 | | | \ / | | | \ 4 / | | \ | / | \ 15---14---13 / \ / \ / \ / \ / 16---------------20 Hunt the Wumpus: The Wumpus lives in a completely dark cave of 20 rooms. Each room has 3 tunnels leading to other rooms. Hazards: 1. Two rooms have bottomless pits in them. If you go there you fall and die. 2. Two other rooms have super-bats. If you go there, the bats grab you and fly you to some random room, which could be troublesome. Then those bats go to a new room different from where they came from and from the other bats. 3. The Wumpus is not bothered by the pits or bats, as he has sucker feet and is too heavy for bats to lift. Usually he is asleep. Two things wake him up: Anytime you shoot an arrow, or you entering his room. The Wumpus will move into the lowest-numbered adjacent room anytime you shoot an arrow. When you move into the Wumpus' room, then he wakes and moves if he is in an odd-numbered room, but stays still otherwise. After that, if he is in your room, he snaps your neck and you die!
Moves: On each move you can do the following, where input can be upper or lower-case: 1. Move into an adjacent room. To move enter 'M' followed by a space and then a room number. 2. Shoot your guided arrow through a list of up to three adjacent rooms, which you specify. Your arrow ends up in the final room. To shoot enter 'S' followed by the number of rooms (1..3), and then the list of the desired number (up to 3) of adjacent room numbers, separated by spaces. If an arrow can't go a direction because there is no connecting tunnel, it ricochets and moves to the lowest-numbered adjacent room and continues doing this until it has traveled the designated number of rooms. If the arrow hits the Wumpus, you win! If the arrow hits you, you lose. You automatically pick up the arrow if you go through a room with the arrow in it. 3. Enter 'R' to reset the person and hazard locations, useful for testing. 4. Enter 'C' to cheat and display current board positions. 5. Enter 'D' to display this set of instructions. 6. Enter 'P' to print the maze room layout. 7. Enter 'X' to exit the game. Good luck! You are in room 13. You smell a stench. 1. Enter your move (or 'D' for directions): P ______18______ / | \ / _9__ \ / / \ \ / / \ \ 17 8 10 19 | \ / \ / \ / | | \ / \ / \ / | | 7 1---2 11 | | | / \ | | | 6----5 3---12 | | | \ / | | | \ 4 / | | \ | / | \ 15---14---13 / \ / \ / \ / \ / 16---------------20 You are in room 13. You smell a stench. 1. Enter your move (or 'D' for directions): m 12 You are in room 12. 2. Enter your move (or 'D' for directions): M 3 You are in room 3. You hear rustling of bat wings. 3. Enter your move (or 'D' for directions): c Cheating! Game elements are in the following rooms: Player Wumpus Bats1 Bats2 Pit1 Pit2 Arrow 3 14 4 7 18 16 -1 You are in room 3. You hear rustling of bat wings. 3. Enter your move (or 'D' for directions): r (Remember arrow value of -1 means it is with the person.) Enter the 7 room locations (1..20) for player, wumpus, bats1, bats2, pit1, pit2, and arrow: 3 14 4 2 18 16 2 You are in room 3. You hear rustling of bat wings. 3. Enter your move (or 'D' for directions): s Sorry, you can't shoot an arrow you don't have. Go find it. You are in room 3. You hear rustling of bat wings. 4. Enter your move (or 'D' for directions): m 2 Woah... you're flying! You've just been transported by bats to room 9 You are in room 9. You feel a draft. 5. Enter your move (or 'D' for directions): m 10 You are in room 10. 6. Enter your move (or 'D' for directions): m 2 Congratulations, you found the arrow and can once again shoot. You are in room 2. You hear rustling of bat wings. 7. Enter your move (or 'D' for directions): s Enter the number of rooms (1..3) into which you want to shoot, followed by the rooms themselves: 3 3 4 14 Wumpus has just been pierced by your deadly arrow! Congratulations on your victory, you awesome hunter you. Exiting Program ...
Implementation Details:
Implement 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. Use the starter code supplied in Codio, which provides you with some of the output you will need, such as functions to display the instructions and display the board.
Implementing the cave system, allowing making moves from room to room. Note you can implement this using arrays, vectors, lists, or whatever way makes sense to you. 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.
Initializing the game to have the Wumpus in some random room, the bottomless pits in two other rooms, and super-bats in two other rooms. These 5 rooms with hazards must all be distinct from one another. Place the person into an initial random room that contains no hazards.
Implement the 'C' option to cheat and display the locations of hazards, the person, and the arrow. This will help you test your program, and will help us test it as well.
Implement the 'R' reset option to set the values of the person, arrow, and all hazards. This will help you test your program, and will help us test it as well.
As you move through the maze, if you enter a room with an arrow you automatically pick it up.
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."
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!
Implement the super-bats dropping you into a random new room, then relocate those bats to some random room different from the person, the other bats, or those bats' original room.
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.
So that your output matches mine, I suggest you handle things in the following order:
When setting random locations for various game components, assign them in the following order:
bats1, bats2, pit1, pit2, Wumpus, person
Each time you choose a random destination for one of the game components, you must ensure that it is not already being used by some other component.
When checking adjacent rooms to display whether or not hazards are present:
Check adjacent rooms in ascending numerical order.
First check for Wumpus, second check for pits, third check for bats, respectively displaying messages when any of these are found.
When moving into a room, check for hazards in the following order:
Check for a pit. If it is there, you die.
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.
Check for bats. If present, they move you to a 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:
When the Wumpus is awakened, 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.
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.
Assessments
The 16 assessments cover all the various output messages and many of the game conditions. Each assessment is worth between 2 to 6 points as follows:
Points Condition
Extra Credit
Up to 6 points of extra credit can only be earned if all other aspects of the game are working and it is turned in on time. Your normal submission should not have the extra-credit portions in it.
Earn extra credit by making ASCII animated splash screens for:
1. The beginning of the game
2. When you kill the Wumpus
3. When you die trying.
To make ASCII animated splash screen print the contents of the screen, then clear the screen (system("clear"); on UNIX, system("cls"); on Windows), then print another slightly different screen, and so on. (See samples of Star Wars, and an amazingly artistic dance, and see this recap of a book on how Victorian stenographers started typewriter art, or this rolling donut). To get extra credit your splash screens must be unequivocally interesting and represent significant effort. Turn in your extra-credit submission using the Codio Prog 5 Hunt the Wumpus Extra Credit project.