Skip to content

Commit

Permalink
work on BFS solution
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Dec 12, 2023
1 parent d564716 commit 8a9a4df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions data/scenarios/Challenges/Mazes/shortest_path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ robots:
- [50, string]
- [50, fast grabber]
- [50, detonator]
- [50, dictionary]
- [1000, rock]
- [1000, lodestone]
- [1000, flower]
Expand Down

0 comments on commit 8a9a4df

Please sign in to comment.