Skip to content

Commit

Permalink
spiders
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Jan 6, 2025
1 parent 0ad3582 commit 9e058a7
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 2 deletions.
55 changes: 55 additions & 0 deletions data/scenarios/Fun/_spider/monkey.sw
Original file line number Diff line number Diff line change
@@ -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";
55 changes: 55 additions & 0 deletions data/scenarios/Fun/_spider/spider.sw
Original file line number Diff line number Diff line change
@@ -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";
46 changes: 46 additions & 0 deletions data/scenarios/Fun/spider.yaml
Original file line number Diff line number Diff line change
@@ -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}
]
4 changes: 2 additions & 2 deletions scripts/gen/preview-world-vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e058a7

Please sign in to comment.