Skip to content

Commit

Permalink
New ranching scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Nov 6, 2022
1 parent 29594ab commit 062a198
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Challenges/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ teleport.yaml
2048.yaml
hanoi.yaml
Mazes
Ranching
1 change: 1 addition & 0 deletions data/scenarios/Challenges/Ranching/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gated-paddock.yaml
165 changes: 165 additions & 0 deletions data/scenarios/Challenges/Ranching/gated-paddock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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 "scenarios/Challenges/Ranching/gated-paddock/enclosure-checking.sw"};
robots:
- name: base
dir: [0, 1]
devices:
- treads
- scanner
- dictionary
- branch predictor
- strange loop
- clock
- ADT calculator
- comparator
- workbench
- lodestone
- grabber
- logger
- hearing aid
- post puller
- name: sheep
description:
- meandering livestock
display:
invisible: false
char: '@'
system: true
dir: [0, 1]
program: |
run "scenarios/Challenges/Ranching/gated-paddock/meandering-sheep.sw";
entities:
- name: fence
display:
char: '#'
description:
- A fence.
properties: [known, portable, unwalkable]
- name: solid fence
display:
char: '#'
attr: rock
description:
- An immobile 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]
seed: 0
solution: |
run "scenarios/Challenges/Ranching/gated-paddock/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..............~~~~....
~~~....................................~~~~~~~~~...~
~~......................................~~~~~~~~~~~~
~~..............................~~~~~~~~~~~~~~~~~~~~
~~~~...................~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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" } {}
)

0 comments on commit 062a198

Please sign in to comment.