Maze Solving Robots

Maze Solving Robots
By Edmund G
Stateless Algorithms
These Algorithms do not record where they have been but only think
about where to go.
Some examples of these algorithms I look at here are:
Random mouse algorithm
Pledges Algorithm
Wall-Follower Algorithm
2
Algorithm (in pseudocode)
while “in maze”
if you can go forward
go forward
add “forward” to list
if you can turn right
go right
add “right” to list
if you can turn left
go left
add “left” to list
if you cannot go forward or turn
turn back
add “back” to list
This is a decent
example of the
“Random Mouse
Algorithm”
note: in this configuration it can get stuck in loops
3
Code (in python) based on algorithm
def main(past_moves): #First try to go forwards
maze = raw_input("Are you still in the maze y/n: ").lower()
while maze == "y":
print(past_moves)
forward = raw_input("can you go forward y/n: ").lower()
if forward == "y":
print("you go forward")
past_moves.append("forward")
main(past_moves)
else:
right = raw_input("can you go right y/n: ").lower()
if right == "y":
print("you go right")
past_moves.append("right")
main(past_moves)
else:
left = raw_input("can you go left y/n: ").lower()
if left == "y":
print("you go left")
past_moves.append("left")
main(past_moves)
else:
go_back(past_moves)
print("you go backwards")
past_moves.append("backwards")
main(past_moves)
past_moves = []
main(past_moves)
4
Algorithm (in pseudocode)
while “in maze”
if you can you turn right
rotate 90 right
if you can go forward
go forward
else
rotate 90 left
This is a good example of the
“Wall-follower (Right)” algorithm
5
Code (in python) based on algorithm
def main(past_moves):
maze = raw_input("Are you still in the maze y/n: ").lower()
while maze == "y":
print(past_moves)
check1 = raw_input("can you turn right y/n: ").lower()
if check1 == "y":
print("you rotate 90 degrees right")
past_moves.append("rotate 90 degrees right ")
main(past_moves)
else:
check2 = raw_input("can you go forward y/n: ").lower()
if check2 == "y":
print("you go forward")
past_moves.append("forward")
main(past_moves)
else:
print("you rotate 90 degrees left")
past_moves.append("rotate 90 degrees left")
main(past_moves)
past_moves = []
main(past_moves)
6
Algorithm (in pseudocode)
while “in maze”
counter = 1
while counter != 0
counter = 0
if you can go forward
go forward
if you can turn right
counter += 90
you turn right
if you can turn left
counter -= 90
you turn left
else
go back
This is a good example of
of Pledges Algorithm
7
Code (in python) based on algorithm
def main(past_move):
maze = raw_input("Are you still in the maze y/n: ").lower()
while maze == "y":
counter = 1
print(counter)
while counter != 0:
print(counter)
forward = raw_input("can you go forward y/n: ").lower()
if forward == "y":
print("you go forward")
past_move.append("forward")
else:
right = raw_input("can you go right y/n: ").lower()
iif right == "y":
print("you turn right")
past_move.append("right")
counter += 89
print(counter)
else:
left = raw_input("can you go left y/n:
if left == "y":
print("you turn left")
past_move.append("left")
counter -= 91
print(counter)
else:
print("you turn back")
past_move.append("go back")
past_move = []
main(past_move)
").lower()
8
Stateful Algorithms
These Algorithms not only think about where to go but where they’ve
been in order to prevent looping etc.
Some examples of these algorithms are:
Tremaux's Algorithm
(Dead End Filling)
9
Algorithm (in pseudocode)
while “in maze”
if there is a junction
if there is an unmarked path
goto subalg
else
turn back
mark path
else
goto subalg
steps += 1
function subalg()
if you can go forward
go forward
add “forward” to list
if you can turn right
go right
add “right” to list
if you can turn left
go left
add “left” to list
if you cannot go forward or turn
turn back
add “back” to list
This is a good example of
Tremaux’s Algorithm
10
Code (in python) based on algorithm
def main(past_moves, steps):
maze = raw_input("Are you still in the maze y/n: ").lower()
while maze == "y":
print(past_moves)
junction = raw_input("Is there a junction y/n: ").lower()
if junction == "y":
path = raw_input("Is the path marked y/n: ").lower()
if path == "n":
sub_alg(steps)
else:
print("you go backwards")
else:
sub_alg(steps)
steps += 1
def sub_alg(steps):
print(past_moves)
forward = raw_input("can you go forward y/n: ").lower()
if forward == "y":
print("you go forward")
past_moves.append("forward")
main(past_moves, steps)
else:
right = raw_input("can you go right y/n: ").lower()
if right == "y":
print("you turn right")
past_moves.append("right")
main(past_moves, steps)
else:
left = raw_input("can you go left y/n: ").lower()
if left == "y":
print("you turn left")
past_moves.append("left")
main(past_moves, steps)
else:
go_back(past_moves)
print("you go backwards")
past_moves.append("backwards")
main(past_moves, steps)
steps = 0
past_moves = []
main(past_moves, steps)
11
Acknowledgments
-Wikipedia, a source for the name’s of
algorithm’s
and
-Codio, a stable cloud computing platform that
allowed for a well organised and tested project
12