New ranching scenario

This commit is contained in:
Karl Ostmo 2022-11-05 14:43:50 -07:00
parent 0e09d47c1f
commit 146cd4b9a4
6 changed files with 352 additions and 0 deletions

View File

@ -3,3 +3,4 @@ teleport.yaml
2048.yaml
hanoi.yaml
Mazes
Ranching

View File

@ -0,0 +1 @@
gated-paddock.yaml

View File

@ -0,0 +1,163 @@
version: 1
name: Pastoral Island
description: |
Start a wool industry from the local fauna.
creative: false
objectives:
- goal:
- |
You've homesteaded on a small Pacific island.
It's time to gather resources to trade.
- |
You encounter some feral sheep. They look like a promising
source of wool.
- |
First, paddock the sheep so they don't drown.
Construct a fence using the nearby gate as a starting point.
Make sure there are no gaps!
- |
Note that you can use the "drill" command (by way of the "post puller" tool)
to demolish a fence that has been "placed".
condition: |
r <- robotnamed "sheep";
as r {run "/home/kostmo/github/swarm-scripts/characters/enclosure-checking.sw"};
robots:
- name: base
dir: [0, 1]
devices:
- treads
- scanner
- dictionary
- branch predictor
- strange loop
- clock
- ADT calculator
- comparator
- workbench
- lodestone
- grabber
- post puller
- name: sheep
description:
- meandering livestock
display:
invisible: false
char: '@'
system: true
dir: [0, 1]
program: |
run "/home/kostmo/github/swarm-scripts/characters/meandering-sheep.sw";
entities:
- name: fence
display:
char: '#'
description:
- A fence.
properties: [known, portable, unwalkable]
- name: solid fence
display:
char: '#'
attr: rock
description:
- An unmovable fence.
properties: [known, unwalkable]
- name: post puller
display:
char: 'P'
attr: rock
capabilities: [drill]
description:
- Good for dismantling fences.
properties: [known]
- name: scrap wood
display:
char: '\'
description:
- Scrap wood, good for nothing, really.
properties: [known]
- name: gate
display:
char: '/'
attr: rock
description:
- A gate.
properties: [known]
- name: cabin
display:
char: 🏠
attr: rock
description:
- A cabin.
properties: [known, unwalkable]
- name: fresh breadcrumb
display:
char: '.'
description:
- A marker that can be put down and found again.
properties: [portable]
- name: treaded breadcrumb
display:
char: 'x'
description:
- A marker that can be put down and found again.
properties: [portable]
recipes:
- in:
- [2, board]
out:
- [1, fence]
- in:
- [0, fresh breadcrumb]
out:
- [1, fresh breadcrumb]
- in:
- [1, fresh breadcrumb]
out:
- [1, treaded breadcrumb]
- in:
- [1, fence]
out:
- [1, scrap wood]
required:
- [1, post puller]
known: [mountain, tree, water, fresh breadcrumb, treaded breadcrumb]
seed: 0
solution: |
run "/home/kostmo/github/swarm-scripts/characters/fence-construction.sw"
world:
default: [dirt, water]
palette:
'B': [grass, null, base]
'.': [grass]
'G': [grass, gate]
'f': [grass, solid fence]
't': [dirt, tree]
'x': [stone, mountain]
'c': [stone, cabin]
's': [grass, null, sheep]
'~': [dirt, water]
upperleft: [-34, 11]
map: |
~~.........~~~~~~~~~~~~~.......................~~~~~
~..............~~~~...............................~~
...................................................~
....................................................
.........................................tttttttt...
.........................................tttttttt...
..............................x..........tttttttt...
.........................................tttttttt...
.........s...............................tttttttt...
.........................................tttttttt...
...................................f................
..xx...............................G.....B......c...
...x...............................f................
..............................s.....................
....................................................
....................................................
~........x.....s....................................
~~..................................................
~~~..........................x..............~~~~....
~~~....................................~~~~~~~~~...~
~~......................................~~~~~~~~~~~~
~~..............................~~~~~~~~~~~~~~~~~~~~
~~~~...................~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -0,0 +1,87 @@
// Algorithm:
// Maintain current direction until a wall is encountered.
// Then enter "wall-following mode".
// This mode presumes the wall is not a loop.
// (If it was a loop, then an "oriented breadcrumb" would need to be left.
// The breadcrumb is oriented in case a single-width passage is backtracked
// along the opposite wall.)
def isFenced =
s <- scan forward;
return (
case s
(\_. false)
(\x. x == "fence" || x == "gate" || x == "solid fence")
);
end;
def isBlockedOrFenced =
b <- blocked;
f <- isFenced;
return (b || f);
end;
// Returns true if we've already placed two
// breadcrumbs on a given tile, false otherwise.
def leaveBreadcrumbs =
let bc1 = "fresh breadcrumb" in
let bc2 = "treaded breadcrumb" in
wasTraversedOnce <- ishere bc1;
if wasTraversedOnce {
_crumb <- grab;
make bc2;
place bc2;
return false;
} {
wasTraversedTwice <- ishere bc2;
if wasTraversedTwice {
return true;
} {
// Make sure nothing's in the way before we place
// our breadcrumb:
x <- scan down;
case x return (\_. grab; return ());
make bc1;
place bc1;
return false;
};
};
end;
def goForwardToPatrol = \wasBlocked.
b <- isBlockedOrFenced;
if b {
turn left;
goForwardToPatrol true;
turn right;
goForwardToPatrol false;
} {
if wasBlocked {
isLoop <- leaveBreadcrumbs;
if isLoop {
fail "loop";
} {};
} {};
move;
};
end;
def checkIsEnclosed =
try {
goForwardToPatrol false;
// Water is the outer boundary
hasWater <- ishere "water";
if hasWater {
return false;
} {
checkIsEnclosed;
};
} {
return true;
};
end;
checkIsEnclosed;

View File

@ -0,0 +1,64 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
def processTree =
grab;
make "log";
make "board";
doN 2 (make "fence");
end;
def grabTwoRows =
doN 7 (processTree; move);
processTree;
turn right;
move;
turn right;
doN 7 (processTree; move);
processTree;
end;
def grabTrees =
doN 7 move;
turn right;
grabTwoRows;
turn left;
move;
turn left;
grabTwoRows;
turn left;
move;
turn left;
grabTwoRows;
end;
def buildFence =
doN 6 move;
turn right;
doN 4 (place "fence"; move);
turn left;
doN 30 (place "fence"; move);
turn left;
doN 15 (place "fence"; move);
turn left;
doN 30 (place "fence"; move);
turn left;
doN 7 (place "fence"; move);
place "fence";
turn right;
doN 6 move;
end;
// buildFence;
grabTrees;
buildFence;

View File

@ -0,0 +1,36 @@
// A "sheep" that wanders around randomly.
let forever : cmd unit -> cmd unit = \c. c ; forever c in
let repeat : int -> cmd unit -> cmd unit =
\n. \c. if (n == 0) {} {c ; repeat (n-1) c} in
let randdir : cmd dir =
d <- random 4;
return (
if (d == 0) {north}
{if (d == 1) {east}
{if (d == 2) {south} {west}}})
in
forever (
n <- random 30;
wait (30 + n);
d <- randdir;
turn d;
dist <- random 3;
repeat dist (
b <- blocked;
if b {} {
move;
// Sheep can drown.
hasWater <- ishere "water";
if hasWater {
say "whoops!";
selfdestruct;
} {};
}
);
r <- random 5;
if (r == 0) { say "baaa" } {}
)