Skip to content

Commit

Permalink
fishing scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Nov 20, 2023
1 parent 01a5b07 commit 6344f96
Show file tree
Hide file tree
Showing 6 changed files with 742 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/scenarios/Challenges/Ranching/00-ORDER.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
capture.yaml
powerset.yaml
fishing.yaml
gated-paddock.yaml
68 changes: 68 additions & 0 deletions data/scenarios/Challenges/Ranching/_fishing/hauler.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def isEnclosureFull =
foundBox <- structure "rubbish enclosure" 0;
case foundBox (\_. return false) (\enclosure.
let boxPos = snd enclosure in

prevLoc <- whereami;

dims <- floorplan "rubbish enclosure";
teleport self boxPos;

c <- density ((0, 0), dims);
let area = fst dims * snd dims in
let notFull = c < area in

teleport self prevLoc;
return $ not notFull;
);
end;

def tryGrab =
try {
grab;
return ()
} {};
end;

def waitUntilEnclosureFull =

isFull <- instant isEnclosureFull;
if isFull {
turn south;
doN 13 move;
turn right;
doN 3 move;
turn right;
doN 2 move;
turn left;

doN 2 (tryGrab; move;);
tryGrab;
turn left;
move;
turn left;
doN 2 (tryGrab; move;);
tryGrab;

// Leave again
turn right;
move;
turn left;
doN 3 move;
turn left;
doN 13 move;
turn back;
} {
wait 10;
waitUntilEnclosureFull;
}
end;

def go =
waitUntilEnclosureFull;
go;
end;

go;
24 changes: 24 additions & 0 deletions data/scenarios/Challenges/Ranching/_fishing/shark.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
Swims back and forth forever.
*/

def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def swim =
appear "^";
doN 3 (move; wait 3);
turn back;
wait 15;
doN 3 (move; wait 3);
turn back;
appear " ";
end;

def go =
waitR <- random 100;
wait $ 50 + waitR;
swim;
go;
end;

go;
138 changes: 138 additions & 0 deletions data/scenarios/Challenges/Ranching/_fishing/solution.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def makeRoll =
make "nori";
make "california roll";
end;

def checkIngredients =
hasTuna <- has "crab";
hasSeaweed <- has "seaweed";
return $ hasTuna && hasSeaweed;
end;

def catchFish = \rod.
use rod forward;
ready <- checkIngredients;
if ready {
makeRoll;
} {
catchFish rod;
};
end;

def harvestIngredients =
turn back;
doN 4 move;
turn right;
move;
harvest;
turn back;
doN 2 move;
harvest;
doN 3 move;
harvest;
turn left;
doN 7 move;
turn left;
end;

def getJunkItem = \idx.
result <- tagmembers "junk" idx;
let totalCount = fst result in
let member = snd result in
let nextIdx = idx + 1 in

hasProhibited <- has member;
if hasProhibited {
return $ inr member;
} {
if (nextIdx < totalCount) {
getJunkItem nextIdx;
} {
return $ inl ();
}
}
end;

def tryPlace = \item.
try {
place item;
} {};
end;

/**
Precondition: facing north in lower-left corner of enclosure
Navigates a serpentine pattern through the space to
place items.
*/
def placeSerpentine = \placeFunc.
placeFunc;
move;
placeFunc;
turn right;
move;
placeFunc;
turn right;
move;
placeFunc;
turn left;
move;
placeFunc;
turn left;
move;
placeFunc;
end;

def returnToCorner =
turn back;
move; move;
turn right;
move; move;
turn right;
end;

def unloadTrash =
try {
placeSerpentine (
item <- getJunkItem 0;
case item (\_. fail "done") (\item. place item);
);
watch forward;
wait 1000;

wait 50;
unloadTrash;
} {};
end;

def disposeTrash =
turn back;
doN 5 move;
turn left;
doN 11 move;
turn left;
move;

doN 2 (
placeSerpentine $ tryPlace "car tire";
returnToCorner;
ignite forward;
wait 80;
move;
);

unloadTrash;
end;

def go =
harvestIngredients;
let rod = "fishing tackle" in
make rod;
equip rod;
catchFish rod;
disposeTrash;
end;

go;
Loading

0 comments on commit 6344f96

Please sign in to comment.