Skip to content

Commit

Permalink
wip: rat logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 14, 2024
1 parent c35b635 commit 758e6c1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
21 changes: 14 additions & 7 deletions data/scenarios/Challenges/_pied-piper/rat.sw
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +26,7 @@ def goFoodDir = \f. \r.
// navigation direction is determined
// but before we move.
try {
move;
moveWithMortality;
} {};
f;
}
Expand All @@ -33,7 +44,7 @@ def goHomeDir = \f. \r.
// navigation direction is determined
// but before we move.
try {
move;
moveWithMortality;
} {};
f;
}
Expand All @@ -52,7 +63,7 @@ def moveUntilBlocked =
isBlocked <- blocked;
if isBlocked {
} {
move;
moveWithMortality;
moveUntilBlocked;
};
end;
Expand All @@ -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";
Expand Down
34 changes: 29 additions & 5 deletions data/scenarios/Challenges/_pied-piper/solution.sw
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 17 additions & 1 deletion data/scenarios/Challenges/pied-piper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ robots:
- 3D printer
- ADT calculator
- antenna
- binoculars
- branch predictor
- clock
- comparator
Expand All @@ -34,10 +35,12 @@ robots:
- lambda
- logger
- net
- rolex
- scanner
- strange loop
- string
- treads
- tweezers
- workbench
inventory:
- [200, oats]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -143,6 +157,8 @@ world:
offset: [23, -24]
orient:
up: east
# - src: burrow
# offset: [-7, 10]
upperleft: [0, 2]
dsl: |
overlay
Expand Down

0 comments on commit 758e6c1

Please sign in to comment.