Maze Code: Left-Wall Follower

A first maze has no loops. Keep your left hand on the wall and you will pass every corridor, including the treasure.

Maze rules that break most scripts

  • Stand on a bush and call `use_item(Items.Weird_Substance, n)` to grow an n×n hedge maze. Fertilizer on plants is how you get Weird Substance.
  • `harvest()` on the treasure gives gold equal to the maze area (5×5 → 25). Harvest anything else and the whole maze vanishes.
  • `get_entity_type()` is `Entities.Treasure` on the chest and `Entities.Hedge` on walls you cannot fly over.
  • `move()` returns False when a wall blocks you. `can_move(direction)` checks without moving. `measure()` anywhere in the maze returns the treasure coordinates.

Spawn a maze, then walk the left wall

python
def spawn_maze():
    if get_ground_type() != Grounds.Soil:
        till()
    harvest()
    plant(Entities.Bush)
    size = get_world_size()
    use_item(Items.Weird_Substance, size)

def solve_maze():
    dirs = [North, East, South, West]
    facing = 0
    while get_entity_type() != Entities.Treasure:
        left = (facing - 1) % 4
        if can_move(dirs[left]):
            facing = left
            move(dirs[facing])
        elif can_move(dirs[facing]):
            move(dirs[facing])
        else:
            facing = (facing + 1) % 4
    harvest()

clear()
while True:
    spawn_maze()
    solve_maze()

After the first maze

Reusing Weird Substance on the treasure moves the chest and can punch holes in walls. Those mazes have loops, so a plain wall follower can circle forever. For leaderboard runs, use `measure()` to walk toward the chest instead of hugging walls.