swarm-0.7.0.0: data/scenarios/Tutorials/stock.yaml
version: 1
name: Stock
description: |
Learn how to stock inventory when building robots.
objectives:
- goal:
- |
In the previous tutorial challenge, you learned how to use `require`{=snippet}
to require specific devices to be equipped.
Sometimes, instead of requiring entities to be equiped as devices, you need them to be stocked in your inventory.
- |
In this case, you can write `stock <int> <name>`{=snippet} to ensure that a certain number
of copies of a certain entity are placed in your inventory. For example:
```
build {stock 2 "flower"; move; place "flower"; move; place "flower"}
```
This would build a robot with two `flower`{=entity}s in its inventory which the robot can then place.
- Your goal in this challenge is to cover the entire 4x4 gray area with `rock`{=entity}s!
- |
**TIP:** You can define commands to simplify your task, for example:
`def r = move; place "rock"; end`
condition: |
def forM = \i.\e. \c. if (i >= e) {} {c i; forM (i+1) e c} end;
def ifC = \test. \then. \else. b <- test; if b then else end;
try {
turn east;
forM 1 5 (\y.
forM 1 5 (\x.
teleport self (x,-y);
ifC (ishere "rock") {} {grab; noop};
);
);
pure true
} { pure false }
solution: |
def x4 = \c. c;c;c;c end;
def mp = move; place "rock" end;
def rr = turn right; move; turn right; x4 mp; turn back; x4 move end;
build {
stock 16 "rock";
x4 rr
};
robots:
- name: base
heavy: true
dir: north
display:
char: Ω
attr: robot
devices:
- logger
- 3D printer
- dictionary
inventory:
- [16, compass]
- [16, solar panel]
- [16, logger]
- [16, treads]
- [16, grabber]
- [16, scanner]
- [16, lambda]
- [100, rock]
world:
palette:
"Ω": [grass, null, base]
".": [grass]
"_": [stone]
"+": [stone, wall]
upperleft: [-1, 1]
map: |
+++++++
+Ω....+
+.____+
+.____+
+.____+
+.____+
+++++++