-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
742 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
capture.yaml | ||
powerset.yaml | ||
fishing.yaml | ||
gated-paddock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
138
data/scenarios/Challenges/Ranching/_fishing/solution.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.