CS312 Project 5: Hunt the Wumpus
Due at the start of the final exam
The game "Hunt the Wumpus" consists of a series of caves, which may contain bottomless pits, a wumpus, or bats. Run the command "wump" on isoptera, or any other Linux with the package bsdgames installed, and learn how to play the game. For this assignment, assume the default parameters.
In order to play the game, you will need to be able to communicate with it. A framework will be provided to give input to the game, and receive output, by using pipes and executing the game as a child process. However, you will have to parse the results. Represent each room with an object, which will need to have at least the following properties (pick an appropriate data type for each):
- Breeze. Indicates whether or not there is a breeze in the room.
- Rustle. Indicates whether or not there are bats in the room.
- Stench. Indicates whether or not there is a stench in the room.
- Connections from the room. There will be three connections.
Given these, it is possible to calculate the safety of an unexplored room. Specifically, if a room that you have not yet visited adjoins a room with a pit or a stench, it is more dangerous. Create functions (which can be methods) which will figure out the approximate probabilities of two things:
- Probability of a pit. This is increased by having adjoining rooms with a breeze. However, if any rooms have a connection to the room under consideration and do not have a breeze, than this probability is 0.
- Probability of a wumpus. The wumpus stench extends for two rooms around the wumpus. So adjoining rooms with a stench increase this probability, but so do stinky rooms that adjoin rooms that adjoin the current room. If a room has a connection to the room in question but not a stench, or if a non-stinky room connects to a room that connects to the room in question, than this probability is 0.
When a room has a very high probability of holding a wumpus, it may be worth one of your 5 arrows. But, be careful about running out of arrows, because you cannot win the game if you shoot all 5. You may want an increase threshold of wumpus probability before expending the last arrow.
The main loop will look something like this:
while the game is still going:
Retrieve and parse output from the last move
For each room you can move to:
if the probability the room holds a wumpus is high enough:
Shoot into the room
Find the safest choice of the three rooms you can go to, and move there
I recommend holding rooms in some sort of container. Since they are numbered, you could use something as simple as an array on the stack that holds 20 room objects. Connections can be represented however you like (room number, a pointer to a room, etc). The probability functions could be methods of the room class, where you call the method on an unexplored room. Remember, the connections are not always bidirectional, so you do have to search for rooms that connect to the current room. Just checking outgoing connections from the current room is not adequate.
There is a mismatch between the game description and the arrow behaviour. An arrow will only hit a wumpus in the final room on the arrow's path. This makes the game somewhat more difficult. Note that since it contradicts the game description, it is possible this is a bug that will be fixed at some point, however I do not think the wumpus game is under active development. My AI class confirmed the bug about 4 years ago.
Running Wumpus
A demo is posted as run_wumpus.cpp in the class examples area. This contains two class definitions, WumpusGame and NetworkWumpusGame. For a WumpusGame, you must have wump installed on your computer somewhere on the path. This is easy on most Linux distributions, where you install the bsdgames package, and wump is also on isoptera. If your distribution does not have that package, you can probably copy the binary from /usr/games/wump on isoptera. However, if you are on a different operating system and installing wump is a hassle, you can create a NetworkWumpusGame instead, which will use the wumpus server on isoptera. It does require network access.