Watch a live Breadth-First Search algorithm flood a 19x19 deepslate labyrinth with glowing cyan nodes before backtracking the shortest golden path to the exit.
SimulationsTechnologyCyanGoldGreenLearningMap MakingBlock displaysBlock building (fill/setblock/clone)21+ commands
This command creation visualizes a real Breadth-First Search (BFS) pathfinding algorithm inside a 19x19 deepslate labyrinth. Starting from the top-left corner, a wave of glowing cyan tiles flows down every corridor, splitting at intersections and filling dead ends until it locates the emerald exit beacon.
Once the target is reached, the flood stops and a glowing golden path traces backward from the exit to the start, highlighting the exact shortest route through the maze.
/scoreboard objectives add c9_t dummy/fill ~-9 ~-1 ~-9 ~9 ~1 ~9 polished_deepslate/fill ~-8 ~ ~-8 ~8 ~1 ~8 chiseled_deepslate/fill ~-7 ~ ~-7 ~-7 ~1 ~-1 air/fill ~-7 ~ ~-5 ~7 ~1 ~-5 air/fill ~-3 ~ ~-7 ~-3 ~1 ~7 air/fill ~3 ~ ~-7 ~3 ~1 ~5 air/fill ~-7 ~ ~3 ~7 ~1 ~3 air/fill ~-1 ~ ~-1 ~7 ~1 ~-1 air/execute align xz run summon block_display ~7.5 ~ ~-0.5 {Tags:["c9_exit"],block_state:{Name:"minecraft:emerald_block"},Glowing:1b,glow_color_override:65280,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.35f,0.1f,-0.35f],scale:[0.7f,1.4f,0.7f]}}/execute unless entity @e[tag=c9_node] run scoreboard players set #wave c9_t 1/execute unless entity @e[tag=c9_node] align xz run summon block_display ~-6.5 ~ ~-6.5 {Tags:["c9_node"],block_state:{Name:"minecraft:cyan_concrete"},Glowing:1b,glow_color_override:65535,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.3f,0.05f,-0.3f],scale:[0.6f,0.4f,0.6f]}}/execute as @e[tag=c9_node] unless score @s c9_t matches 1.. run scoreboard players operation @s c9_t = #wave c9_t/execute unless entity @e[tag=c9_path] at @e[tag=c9_exit] run tag @e[tag=c9_node,distance=..0.4,limit=1] add c9_path/execute unless entity @e[tag=c9_path] as @e[tag=c9_node] if score @s c9_t = #wave c9_t at @s positioned ~1 ~ ~ if block ~ ~ ~ air unless entity @e[tag=c9_node,distance=..0.4] run summon block_display ~ ~ ~ {Tags:["c9_node"],block_state:{Name:"minecraft:cyan_concrete"},Glowing:1b,glow_color_override:65535,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.3f,0.05f,-0.3f],scale:[0.6f,0.4f,0.6f]}}/execute unless entity @e[tag=c9_path] as @e[tag=c9_node] if score @s c9_t = #wave c9_t at @s positioned ~-1 ~ ~ if block ~ ~ ~ air unless entity @e[tag=c9_node,distance=..0.4] run summon block_display ~ ~ ~ {Tags:["c9_node"],block_state:{Name:"minecraft:cyan_concrete"},Glowing:1b,glow_color_override:65535,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.3f,0.05f,-0.3f],scale:[0.6f,0.4f,0.6f]}}/execute unless entity @e[tag=c9_path] as @e[tag=c9_node] if score @s c9_t = #wave c9_t at @s positioned ~ ~ ~1 if block ~ ~ ~ air unless entity @e[tag=c9_node,distance=..0.4] run summon block_display ~ ~ ~ {Tags:["c9_node"],block_state:{Name:"minecraft:cyan_concrete"},Glowing:1b,glow_color_override:65535,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.3f,0.05f,-0.3f],scale:[0.6f,0.4f,0.6f]}}/execute unless entity @e[tag=c9_path] as @e[tag=c9_node] if score @s c9_t = #wave c9_t at @s positioned ~ ~ ~-1 if block ~ ~ ~ air unless entity @e[tag=c9_node,distance=..0.4] run summon block_display ~ ~ ~ {Tags:["c9_node"],block_state:{Name:"minecraft:cyan_concrete"},Glowing:1b,glow_color_override:65535,brightness:{sky:15,block:15},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.3f,0.05f,-0.3f],scale:[0.6f,0.4f,0.6f]}}/execute unless entity @e[tag=c9_path] run scoreboard players add #wave c9_t 1/execute if entity @e[tag=c9_path] if score #wave c9_t matches 2.. run scoreboard players remove #wave c9_t 1/execute if entity @e[tag=c9_path] at @e[tag=c9_path] as @e[tag=c9_node,tag=!c9_path,distance=0.6..1.2] if score @s c9_t = #wave c9_t run tag @s add c9_path/execute as @e[tag=c9_path] at @s run particle end_rod ~ ~0.6 ~ 0.1 0.1 0.1 0.01 1/execute as @e[tag=c9_path] run data merge entity @s {block_state:{Name:"minecraft:gold_block"},glow_color_override:16766720,transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[-0.35f,0.05f,-0.35f],scale:[0.7f,0.85f,0.7f]}}/execute if entity @e[tag=c9_path] unless score #wave c9_t matches 2.. run scoreboard players remove #wave c9_t 1setup #2 Builds the outer 19x19 polished deepslate frame and floor for the labyrinth, followed by carving out interconnected corridors with air.loop #2 Aligns to the block grid using <code>align xz</code> and summons the initial cyan <code>block_display</code> seed inside the top-left corridor at <code>~-6.5 ~ ~-6.5</code>.loop #5 Expands the search frontier East (+X) by checking if the adjacent block is air and doesn't already have a node, then summons a new cyan node for the next wave.loop #11 Once the exit is touched by the wave, the wave counter counts backward and tags adjacent nodes matching the exact previous wave step with <code>c9_path</code>.loop #13 Transforms nodes along the shortest path into taller glowing gold blocks so the solved route rises clearly above the cyan exploration flood.


Recorded on our own test server: 48 frames at about 9.5 fps. Our image check saw: A deepslate labyrinth filled with glowing cyan path markers and a highlighted golden path leading from the top-left to a glowing green block on the right.
Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.
To run the pathfinder between a player and a custom destination, summon the c9_exit block display at your target location, then replace the starting node summon coordinates in the second loop command with at @p align xz run summon block_display ~0.5 ~ ~0.5 ... so the search begins right at your feet.
/kill @e[tag=c9_node]/kill @e[tag=c9_exit]/scoreboard objectives remove c9_t/fill ~-9 ~-1 ~-9 ~9 ~1 ~9 air/fill ~-9 ~-1 ~-9 ~9 ~-1 ~9 grass_blockYes! Because the nodes check for air blocks dynamically using if block ~ ~ ~ air, you can break or place walls inside the 19x19 interior and reset the nodes to watch it solve your custom layout.
Run /kill @e[tag=c9_node] in chat. The loop automatically detects when no nodes exist, resets the wave counter to 1, and starts a fresh search from the corner.
▶Four-Dimensional Hypercube Tesseract RotationSimulationsExpert24 cmds
▶Holographic DNA Double-Helix SplicerSimulationsHard24 cmds
▶Magnetic Ferrofluid Audio VisualizerSimulationsHard24 cmds
▶Microscopic Bacteriophage Viral InjectionSimulationsHard24 cmds
▶Monumental Dam Spillway Floodgate ReleaseSimulationsHard24 cmds