top of page

THE CODE

Understanding the algorithm

  1. The robot sees the grid/Wampus World like a Cartesian coordinate system, with the top left being (0, 0) and the starting position of the robot always being (0, 3).

  2. One by one, the robot drives to squares it knows through logic are 100% safe. Since all Wampus world grids are solveable, Scrappy is always able to find a path to the gold and back

  3. Here is the step-by-step algorithm of our code:

  4. 1) Console input: The users inputs a number from 0 to 1+2+8 = 11 that conveys the contents of the squares that Scrappy is adjacent to. Per the rules, adjacent squares are any squares to the north, west, south, or east directions, given that the squares are 1 of the 16 in the grid.

  5. 1 = Breeze (Scrappy is adjacent to a square with a hole); 2 = Stench (Scrappy is adjacent to a square with the Wampus; 4 = Glimmer (Scrappy is adjacent to a square with the Gold); 8 Scrappy is on the Square with the Gold. Using this number system, Scrappy can decipher the if they are adjacent to a hole, the Wampus, or the Gold, but does not know their exact locations.

Understanding the Algothrim: Text
Image by Michu Đăng Quang

UNDERSTANDING WALLY

Scrappy goes through this cycle of 1) console input/processing, 2) BFS pathfinding, and 3) moving until it can logically determine the gold's location. In general, this happens one of two ways. First, the robot could receive the input for a glimmer and nothing else when entering a new square. This means that all adjacent squares are safe (no holes nor the Wampus), only the possibility of gold. This means that Scrappy can leisurely move to all adjacent squares until he receives the notification that he is on the gold square since there is no danger at all. This, while easier, is a lot less common. The second and more conventional method is to find multiple glimmer notifications and move to the safe, adjacent squares where those notifications intersect. This takes longer and usually requires a greater understanding of the other obstacles on the board.

The logic above can also be somewhat applied to the Wampus. Instead of finding the gold square, though, determining the location of the Wampus allows Scrappy to shoot it, freeing up another safe square for Scrappy to move to and receive new notifications from.

This is just a brief summary of the code behind Scrappy. There are many more test cases that would require further detail.

Understanding the Algothrim: Welcome
bottom of page