Skip to content

Commit

Permalink
fix more scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jan 5, 2025
1 parent bb4f47b commit ce710bd
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 89 deletions.
40 changes: 20 additions & 20 deletions data/scenarios/Challenges/Ranching/_fishing/hauler.sw
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ def intersperse = \n. \f2. \f1. if (n > 0) {
} {};
end;

def isEnclosureFull = \idx.
foundBox <- structure "rubbish enclosure" idx;
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;
);
def isEnclosureFull : Int * Int -> Cmd Bool = \encl.
prevLoc <- whereami;

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

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 any : (a -> Cmd Bool) -> (rec l. Unit + a * l) -> Cmd Bool = \p. \l.
case l
(\_. return false)
(\c. b <- p (fst c); if b {return true} {any p (snd c)})
end;

def isEitherEnclosureFull =
full1 <- isEnclosureFull 0;
full2 <- isEnclosureFull 1;
return $ full1 || full2;
enclosures <- structures "rubbish enclosure";
any isEnclosureFull enclosures
end;

def tryGrab =
Expand Down
24 changes: 6 additions & 18 deletions data/scenarios/Challenges/Ranching/_fishing/solution.sw
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,11 @@ def harvestIngredients =
move;
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 find : (a -> Cmd Bool) -> (rec l. Unit + a * l) -> Cmd (Unit + a) = \p. \l.
case l
(\_. return (inl ()))
(\cons. h <- p (fst cons); if h {return $ inr (fst cons)} {find p (snd cons)})
end

def tryPlace = \item.
try {
Expand Down Expand Up @@ -131,7 +119,7 @@ def returnToCorner =
def unloadTrash =
try {
placeSerpentine (
item <- getJunkItem 0;
item <- find has (tagmembers "junk");
case item (\_. fail "done") (\item. place item);
);
watch down;
Expand Down
68 changes: 27 additions & 41 deletions data/scenarios/Challenges/Ranching/fishing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,14 @@ objectives:
Otherwise, when the enclosure becomes full, the trash
hauler will come to empty it.
condition: |
// Returns true if prohibited item is in inventory.
def checkProhibited = \idx.
result <- tagmembers "junk" idx;
let totalCount = fst result in
let member = snd result in
let nextIdx = idx + 1 in
def hasAny : (rec l. Unit + Text * l) -> Cmd Bool = \items.
case items
(\_. return false)
(\c. b <- has (fst c); if b {return true} {hasAny (snd c)})
end;
hasProhibited <- as base {has member};
if hasProhibited {
return false;
} {
if (nextIdx < totalCount) {
checkProhibited nextIdx;
} {
return true;
}
}
end;
checkProhibited 0;
let prohibited = tagmembers "junk" in
h <- hasAny prohibited; return (not h)
- teaser: No littering
id: littered
hidden: true
Expand All @@ -89,33 +77,33 @@ objectives:
- |
Note that certain items can be burned with a `torch`{=entity} to make room.
condition: |
def locIsInsideEnclosure = \loc. \dims. \idx.
foundBox <- structure "rubbish enclosure" idx;
case foundBox (\_. return false) (\enclosure.
let boxPos = snd enclosure in
return $ snd loc >= snd boxPos
&& snd loc < snd dims + snd boxPos
&& fst loc >= fst boxPos
&& fst loc < fst dims + fst boxPos;
);
def locIsInsideEnclosure = \loc. \dims. \boxPos.
return $ snd loc >= snd boxPos
&& snd loc < snd dims + snd boxPos
&& fst loc >= fst boxPos
&& fst loc < fst dims + fst boxPos;
end;
def junkOutsideEnclosure =
result <- scan down;
case result (\_. return false) (\item.
isJunk <- hastag item "junk";
let isJunk = hastag item "junk" in
if isJunk {
foundBox <- structure "rubbish enclosure" 0;
enclosures <- structures "rubbish enclosure";
case foundBox (\_. return false) (\enclosure.
case enclosures (\_. return false) (\cons0.
let enclosure0 = fst cons0 in
case (snd cons0) (\_. return false) (\cons1.
let enclosure1 = fst cons1 in
dims <- floorplan "rubbish enclosure";
loc <- whereami;
dims <- floorplan "rubbish enclosure";
loc <- whereami;
insideFirst <- locIsInsideEnclosure loc dims 0;
insideSecond <- locIsInsideEnclosure loc dims 1;
return $ not $ insideFirst || insideSecond;
);
insideFirst <- locIsInsideEnclosure loc dims enclosure0;
insideSecond <- locIsInsideEnclosure loc dims enclosure1;
return $ not $ insideFirst || insideSecond;
)
)
} {
return false;
};
Expand Down Expand Up @@ -208,13 +196,11 @@ entities:
description:
- |
Can tell you if something is `junk`{=tag}
via the `hastag` command. E.g.:
via the `hastag` function. E.g.:
- |
`hastag "car tire" "junk"`
- |
Also allows you to iterate over the list of junk, e.g.:
- |
`tagmembers "junk" 0`
Also allows you to get the list of all junk items with `tagmembers "junk"`.
capabilities: [hastag, tagmembers]
- name: torch
display:
Expand Down
5 changes: 4 additions & 1 deletion data/scenarios/Challenges/_dna/lab.sw
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def waitForCloneableOrganism =

waitUntilOccupied;

scan down;
thingHere <- scan down;
return $ case thingHere (\x. inL x) (\item.
if (hastag item "organism") {inR item} {inL ()}
)
);

case organism (\_.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def goToLocation = \currentLoc. \absoluteDestination.

def visitNextWaypoint = \nextWpIdx.
loc <- whereami;
nextWaypointQuery <- waypoint "wp" nextWpIdx;
goToLocation loc $ snd nextWaypointQuery;
let nextWaypointQuery = waypoint "wp" nextWpIdx in
goToLocation loc $ nextWaypointQuery;

visitNextWaypoint $ nextWpIdx + 1;
end;

def go =
waypointQuery <- waypoint "wp" 0;
teleport self $ snd waypointQuery;
let waypointQuery = waypoint "wp" 0 in
teleport self $ waypointQuery;
visitNextWaypoint 1;
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def followRoute = \loc.
end;

def visitNextWaypoint = \nextWpIdx.
nextWaypointQuery <- waypoint "wp" nextWpIdx;
followRoute $ snd nextWaypointQuery;
let nextWaypointQuery = waypoint "wp" nextWpIdx in
followRoute $ nextWaypointQuery;

visitNextWaypoint $ nextWpIdx + 1;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def visitNextWaypoint = \nextWpIdx.
} {};
} {};
watch down;
nextWaypointQuery <- waypoint "wp" nextWpIdx;
teleport self $ snd nextWaypointQuery;
let nextWaypointQuery = waypoint "wp" nextWpIdx in
teleport self $ nextWaypointQuery;
wait 1000;
visitNextWaypoint $ nextWpIdx + 1;
end;

visitNextWaypoint 0;
visitNextWaypoint 0;

0 comments on commit ce710bd

Please sign in to comment.