-
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
401 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,116 @@ | ||
def checkExpireSelf = | ||
loc <- whereami; | ||
if (snd loc > 6) {selfdestruct} {}; | ||
end; | ||
|
||
|
||
def moveWithMortality = | ||
move; | ||
instant checkExpireSelf; | ||
end; | ||
|
||
def goFoodDir = \f. \r. | ||
// say "in goFoodDir"; | ||
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 { | ||
moveWithMortality; | ||
} {}; | ||
f; | ||
} | ||
end; | ||
|
||
def goHomeDir = \f. \r. | ||
// say "in goHomeDir"; | ||
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 { | ||
moveWithMortality; | ||
} {}; | ||
f; | ||
} | ||
end; | ||
|
||
def findGoodDirection = | ||
// say "in findGoodDirection"; | ||
isBlocked <- blocked; | ||
if isBlocked { | ||
turn left; | ||
findGoodDirection; | ||
} {}; | ||
end; | ||
|
||
def moveUntilBlocked = | ||
isBlocked <- blocked; | ||
if isBlocked { | ||
} { | ||
moveWithMortality; | ||
moveUntilBlocked; | ||
}; | ||
end; | ||
|
||
def pauseAtRandom = | ||
r <- random 3; | ||
if (r == 0) { | ||
r2 <- random 12; | ||
wait $ 6 + r2; | ||
} {} | ||
end; | ||
|
||
def returnHome = \homeLoc. | ||
// say "in returnHome"; | ||
nextDir <- path (inL ()) (inL homeLoc); | ||
case nextDir return $ goHomeDir $ returnHome homeLoc; | ||
end; | ||
|
||
def pursueFood = \hadSensedFood. \homeLoc. | ||
// say $ "in pursueFood. hadSensedFood? " ++ format hadSensedFood; | ||
nextDir <- path (inR 5) (inR "oats"); | ||
case nextDir (\_. if hadSensedFood {returnHome homeLoc} {return ()}) $ | ||
goFoodDir $ pursueFood true homeLoc; | ||
end; | ||
|
||
|
||
def doMovement = \startLoc. | ||
// say "in doMovement"; | ||
checkExpireSelf; | ||
|
||
findGoodDirection; | ||
moveUntilBlocked; | ||
pauseAtRandom; | ||
pursueFood false startLoc; | ||
end; | ||
|
||
/** Loop */ | ||
def go = \startLoc. | ||
doMovement startLoc; | ||
go startLoc; | ||
end; | ||
|
||
startLoc <- whereami; | ||
// let shouldDestruct = !(snd startLoc == -17 && fst startLoc < 19) in | ||
let shouldDestruct = false in | ||
if shouldDestruct { | ||
selfdestruct; | ||
} { | ||
go startLoc; | ||
} |
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,39 @@ | ||
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end; | ||
|
||
def makeOatsCrumb = \spacing. | ||
place "oats"; | ||
doN spacing move; | ||
end; | ||
|
||
|
||
def waitUntilDisappeared = | ||
found <- scout north; | ||
if found { | ||
wait 1; | ||
waitUntilDisappeared; | ||
} {}; | ||
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 - 1)*spacing) move; | ||
turn back; | ||
watch down; | ||
wait 2000; | ||
end; | ||
|
||
def go = | ||
let spacing = 4 in | ||
let segments = 5 in | ||
makeOatsTrail spacing segments; | ||
// Has probably awakened due to rat eating food here. | ||
waitUntilDisappeared; | ||
makeOatsTrail spacing $ segments; | ||
end; | ||
|
||
go; |
Oops, something went wrong.