Skip to content

Instantly share code, notes, and snippets.

@nonZero
Created October 28, 2013 14:44
Show Gist options
  • Save nonZero/7197934 to your computer and use it in GitHub Desktop.
Save nonZero/7197934 to your computer and use it in GitHub Desktop.
MAZE (can you spot the bug?)
MAZE_DRAWING = """
###################################
###################################
###########################
## ######## #######
## ########### ############ #######
## ########### ############ #######
## ########### #######
###########################
###################################
###################################
###################################
###################################
""".strip().splitlines()
MAZE = [[c == " " for c in row] for row in MAZE_DRAWING]
# print MAZE
def where_can_i_go(maze, x, y):
""" returns a tuple of bolleans (north, east, south, west) """
return (
y > 0 and maze[y - 1][x],
x < len(maze[0]) - 1 and maze[y][x + 1],
y < len(maze) - 1 and maze[y + 1][x],
x > 0 and maze[y][x - 1]
)
def main(maze):
x = 0
y = 0
while not maze[y][x]:
y += 1
while True:
print "Where would you like to go today: ",
n, e, s, w = where_can_i_go(maze, x, y)
if n:
print "North",
if e:
print "East",
if s:
print "South",
if w:
print "West",
print "?"
direction = raw_input()
if direction == "n":
y -= 1
if direction == "s":
y += 1
if direction == "w":
x -= 1
if direction == "e":
x += 1
if x == len(maze[0]):
print "KOL HAKAVOD!"
break
main(MAZE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment