The Logic Behind Crabbot

Crabbot's misson is to collect the gold without being eaten by a wumpus or falling into a pit and only has knowlege of these dangers via clues that he is given along the way. Thus, out robot’s logic is based on deduction. We created two structs to store a position (and the direction the wumpus is facing) on the 4x4 grid, as well as a square on the board that will hold integers representing the presence of a pit, wumpus, gold, breeze, glitter, stench, whether it has been visited, and whether or not it is safe. When a pit is set to 0, it means there is no pit in that spot, a 1 means it could be there. Wumpuses and gold are all set to 0 initially, and updated to -1 to signal that it is absolutely not there or 1 if it could possibly be there. Throughout the running of our program, we will always keep track of the robot’s current position, a path of positions it has traveled (so we can safely get back home), the length of this path, and the board (a 4x4 array of squares to keep track of what we know is in each spot).

When we first start up the program, we create variables to keep track of some important pieces of information, including whether or not we have found the gold, found the wumpus, saw glitter, saw the wumpus, whether the wumpus is gone, whether we have the have gold, and whether we have visited the home square. We place our robot in the bottom left corner facing upwards. We marked every square on the board as not having a wumpus, gold, not safe, and not visited, while marking every square true for pit. We then marked the home square as safe without a pit. Now we are ready to start the robot’s “thinking” process.

While we do not have the gold, we will go through the following steps:

1. Get the current square the robot is on. If we have not yet visited this square :

a. Get IR signal using the remote

b. Mark current spot as visited on the board array

c. Update board:

§ Add stenches, breezes, and glitters as appropriate, and update the saw_glitter and saw_wumpus variables if needed

§ If we smell a stench, as long as the surrounding spots are not -1 for wumpus, update wumpus variable to 1 in those spots

§ If we see a glitter, as long as the surrounding spots are not -1 for gold, update gold variable to 1 in those spots

§ If we smell a stench for the second time, we know where the wumpus is (since there is only one of them) – we face it and shoot it

§ If no stench, remove wupuses from all surround squares by setting the wumpus variable to -1

§ If we see a glitter a second time, we know where the gold is (since there is only one of them) – we face gold and go get it, then return home

§ If there is no glitter, mark surrounding squares as -1 for gold

§ If there is no breeze, clear pits (set them to 0) surrounding current position

§ If the current square has only a glitter or nothing – mark all surrounding spots as safe

§ If there is only a glitter – gold has to be in one of the surrounding squares, so check all four for the gold if they have not yet been visited. Once it has been found, return home

§ If at gold, return home by following the path array

2. If the wumpus is still on the board, check to see if we know where it is – we will only know where it is if there is only one square that has wumpus = 1

a. If we can face the wumpus, face it and shoot it

3. “Deduce world” by doing the following:

a. Check for one wumpus on the board – if there is one, we have found it

b. Check for one gold on the board – if there is one, we have found it

c. Mark safe spots. A spot is considered safe if pit = 0 and wumpus = -1 on that square

d. If we found gold, mark gold spot as safe, the pit as 0, and the wumpus as -1

e. If we found wumpus, mark that spot with pit = 0

4. Try movement

a. Only move into a safe square and one that that we have not already visited

b. First attempt up, then right, then down, then left

§ If any of those moves were successful, add the current spot to the path array, increase the path length, and them physically move to the next square

c. If no movement is possible, go back to last square by looking at the last spot on path array and then going there after reducing the length by one

5. Repeat steps 1-4 as long as needed

a. If we get back home and we have already been there before (gone all around the board without finding gold) and we found the wumpus and its not dead yet, clear the board of all visited spots and try again – we now know where the wumpus is, so we can kill it and hopefully clear a path to the gold