swarm/example/dfs.sw
2022-09-26 20:10:12 +00:00

14 lines
356 B
Plaintext

def ifC : forall a. cmd bool -> {cmd a} -> {cmd a} -> cmd a =
\test. \thn. \els. b <- test; if b thn els end
// Recursive DFS to harvest a contiguous forest
def dfs : cmd unit =
ifC (ishere "tree") {
grab;
turn west;
ifC blocked {} {move; dfs; turn east; move};
turn north;
ifC blocked {} {move; dfs; turn south; move};
} {}
end