diff --git a/data/scenarios/Fun/_spider/monkey.sw b/data/scenarios/Fun/_spider/monkey.sw new file mode 100644 index 000000000..81667888a --- /dev/null +++ b/data/scenarios/Fun/_spider/monkey.sw @@ -0,0 +1,55 @@ +def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; + +def intersperse = \n. \f2. \f1. if (n > 0) { + f1; + if (n > 1) { + f2; + } {}; + intersperse (n - 1) f2 f1; + } {}; + end; + +def placeBoulder = \border. + create border; + + isEmptyHere <- isempty; + if isEmptyHere { + place border + } { + swap border; + return (); + }; + + return (); +end + +def spinWeb = \border. + move; + turn left; + + try { + intersperse 2 move $ placeBoulder border; + doN 3 ( + turn left; + doN 2 (placeBoulder border; move); + ); + placeBoulder border; + } {}; +end + +def goDir = \f. \result. + let d = fst result in + if (d == down) { + spinWeb "mountain"; + } { + turn d; move; + }; + f; +end; + +def followRoute = \item. + nextDir <- path (inL ()) (inR item); + case nextDir return $ goDir $ followRoute item; + end; + +followRoute "tree"; \ No newline at end of file diff --git a/data/scenarios/Fun/_spider/spider.sw b/data/scenarios/Fun/_spider/spider.sw new file mode 100644 index 000000000..5a3c144ea --- /dev/null +++ b/data/scenarios/Fun/_spider/spider.sw @@ -0,0 +1,55 @@ +def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; + +def intersperse = \n. \f2. \f1. if (n > 0) { + f1; + if (n > 1) { + f2; + } {}; + intersperse (n - 1) f2 f1; + } {}; + end; + +def placeBoulder = \border. + create border; + + isEmptyHere <- isempty; + if isEmptyHere { + place border + } { + swap border; + return (); + }; + + return (); +end + +def spinWeb = \border. + move; + turn left; + + try { + intersperse 2 move $ placeBoulder border; + doN 3 ( + turn left; + doN 2 (placeBoulder border; move); + ); + placeBoulder border; + } {}; +end + +def goDir = \f. \result. + let d = fst result in + if (d == down) { + spinWeb "mountain"; + } { + turn d; move; + }; + f; +end; + +def followRoute = \item. + nextDir <- path (inL ()) (inR item); + case nextDir return $ goDir $ followRoute item; + end; + +followRoute "flower"; \ No newline at end of file diff --git a/data/scenarios/Fun/spider.yaml b/data/scenarios/Fun/spider.yaml new file mode 100644 index 000000000..505440fb4 --- /dev/null +++ b/data/scenarios/Fun/spider.yaml @@ -0,0 +1,46 @@ +version: 1 +name: Spiders +description: | + Spiders catching prey by spinning webs +creative: true +robots: + - name: base + dir: north + loc: [5, 0] + - name: spider + display: + invisible: false + attr: blue + dir: north + system: true + loc: [0, 0] + program: | + run "scenarios/Fun/_spider/spider.sw" + - name: monkey + display: + invisible: false + attr: red + dir: north + system: true + loc: [0, 0] + program: | + run "scenarios/Fun/_spider/monkey.sw" +structures: + - name: cocoon + recognize: [north] + structure: + mask: '.' + palette: + 'b': [grass, mountain] + map: | + bbb + b.b + bbb +known: [tree] +world: + dsl: | + overlay + [ {grass} + , mask ((hash % 200) == 0) {flower} + , mask (((hash+1) % 200) == 0) {tree} + ] \ No newline at end of file diff --git a/scripts/gen/preview-world-vscode.sh b/scripts/gen/preview-world-vscode.sh index bf91977ea..4f1ba3b87 100755 --- a/scripts/gen/preview-world-vscode.sh +++ b/scripts/gen/preview-world-vscode.sh @@ -25,9 +25,9 @@ IMG_WIDTH=200 IMG_HEIGHT=150 IMG_OUTPUT_PATH=output.png -RENDER_IMG_COMMAND="stack exec swarm-scene -- $SCENARIO_PATH --fail-blank --dest $IMG_OUTPUT_PATH --png --width $IMG_WIDTH --height $IMG_HEIGHT" +RENDER_IMG_COMMAND="cabal run swarm-scene -- $SCENARIO_PATH --fail-blank --dest $IMG_OUTPUT_PATH --png --width $IMG_WIDTH --height $IMG_HEIGHT" -stack build --fast swarm:swarm-scene +cabal build -j -O0 swarm:swarm-scene $RENDER_IMG_COMMAND code --reuse-window $SCENARIO_PATH && code --reuse-window $IMG_OUTPUT_PATH