One of the first computer games in the 1970's was an adventure game called "Hunt the Wumpus". In this game, you are forced to wander around a maze of caves, hunting the dreaded wumpus (or possible more than one wumpi). You are armed only with hand grenades, which you can throw at a wumpus to kill it. The problem is that wumpi are both fierce and fast. If you ever wander into a cave that contains a wumpus, then that wumpus will attack and kill you before you even have a chance to throw a grenade. Your only hope is to throw the grenade into the cave from an adjacent cave. Fortunately, wumpi are rather odorous creatures, so you will be able to smell a wumpus when you are in an adjacent cave. Of course, you won't know which cave the wumpus is in (every cave is connected to three other caves), so you will have to guess when you throw your grenade.
The object of the game is to kill all of the wumpi before you run out of grenades (and without getting killed). As if this weren't hard enough, you don't know exactly how many wumpi there are, or how many grenades you have (you will have 4 grenades for every wumpus). Plus, there are other things to watch out for. Somewhere in the maze is a group of giant bats, which will pick you up and fly you to some random cave (but at least they will only drop you in an empty cave). There is also a bottomless pit that you must avoid. Luckily, there is some warning about these hazards: you will be able to hear the flapping wings of the bats and feel a draft coming from the pit when you are in an adjacent cave. Oh, and there are the Lost Caverns of the Wyrm, which are very difficult to get out of. Below is a sample execution of the game.
Note: This game in no way intends to promote or condone violence. If you object to the violent nature of this game, alter the rules accordingly. Perhaps a wumpus is a poor soul who has been placed under a spell, and instead of grenades you are tossing bottles of potion that release the person from that spell. Use your imagination.
PART 1: In order to write a program for playing Hunt the Wumpus, you will first need to complete the implementation of the Maze class (partially defined in the Wumpus code directory). This class stores all of the information about a maze of caves, as well as state information about the game (location of the player and wumpi, number of grenades left, etc.). It also provides member functions needed in order to write a game playing program.
Your program should assume the existence of a data file called "caves.dat", which stores the configuration of the cave maze. The first line of this file should specify the number of caves in the maze, and then each subsequent line will contain the following information:
However, it should be possible to customize the game simply by replacing this file with a different cave configuration. The data structure used to store the maze information is a vector of structs, with each struct containing the name of the cave, the numbers of adjacent caves, the contents of the cave (e.g., wumpus, bats, ...), and whether or not that cave has been previously visited. The constructor for the Maze class, which is provided for you, reads in the information from the "caves.dat" file and initializes the vector. In addition, the constructor determines how many wumpi there are going to be (a random number between 1 and the number of caves divided by four), initializes the number of grenades (four grenades per wumpus), and randomly places the wumpi, bats and pit in the maze.
Complete the definition of the Maze class by implementing the following member functions:
You should write a driver program to test your code. For easier testing, consider modifying the constructor temporarily so that you know exactly where things are. As always, interleave the coding and testing phases -- test each function independently as you complete it.
PART 2: Using your Maze class, write a program that allows the user to play Hunt the Wumpus. You may find that your program will be quite short, since most of the work is done in the Maze member functions .
When grading this program, special attention will be paid to style and robustness. As always, your program should be modular and should follow good commenting, indentation, and naming conventions. Robustness refers to your program's ability to behave correctly in all cases, even those that may be unexpected or rare. As you test your program, you should be very careful to think about any such cases that might arise, and test for them. For example, a wumpus that is startled by a nearby explosion is supposed to run to an adjacent empty cave. What if there are no empty caves adjacent to a wumpus? Although this is unlikely, especially with a small number of wumpi, it is possible. In such a case, the wumpus should stay where it is. Special cases such as these may affect your design of the wumpus program, and may force some modifications to code in the Maze member functions.