Skip to content

Commit

Permalink
beekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Oct 29, 2023
1 parent 2fc6257 commit 35580bd
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Challenges/Ranching/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
beekeeping.yaml
capture.yaml
powerset.yaml
gated-paddock.yaml
52 changes: 52 additions & 0 deletions data/scenarios/Challenges/Ranching/_beekeeping/queenbee.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Spawns worker bees when structures are detected

def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
def mod : int -> int -> int = \a. \b. a - (a/b)*b end;

def workerProgram = \hiveIdx. \structureLoc.
foundStructure <- structure "beehive" hiveIdx;
let stillHasStructure = case foundStructure (\_. false) (\fs.
structureLoc == snd fs;
) in

if (stillHasStructure) {
doN 10 (move; wait 4;);
turn back;
doN 10 (move; wait 4;);
workerProgram hiveIdx structureLoc;
} {
selfdestruct;
}
end;

def workerProgramInit = \hiveIdx. \structureLoc.
teleport self structureLoc;
appear "8";
if (mod hiveIdx 2 == 0) {turn left;} {};
workerProgram hiveIdx structureLoc;
end;

def observeHives = \lastHiveCount.

foundStructure <- structure "beehive" lastHiveCount;
newHiveCount <- case foundStructure (\_. return lastHiveCount) (\fs.
let newHiveCount = fst fs in

if (newHiveCount > lastHiveCount) {
// Build worker bee, assign ID, location
build {workerProgramInit lastHiveCount $ snd fs};
return ();
} {};

return newHiveCount;
);

wait 1;
observeHives newHiveCount;
end;

def go =
observeHives 0;
end;

go;
74 changes: 74 additions & 0 deletions data/scenarios/Challenges/Ranching/_beekeeping/solution.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

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 nextRow = \d.
turn d;
move;
turn d;
end;

def slatRow =
make "slat";
intersperse 3 move (place "slat");
end;

def buildHive =
doN 4 (intersperse 4 move (place "board"); turn right; move;);
turn right;
move;

slatRow;
nextRow left;
slatRow;
nextRow right;
slatRow;

end;

def moveToNextHive =
turn left;
doN 7 move;
turn left;
doN 3 move;
turn right;
end;

def buildTankSide = \item.
doN 3 (move; place item;);
move;
turn right;
move;
place item;
turn left;
move;
turn right;
end;

def buildBrewery =
turn right;
doN 3 (place "copper pipe"; move;);
move;
turn right;
doN 3 move;
turn right;
move;
doN 4 $ buildTankSide "copper wall";
end;

def go =
intersperse 4 moveToNextHive buildHive;

doN 10 move;
buildBrewery;
end;

go;
140 changes: 140 additions & 0 deletions data/scenarios/Challenges/Ranching/beekeeping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
version: 1
name: Beekeeping
author: Karl Ostmo
description: |
Build an apiary
creative: true
seed: 2
objectives:
- teaser: Construct hives
goal:
- |
Build eight `beehive`{=entity}s
condition: |
foundStructure <- structure "beehive" 0;
return $ case foundStructure (\_. false) (\_. true);
- teaser: Collect honey
goal:
- |
Collect 12 jars of honey
condition: |
return false;
robots:
- name: base
dir: [1, 0]
devices:
- 3D printer
- branch predictor
- calculator
- clock
- comparator
- dictionary
- dozer blade
- grabber
- hearing aid
- keyboard
- lambda
- logger
- scanner
- strange loop
- treads
- welder
- workbench
inventory:
- [100, board]
- [50, copper wall]
- [3, copper pipe]
- name: queenbee
dir: [1, 0]
system: true
display:
invisible: false
program:
run "scenarios/Challenges/Ranching/_beekeeping/queenbee.sw"
solution: |
run "scenarios/Challenges/Ranching/_beekeeping/solution.sw"
structures:
- name: beehive
recognize: true
structure:
palette:
'-': [dirt, slat]
'b': [dirt, board]
map: |
bbbbb
b---b
b---b
b---b
bbbbb
- name: brewery
recognize: true
structure:
palette:
'p': [dirt, copper wall]
'I': [dirt, copper pipe]
'.': [dirt]
map: |
..ppp..
.p...p.
p.....p
p.III.p
p.....p
.p...p.
..ppp..
entities:
- name: honeycomb
display:
char: 'x'
attr: gold
description:
- Pushable rock
properties: [known, unwalkable, portable]
- name: slat
display:
char: '-'
attr: ice
description:
- Internal component of a beehive
properties: [known, portable]
- name: copper wall
display:
char: 't'
attr: copper
description:
- Material for brewery tank
properties: [known, portable, unwalkable]
recipes:
- in:
- [1, board]
out:
- [3, slat]
known: [flower, tree]
world:
dsl: |
let
cl = perlin seed 1 0.15 0.0,
flowers = cl > 0.7
in
overlay
[ {grass}
, mask (flowers && (x + y) % 3 == 0) {flower}
]
upperleft: [0, 0]
offset: false
palette:
'B': [grass, erase, base]
'Q': [grass, erase, queenbee]
'.': [grass, erase]
'*': [grass, flower]
map: |
..........Q.....
................
..B.............
................
................
................
................
................
................
1 change: 1 addition & 0 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ testScenarioSolutions rs ui =
, testGroup
"Ranching"
[ testSolution Default "Challenges/Ranching/capture"
, testSolution (Sec 10) "Challenges/Ranching/beekeeping"
, testSolution (Sec 10) "Challenges/Ranching/powerset"
, testSolution (Sec 30) "Challenges/Ranching/gated-paddock"
]
Expand Down

0 comments on commit 35580bd

Please sign in to comment.