In this project, I used a graph to implement the game Hunt the Wumpus with very simple rules. A graph is a non-linear data structure consisting of vertices and edges. I implemented a game in which only a Wumpus and a hunter are in the cave and the hunter has a single arrow to shoot the Wumpus. I reused my LandscapeDisplay, Landscape, and Agent classes from prior projects. Specifically, I stored the vertices in LinkedLists and used Dijkstra's algorithm and a PriorityQueue to find the shortest path between two vertices in the graph. I also added UI elements to allow user control the actions of the player. The final game worked as expected.
Testing the Vertex class:
Ran across the wumpus:
Killed the wumpus:
1) Make the game visually interesting.
I modified my Vertex's draw method to make the game aesthetically appealing.
The green rectangles show the doorways.
2) Have your game generate interesting random graphs so you can replay a different game every time.
Instead of arbitrarily choosing the locations of the hunter and the wumpus, I modified the constructor to allow it to randomly generate the hunter's and the wumpus' initial positions. And I used a while loop to check if the hunter is too close to the wumpus; if so, it relocates the hunter.
As shown below, the initial room where the hunter is and the home of the Wumpus are unpredictable, which makes the game more interesting.
Image ModifiedImage Modified
Additionally, I made the constructor connect the rooms with a 50% chance by adding two if statements inside the double for loops.
I also made sure the hunter could get to the Wumpus by adding another condition in the while loop where the hunter would be located if it is too close to the Wumpus or it cannot get to the Wumpus, given the fact that the cost of getting to an inaccessible room is infinity.
3) Add a replay button that resets the game.
I added another state REPLAY to the PlayState enum.
At the end of the project, I learned about a new data structure—a graph--and set it up by adding UI elements. I practiced implementing Dijkstra's algorithm to calculate shortest paths. Combining different data structures such as LinkedLists, Arrays, ArrayLists, and Priority Queues, I developed more profound understanding of these data structures and their advantages. The game was hard to design at first due to the complicated structures and multiple classes. I was glad to finally figure it out.
I would like to thank Professor Taylor, Professor Maxwell, and Professor Layton for all the help and the amazing semester.