diff --git a/data/scenarios/Challenges/Mazes/_shortest_path/shortest_path_sol.sw b/data/scenarios/Challenges/Mazes/_shortest_path/shortest_path_sol.sw index b0a2ffa6a..99fc7969f 100644 --- a/data/scenarios/Challenges/Mazes/_shortest_path/shortest_path_sol.sw +++ b/data/scenarios/Challenges/Mazes/_shortest_path/shortest_path_sol.sw @@ -6,13 +6,21 @@ def ifM = \p.\t.\e. b <- p; if b t e end; def DFSn : int -> cmd bool = \n. // say $ "DFSn at level " ++ format n; ifM (ishere "goal") {swap "path"; selfdestruct} {}; - if (n == 0) {} { - ifM (ishere "path") {} { - place "path"; - tL; b <- blocked; bL <- if b {return true} {move; DFSn (n-1)}; - tR; b <- blocked; bF <- if b {return true} {move; DFSn (n-1)}; - tR; b <- blocked; bR <- if b {return true} {move; DFSn (n-1)}; - tL; if (bL && bF && bR) {swap "rock"} {grab}; return () + ifM (ishere "rock") {} { + if (n == 0) {} { + ifM (ishere "path") {} { + place "path"; + // Weird stuff with let bindings is a workaround for + // https://github.com/swarm-game/swarm/issues/681 + // (see https://github.com/swarm-game/swarm/issues/1032#issuecomment-1402465755) + tL; b <- blocked; dead <- if b {return true} {move; DFSn (n-1)}; + let deadL = dead in + tR; b <- blocked; dead <- if b {return true} {move; DFSn (n-1)}; + let deadF = dead in + tR; b <- blocked; dead <- if b {return true} {move; DFSn (n-1)}; + let deadR = dead in + tL; if (deadL && deadF && deadR) {swap "rock"} {grab}; return () + } } }; rockhere <- ishere "rock"; diff --git a/data/scenarios/Challenges/Mazes/shortest_path.yaml b/data/scenarios/Challenges/Mazes/shortest_path.yaml index c8c022d67..719fbc826 100644 --- a/data/scenarios/Challenges/Mazes/shortest_path.yaml +++ b/data/scenarios/Challenges/Mazes/shortest_path.yaml @@ -88,6 +88,7 @@ robots: - [50, string] - [50, fast grabber] - [50, detonator] + - [50, dictionary] - [1000, rock] - [1000, lodestone] - [1000, flower]