diff --git a/data/scenarios/Challenges/_pied-piper/rat.sw b/data/scenarios/Challenges/_pied-piper/rat.sw index c6e744a59..0cfa18b78 100644 --- a/data/scenarios/Challenges/_pied-piper/rat.sw +++ b/data/scenarios/Challenges/_pied-piper/rat.sw @@ -1,4 +1,46 @@ +def goFoodDir = \f. \r. + // say "in goFoodDir"; + let d = fst r in + if (d == down) { + foodHere <- ishere "oats"; + if foodHere { + grab; return () + } {}; + f; + return () + } { + turn d; + + // An obstruction might arise after + // navigation direction is determined + // but before we move. + try { + move; + } {}; + f; + } + end; + +def goHomeDir = \f. \r. + // say "in goHomeDir"; + let d = fst r in + if (d == down) { + return () + } { + turn d; + + // An obstruction might arise after + // navigation direction is determined + // but before we move. + try { + move; + } {}; + f; + } + end; + def findGoodDirection = + // say "in findGoodDirection"; isBlocked <- blocked; if isBlocked { turn left; @@ -23,15 +65,45 @@ def pauseAtRandom = } {} end; -def doMovement = +def returnHome = \homeLoc. + // say "in returnHome"; + nextDir <- path (inL ()) (inL homeLoc); + case nextDir return $ goHomeDir $ returnHome homeLoc; + end; + +def pursueFood = \hadSensedFood. \homeLoc. + // say $ "in pursueFood. hadSensedFood? " ++ format hadSensedFood; + nextDir <- path (inR 5) (inR "oats"); + case nextDir (\_. if hadSensedFood {returnHome homeLoc} {return ()}) $ + goFoodDir $ pursueFood true homeLoc; + end; + +def checkExpireSelf = + loc <- whereami; + if (snd loc > 6) {selfdestruct} {}; + end; + +def doMovement = \startLoc. + // say "in doMovement"; + checkExpireSelf; + findGoodDirection; moveUntilBlocked; - pauseAtRandom + pauseAtRandom; + pursueFood false startLoc; end; -def go = - doMovement; - go; +/** Loop */ +def go = \startLoc. + doMovement startLoc; + go startLoc; end; -go; \ No newline at end of file +startLoc <- whereami; +// let shouldDestruct = !(snd startLoc == -17 && fst startLoc < 19) in +let shouldDestruct = false in +if shouldDestruct { + selfdestruct; +} { + go startLoc; +} diff --git a/data/scenarios/Challenges/_pied-piper/solution.sw b/data/scenarios/Challenges/_pied-piper/solution.sw index 065404d56..abefbe0ab 100644 --- a/data/scenarios/Challenges/_pied-piper/solution.sw +++ b/data/scenarios/Challenges/_pied-piper/solution.sw @@ -1,8 +1,15 @@ +def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; + +def makeOatsTrail = + place "oats"; + doN 4 move; + end; + def go = - place "tree"; - move; move; - // place "oats"; + doN 5 makeOatsTrail; + turn back; + doN (5*4) move; + turn back; end; -wait 10; go; \ No newline at end of file diff --git a/data/scenarios/Challenges/pied-piper.yaml b/data/scenarios/Challenges/pied-piper.yaml index 5a831d6a8..a7634d992 100644 --- a/data/scenarios/Challenges/pied-piper.yaml +++ b/data/scenarios/Challenges/pied-piper.yaml @@ -17,8 +17,8 @@ terrains: Wooden raised path robots: - name: base - loc: [18, -22] - dir: north + loc: [19, 7] + dir: south devices: - 3D printer - ADT calculator @@ -26,19 +26,24 @@ robots: - branch predictor - clock - comparator + - compass - counter - dictionary - grabber + - hearing aid - lambda - logger - net - scanner - strange loop - string + - treads - workbench inventory: - - [50, oats] - - [50, tree] + - [200, oats] + walkable: + never: + - door - name: rat system: true dir: west @@ -49,16 +54,6 @@ robots: - logger program: | run "scenarios/Challenges/_pied-piper/rat.sw" - - name: helper - loc: [0, 10] - system: true - dir: west - display: - invisible: false - devices: - - logger - program: | - noop; objectives: - goal: - Rats have infested the village dwellings. Clear them out! @@ -72,10 +67,17 @@ solution: | entities: - name: door display: - char: 'X' + char: 'D' description: - door properties: [known] + - name: wall + display: + char: 'W' + attr: wood + description: + - wall + properties: [known, unwalkable] - name: oats display: attr: oats @@ -93,7 +95,7 @@ world: structure: palette: 'd': [stone, door] - 'x': [stone, boulder] + 'x': [stone, wall] '.': [stone] 'r': [stone, erase, rat] map: | @@ -150,8 +152,8 @@ world: , mask (y > -37 && y < -32) {stone} ] map: | - ....bbbb.. - ....bbbb.. - ....bbbb.. - ....bbbb.. - ....bbbb.. + ....bbbb + ....bbbb + ....bbbb + ....bbbb + ....bbbb