From 758e6c102725096688e4f475b32b79ce9211ef97 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Mon, 2 Sep 2024 14:38:37 -0700 Subject: [PATCH] wip: rat logic --- data/scenarios/Challenges/_pied-piper/rat.sw | 21 ++++++++---- .../Challenges/_pied-piper/solution.sw | 34 ++++++++++++++++--- data/scenarios/Challenges/pied-piper.yaml | 18 +++++++++- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/data/scenarios/Challenges/_pied-piper/rat.sw b/data/scenarios/Challenges/_pied-piper/rat.sw index 0cfa18b78..c6d92c559 100644 --- a/data/scenarios/Challenges/_pied-piper/rat.sw +++ b/data/scenarios/Challenges/_pied-piper/rat.sw @@ -1,3 +1,14 @@ +def checkExpireSelf = + loc <- whereami; + if (snd loc > 6) {selfdestruct} {}; + end; + + +def moveWithMortality = + move; + instant checkExpireSelf; + end; + def goFoodDir = \f. \r. // say "in goFoodDir"; let d = fst r in @@ -15,7 +26,7 @@ def goFoodDir = \f. \r. // navigation direction is determined // but before we move. try { - move; + moveWithMortality; } {}; f; } @@ -33,7 +44,7 @@ def goHomeDir = \f. \r. // navigation direction is determined // but before we move. try { - move; + moveWithMortality; } {}; f; } @@ -52,7 +63,7 @@ def moveUntilBlocked = isBlocked <- blocked; if isBlocked { } { - move; + moveWithMortality; moveUntilBlocked; }; end; @@ -78,10 +89,6 @@ def pursueFood = \hadSensedFood. \homeLoc. goFoodDir $ pursueFood true homeLoc; end; -def checkExpireSelf = - loc <- whereami; - if (snd loc > 6) {selfdestruct} {}; - end; def doMovement = \startLoc. // say "in doMovement"; diff --git a/data/scenarios/Challenges/_pied-piper/solution.sw b/data/scenarios/Challenges/_pied-piper/solution.sw index abefbe0ab..889f305a0 100644 --- a/data/scenarios/Challenges/_pied-piper/solution.sw +++ b/data/scenarios/Challenges/_pied-piper/solution.sw @@ -1,15 +1,39 @@ def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; -def makeOatsTrail = +def makeOatsCrumb = \spacing. place "oats"; - doN 4 move; + doN spacing move; end; -def go = - doN 5 makeOatsTrail; + +def waitUntilDisappeared = + found <- scout north; + if found { + wait 1; + waitUntilDisappeared; + } {}; + end; + +/** +Place a trail of breadcrumbs, and return +one crumb short of the first crumb. +*/ +def makeOatsTrail = \spacing. \segments. + doN segments $ makeOatsCrumb spacing; turn back; - doN (5*4) move; + doN ((segments - 1)*spacing) move; turn back; + watch down; + wait 2000; + end; + +def go = + let spacing = 4 in + let segments = 5 in + makeOatsTrail spacing segments; + // Has probably awakened due to rat eating food here. + waitUntilDisappeared; + makeOatsTrail spacing $ segments; end; go; \ No newline at end of file diff --git a/data/scenarios/Challenges/pied-piper.yaml b/data/scenarios/Challenges/pied-piper.yaml index a7634d992..03f3a50c1 100644 --- a/data/scenarios/Challenges/pied-piper.yaml +++ b/data/scenarios/Challenges/pied-piper.yaml @@ -23,6 +23,7 @@ robots: - 3D printer - ADT calculator - antenna + - binoculars - branch predictor - clock - comparator @@ -34,10 +35,12 @@ robots: - lambda - logger - net + - rolex - scanner - strange loop - string - treads + - tweezers - workbench inventory: - [200, oats] @@ -87,10 +90,21 @@ entities: properties: [known, pickable, growable] growth: duration: [20, 30] -known: [water] +known: [water, boulder] seed: 0 world: structures: + - name: burrow + structure: + mask: '.' + palette: + 'x': [stone, boulder] + map: | + .xxxx. + xx..xx + x..... + xx..xx + .xxxx. - name: house structure: palette: @@ -143,6 +157,8 @@ world: offset: [23, -24] orient: up: east + # - src: burrow + # offset: [-7, 10] upperleft: [0, 2] dsl: | overlay