-
Notifications
You must be signed in to change notification settings - Fork 52
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
3 changed files
with
402 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
def goDir = \f. \r. | ||
let d = fst r in | ||
if (d == down) { | ||
grapesHere <- ishere "grapes"; | ||
if grapesHere { | ||
grab; return () | ||
} {}; | ||
return (); | ||
} { | ||
turn d; | ||
|
||
// An obstruction might arise after | ||
// navigation direction is determined | ||
// but before we move. | ||
try { | ||
move; | ||
} {}; | ||
f; | ||
} | ||
end; | ||
|
||
def followRoute = \item. | ||
nextDir <- path (inL ()) (inR item); | ||
case nextDir return $ goDir $ followRoute item; | ||
end; | ||
|
||
def getGrapes = | ||
let targetItem = "grapes" in | ||
emperorHasThem <- has targetItem; | ||
if emperorHasThem { | ||
say "Tally ho!"; | ||
} { | ||
grapesDropped <- as base { | ||
baseHasThem <- has targetItem; | ||
return $ not baseHasThem; | ||
}; | ||
|
||
if grapesDropped { | ||
followRoute targetItem; | ||
} { | ||
wait 10; | ||
getGrapes; | ||
}; | ||
} | ||
end; | ||
|
||
def avoidSides = | ||
|
||
toLeft <- scan back; | ||
case toLeft return (\_. | ||
turn right; | ||
); | ||
|
||
toRight <- scan back; | ||
case toRight return (\_. | ||
turn left; | ||
); | ||
|
||
behind <- scan back; | ||
case behind return (\_. | ||
isBlocked <- blocked; | ||
if isBlocked {} {move;} | ||
); | ||
|
||
watch forward; | ||
watch back; | ||
watch left; | ||
watch right; | ||
wait 1000; | ||
end; | ||
|
||
def go = | ||
getGrapes; | ||
avoidSides; | ||
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,118 @@ | ||
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 shiftRightForPush = | ||
turn back; | ||
move; | ||
turn left; | ||
move; | ||
turn left; | ||
end; | ||
|
||
/* | ||
Precondition: | ||
Positioned behind the wall, facing it, on the leftmost cell. | ||
*/ | ||
def pushWall = | ||
intersperse 3 shiftRightForPush push; | ||
end; | ||
|
||
def moveToBackWall = | ||
turn back; | ||
doN 5 move; | ||
turn right; | ||
doN 2 move; | ||
turn right; | ||
end; | ||
|
||
def moveRightSide = | ||
turn right; | ||
push; | ||
turn right; | ||
move; | ||
turn left; | ||
move; | ||
turn left; | ||
doN 5 push; | ||
turn right; | ||
move; | ||
turn left; | ||
move; | ||
turn left; | ||
push; | ||
end; | ||
|
||
def moveLeftSide = | ||
doN 4 move; | ||
turn left; | ||
doN 5 move; | ||
turn right; | ||
push; | ||
turn left; | ||
move; | ||
turn right; | ||
move; | ||
turn right; | ||
doN 5 push; | ||
turn left; | ||
move; | ||
turn right; | ||
move; | ||
turn right; | ||
push; | ||
end; | ||
|
||
def initialSetup = | ||
turn south; | ||
doN 3 move; | ||
turn right; | ||
move; | ||
turn right; | ||
end; | ||
|
||
def waitUntilGrapesGrabbed = | ||
itemHere <- scan forward; | ||
case itemHere return (\_. | ||
watch forward; | ||
wait 1000; | ||
waitUntilGrapesGrabbed; | ||
); | ||
end; | ||
|
||
def placeGrapes = | ||
|
||
doN 4 move; | ||
place "grapes"; | ||
turn back; | ||
move; | ||
doN 2 push; | ||
turn back; | ||
doN 2 move; | ||
waitUntilGrapesGrabbed; | ||
|
||
turn back; | ||
doN 4 move; | ||
turn back; | ||
doN 2 push; | ||
end; | ||
|
||
def go = | ||
placeGrapes; | ||
|
||
// initialSetup; | ||
// pushWall; | ||
// moveToBackWall; | ||
// pushWall; | ||
// moveRightSide; | ||
// moveLeftSide; | ||
end; | ||
|
||
go; |
Oops, something went wrong.