Skip to content

Instantly share code, notes, and snippets.

@zapakh
Created May 22, 2024 07:44
Show Gist options
  • Select an option

  • Save zapakh/bd3901660e1b5ab95328a640d75cb453 to your computer and use it in GitHub Desktop.

Select an option

Save zapakh/bd3901660e1b5ab95328a640d75cb453 to your computer and use it in GitHub Desktop.
# Solve an acyclic maze by hugging the wall.
# You will need some Fertilizer to start.
def do_right_hand_maze():
harvest()
plant(Entities.Bush)
while get_entity_type() == Entities.Bush:
use_item(Items.Fertilizer)
heading = North
while get_entity_type() != Entities.Treasure:
right = right_from(heading)
if move(right):
heading = right
elif not move(heading):
heading = left_from(heading)
harvest()
def right_from(dir):
dirs = [North, East, South, West, North]
return find_next(dirs, dir)
def left_from(dir):
dirs = [North, West, South, East, North]
return find_next(dirs, dir)
def find_next(list, elem):
for i in range(len(list)-1):
if list[i] == elem:
return list[i+1]
return None
do_right_hand_maze()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment