Montana Tech of The University of Montana
Computer Science Department

CSCI 135
Fundamentals of Computer Science I
Fall 2020



LAB 8 - Wumpus World: Testing

In the previous lab, you wrote a Fraction class with methods that were to withstand testing. In this assignment, you will write tests to try to break existing code - the inverse of what you did last time. You will use the Wumpus World game that we used to work through analysis and part of the design in class on Monday. In class we also defined some test cases from the description of the problem, and then talked about designing tests from the specified API. Your assignment this week is to implement test code and try to break the code provided to you.

To begin with, download the Wumpus World code from here: WumpusWorld.zip.

Since this code uses pictures and sounds, you will need to run it from a command window.
  Wumpus World

Recall the description of the game from Monday's lecture. This has not changed.


The Game. The Wumpus World game takes place in a cave with different rooms in it. You can think of the cave as an NxM rectangular grid. The player always starts in position 0,0, which is guaranteed to be safe (but it may still be smelly or breezy or glittery).

The objective of the game is to find the gold. The player will know when he/she is in a room with the gold because there will be a "glitter" in that room. If the player detects a glitter, he/she can pick up the gold and the game is won.

Bottomless pits are present in some of the rooms. There is a 20% chance that any given room will have a pit. All rooms adjacent to a pit are breezy, that is, a player entering a room adjacent to a pit will detect a breeze. If the player moves into the room with a pit, he/she falls in and dies a horrible death.

There is only one wumpus in the cave, and he is also placed at random. Rooms adjacent to the wumpus are smelly, that is, a player will detect a stench in a room adjacent to a wumpus. The wumpus cannot move. If the player enters a room with the wumpus, he/she will be eaten, and, once again, die a horrible death.

There is also only one room in the cave that contains the gold. Unlike the other objects, the player has to be in the same room as the gold in order to detect a glitter. Like the wumpus, the gold is placed at random.

The player can move up, down, left, or right, using the 'w', 'a', 's' and 'd' keys. The player also has one arrow. Once it's used up, it's gone. It can be used to shoot a wumpus, and can be shot in any direction the player can move in, using the keys 'i', 'j', 'k' and 'l'. If the player is successful in shooting the wumpus, the wumpus will emit a blood-curdling scream, and will no longer be a threat. The only other action the player can perform is to "grab gold", using the key 'g'.

When the player first starts the game, he/she does not know (and cannot see) where the location of pits, gold and the wumpus are. The only clues are whether the current room is breezy, smelly, or glittery.

The Assignment: The overall assignment is to produce test code for this game. The test code you write should should perform unit testing of all the class methods and any functions in the code. Unit tests for classes are easily included in the file(s) that contain the code you are testing. To get you started, there are some test examples at the bottom of Room.py found in the downloaded zip file. You will want to write additional test cases, based on the discussion in class, and anything that you think would break the code. Remember that a successful test is one that discovers a fault.

One hint is that if you are testing something that will likely fail, you might want to wrap it in a try/except construct so that your test code continues to execute even though the program code would have crashed. An example of this is included in the sample test code in Room.py. You will find it annoying to keep commenting out / uncommenting code otherwise.

Another hint is that if you provide descriptive print statements to describe a test and whether it passed or failed, it will help you know which tests were successful (that is, found a bug).

If you have included the test code at the bottom of the files in the classes, you can simply run that file. For example, try running: python Room.py from the command line to see how the sample tests work. Look at the test code in Room.py. You'll notice that there is a line if __name__ == "__main__": and all the code after that is indented. This keeps that part of the code from interefering with the rest of the program - that is, it will only run if the program is compiled directly. If you don't use that line, the test code may break code in other parts of the program.

For testing the main game loop, you may have to either write a WumpusWorldClient.py, or test manually (yes, that means play the game, try it with different conditions). Either way, be sure to document your results so that the maintainer (me) knows what test you tried and what worked, what didn't.

IMPORTANT!!! At the top of each file you modify, the first few lines, make sure you add your own header with your name and a description of what code you added.


Grading:

Grade Item Wumpus World II Points Earned
Header Comment
2
Tests in Room.py
2
Tests in Cave.py
2
Tests in Player.py
2
Tests of WumpusWorld.py
2
For Every Fault Found:
1, up to 20 total


Submission.
Submit your Python files with test code for Player.py, Cave.py and Room.py to Moodle, under Lab 8. If you wrote code to to test the game loop, WumpusWorldClient.py, submit that also. If you didn't write code, but tested the game manually, submit a list of errors in a header comment in WumpusWorld.py, and submit that file.


Extra Credit.
A couple of ideas for extra credit on this assignment are to add multiple wumpuses (wumpii?) to the game. Or to add "bats" that randomly pick up the wumpus, the player or the gold and move them to random locations. Or, you could allow the wumpus to move also. You can also get extra credit by fixing the faults you find in the code and documenting (in comments) what you did. If you choose to do any of these, submit your regular assignment to the normal Moodle dropbox, but submit your extra credit version, with all necessary files, to the Extra Credit dropbox at the top of the Moodle page. Have fun!!



Page last updated: August 16, 2021