diff --git a/data/scenarios/Challenges/Ranching/00-ORDER.txt b/data/scenarios/Challenges/Ranching/00-ORDER.txt index 95978ccd78..8bdbff6478 100644 --- a/data/scenarios/Challenges/Ranching/00-ORDER.txt +++ b/data/scenarios/Challenges/Ranching/00-ORDER.txt @@ -1,3 +1,4 @@ +beekeeping.yaml capture.yaml powerset.yaml gated-paddock.yaml diff --git a/data/scenarios/Challenges/Ranching/_beekeeping/queenbee.sw b/data/scenarios/Challenges/Ranching/_beekeeping/queenbee.sw new file mode 100644 index 0000000000..ec16fa7534 --- /dev/null +++ b/data/scenarios/Challenges/Ranching/_beekeeping/queenbee.sw @@ -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; diff --git a/data/scenarios/Challenges/Ranching/_beekeeping/solution.sw b/data/scenarios/Challenges/Ranching/_beekeeping/solution.sw new file mode 100644 index 0000000000..85de338b54 --- /dev/null +++ b/data/scenarios/Challenges/Ranching/_beekeeping/solution.sw @@ -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; \ No newline at end of file diff --git a/data/scenarios/Challenges/Ranching/beekeeping.yaml b/data/scenarios/Challenges/Ranching/beekeeping.yaml new file mode 100644 index 0000000000..232b933541 --- /dev/null +++ b/data/scenarios/Challenges/Ranching/beekeeping.yaml @@ -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............. + ................ + ................ + ................ + ................ + ................ + ................ + + \ No newline at end of file diff --git a/test/integration/Main.hs b/test/integration/Main.hs index f4484fc055..8bb1747658 100644 --- a/test/integration/Main.hs +++ b/test/integration/Main.hs @@ -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" ]