Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exterminator scenario #2126

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/scenarios/Challenges/Ranching/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ capture.yaml
powerset.yaml
fishing.yaml
gated-paddock.yaml
pied-piper.yaml
107 changes: 107 additions & 0 deletions data/scenarios/Challenges/Ranching/_pied-piper/rat.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
def moveWithMorbidity =
moldHere <- ishere "mold";
if moldHere {
try {
// handle race conditions in which
// another robot grabs it first
m <- harvest;
let spores = "mold spores" in
if (m == spores) {
say $ "Yuck, " ++ spores ++ "! I'm outta here.";
selfdestruct;
} {};
} {};
} {};
move;
end;

def goFoodDir = \f. \r.
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 {
moveWithMorbidity;
} {};
f;
}
end;

def goHomeDir = \f. \r.
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 {
moveWithMorbidity;
} {};
f;
}
end;

def findGoodDirection =
isBlocked <- blocked;
if isBlocked {
turn left;
findGoodDirection;
} {};
end;

def moveUntilBlocked =
isBlocked <- blocked;
if isBlocked {
} {
moveWithMorbidity;
moveUntilBlocked;
};
end;

def pauseAtRandom =
r <- random 3;
if (r == 0) {
r2 <- random 12;
wait $ 6 + r2;
} {}
end;

def returnHome = \homeLoc.
nextDir <- path (inL ()) (inL homeLoc);
case nextDir return $ goHomeDir $ returnHome homeLoc;
end;

def pursueFood = \hadSensedFood. \homeLoc.
nextDir <- path (inR 5) (inR "oats");
case nextDir (\_. if hadSensedFood {returnHome homeLoc} {return ()}) $
goFoodDir $ pursueFood true homeLoc;
end;

def doMovement = \startLoc.
findGoodDirection;
moveUntilBlocked;
pauseAtRandom;
pursueFood false startLoc;
end;

/** Loop */
def go = \startLoc.
doMovement startLoc;
go startLoc;
end;

startLoc <- whereami;
go startLoc;
191 changes: 191 additions & 0 deletions data/scenarios/Challenges/Ranching/_pied-piper/solution.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
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 uTurn = \d.
turn d;
move;
turn d;
end;

/**
Starting at bottom right of field
*/
def harvestField = \fieldWidth.
intersperse fieldWidth move harvest;
uTurn right;
intersperse fieldWidth move harvest;
uTurn left;
intersperse fieldWidth move harvest;
uTurn right;
intersperse fieldWidth move harvest;
end;

def makeOatsCrumb = \spacing.
place "oats";
doN spacing move;
end;

def waitUntilRatDisappeared =
found <- scout east;
if found {
wait 1;
waitUntilRatDisappeared;
} {};
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 (segments * spacing) move;
turn back;
end;

def placeHorizontalTrail = \horizontalSpacing.
turn east;
doN (2*horizontalSpacing) move;
place "oats";
turn back;
doN horizontalSpacing move;
place "oats";
doN horizontalSpacing move;
turn left;
end;

def waitForRatToPass =

// Wait until the rat ate this crumb
watch down;
wait 2000;
waitUntilRatDisappeared;
end;

def makeTrails =
let spacing = 4 in
let segments = 5 in

wait 30;
placeHorizontalTrail 5;
makeOatsTrail spacing $ segments + 1;
end;

def getKey =
turn east;
doN 15 move;
turn right;
move;
_k <- grab;
turn right;
doN 5 move;
turn right;
doN 6 move;
turn left;
doN 18 move;
turn left;
doN 20 move;
turn right;
doN 2 move;
use "unlocker" forward;
doN 6 move;
turn right;
doN 8 move;
turn left;
move;
turn right;
doN 6 move;
turn left;
move;
end;

def placeMold = \moldItem.
turn east;
doN 11 move;
sow moldItem;
end;

def go =
getKey;
harvestField 20;

turn left;
doN 2 move;
turn left;
harvestField 20;


move;
turn right;
doN 14 move;
turn left;

// Get the mold
doN 4 move;
turn left;
doN 3 move;
moldItem <- grab;
turn back;
doN 3 move;

turn right;
doN 3 move;
turn left;

// Head back to the house
doN 8 move;
turn left;
doN 8 move;
turn left;

// Start laying trail
intersperse 5 (doN 4 move) $ place "oats";
placeHorizontalTrail 5;

waitForRatToPass;

makeTrails;
waitForRatToPass;


makeOatsTrail 4 10;
placeHorizontalTrail 5;
waitForRatToPass;

makeOatsTrail 4 12;
placeHorizontalTrail 5;
waitForRatToPass;

turn east;
doN 2 move;

placeHorizontalTrail 4;
makeOatsTrail 4 4;
waitForRatToPass;

makeOatsTrail 4 6;
placeHorizontalTrail 4;

waitForRatToPass;
makeOatsTrail 4 10;
placeHorizontalTrail 4;


waitForRatToPass;
makeOatsTrail 4 12;
placeHorizontalTrail 4;

placeMold moldItem;
end;

go;
Loading
Loading