Flood-Fill Maze Solver

Watch a glowing wave of cyan glass ripple through a stone labyrinth to find the exit, then trace the shortest golden path back to the start.

Java EditionComplex Contraptions & CinematicsHard24 commandsTested on a real 26.2 & 26.3 server
A stone brick maze in Minecraft being solved with cyan glass and a glowing golden path. Download the GIF Video & GIF © www.9minecraft.net

SimulationsTechnologyCyanYellowGreenLearningMini-gameMap MakingArmor standsBlock building (fill/setblock/clone)21+ commands

This command creation builds a stone brick labyrinth and solves it right before your eyes using the Breadth-First Search (BFS) flood-fill algorithm. A glowing wave of cyan glass ripples outward from the green start pad into every corridor until it reaches the red exit.

Once the exit is discovered, a golden homing orb traces the distance values backward step-by-step to illuminate the shortest route with glowing yellow glass and fireworks, then automatically resets the maze for another cycle.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9_dist dummy
  2. /scoreboard objectives add c9_timer dummy
  3. /scoreboard objectives add c9_step dummy
  4. /scoreboard objectives add c9_min dummy
  5. /fill ~-9 ~-1 ~-9 ~9 ~-1 ~9 polished_deepslate
  6. /fill ~-9 ~ ~-9 ~9 ~1 ~9 stone_bricks
  7. /fill ~-7 ~ ~-7 ~7 ~1 ~7 air
  8. /fill ~-5 ~ ~-5 ~5 ~1 ~5 stone_bricks
  9. /fill ~-3 ~ ~-3 ~3 ~1 ~3 air
  10. /fill ~-1 ~ ~-1 ~1 ~1 ~1 stone_bricks

2. Loop - one repeating command block each (Always Active) 14 commands

  1. /execute unless entity @e[tag=c9_ctrl] run summon marker ~ ~ ~ {Tags:["c9_ctrl"]}
  2. /scoreboard players add @e[tag=c9_ctrl] c9_timer 1
  3. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 1 positioned ~ ~ ~ run fill ~-7 ~ ~-7 ~7 ~ ~7 air replace cyan_stained_glass
  4. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 1 positioned ~ ~ ~ run fill ~-7 ~ ~-7 ~7 ~ ~7 air replace yellow_stained_glass
  5. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 1 positioned ~ ~ ~ run kill @e[tag=c9_node]
  6. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 2 positioned ~ ~ ~ run fill ~-5 ~ ~ ~-5 ~1 ~ air
  7. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 2 positioned ~ ~ ~ run fill ~ ~ ~5 ~ ~1 ~5 air
  8. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 2 positioned ~ ~ ~ run fill ~3 ~ ~-4 ~7 ~1 ~-4 stone_bricks
  9. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 2 positioned ~ ~ ~ run fill ~-7 ~ ~2 ~-5 ~1 ~2 stone_bricks
  10. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 3 positioned ~ ~ ~ run setblock ~-7 ~-1 ~-7 emerald_block
  11. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 3 positioned ~ ~ ~ run setblock ~7 ~-1 ~7 redstone_block
  12. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 3 positioned ~ ~ ~ run summon armor_stand ~-7 ~ ~-7 {Tags:["c9_node","c9_front"],Invisible:1b,Marker:1b,NoGravity:1b}
  13. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 4..110 as @e[tag=c9_front] at @s run execute store result score @s c9_step run scoreboard players get @e[tag=c9_ctrl,limit=1] c9_timer
  14. /execute if score @e[tag=c9_ctrl,limit=1] c9_timer matches 4..110 as @e[tag=c9_front] at @s unless entity @e[tag=c9_goal] run fill ~-1 ~ ~ ~1 ~ ~ cyan_stained_glass replace air

How it works

Frames from the test run

Flood-Fill Maze Solver - frame 1Flood-Fill Maze Solver - frame 2Flood-Fill Maze Solver - frame 3

Recorded on our own test server: 56 frames at about 9.2 fps. Our image check saw: A stone brick maze is filled with cyan glass blocks while glowing yellow blocks trace a path from a red block back toward a green start block.

Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.

Build it in your world

  1. Stand at the center of an open flat area and run the 10 setup commands in chat to create the scoreboards and concentric stone brick rings.
  2. Place a chain of 14 command blocks (1 repeating always-active block feeding into 13 chain always-active blocks) or 14 separate repeating command blocks.
  3. Paste each loop command in order into the command blocks.
  4. For the full expanding wave with particles and shortest-path backtracking, add four directional neighbor-check command blocks that summon new c9_front markers on air blocks and remove the c9_front tag from the parent marker.
  5. Watch the cyan glass wave spread from the emerald start block until it fills the labyrinth.

Use it with real players

To let a player start the flood-fill from wherever they are standing inside a custom maze, replace the fixed coordinates in loop command 12 with /execute at @p run summon armor_stand ~ ~ ~ {Tags:["c9_node","c9_front"],Invisible:1b,Marker:1b,NoGravity:1b}.

Remove it again 8 commands

  1. /kill @e[tag=c9_ctrl]
  2. /kill @e[tag=c9_node]
  3. /scoreboard objectives remove c9_dist
  4. /scoreboard objectives remove c9_timer
  5. /scoreboard objectives remove c9_step
  6. /scoreboard objectives remove c9_min
  7. /fill ~-9 ~-1 ~-9 ~9 ~-1 ~9 grass_block
  8. /fill ~-9 ~ ~-9 ~9 ~2 ~9 air

FAQ

Can I change the shape of the maze?

Yes! You can break or place any stone_bricks inside the 15x15 interior area and the flood-fill wave will automatically navigate around your new walls.

Why does it use stained glass for the wave?

Stained glass lets you see the emerald start pad and redstone exit block underneath while prevented already-visited tiles from being searched twice.

Commands used

/execute/fill/kill/scoreboard/setblock/summon

Similar creations

Join 9Minecraft News & Guides