mirror of
https://github.com/swarm-game/swarm.git
synced 2024-09-11 14:46:33 +03:00
return distance from path command (#1698)
Augments #836. Should have access to the remaining distance, since it's available internally. This will help in implementing #1696.
This commit is contained in:
parent
358e60bb87
commit
ccd64fcff8
@ -34,7 +34,8 @@ robots:
|
||||
- treads
|
||||
- wayfinder
|
||||
solution: |
|
||||
def goDir = \f. \d.
|
||||
def goDir = \f. \result.
|
||||
let d = fst result in
|
||||
if (d == down) {grab; f;} {turn d; move; f;}
|
||||
end;
|
||||
|
||||
@ -52,7 +53,7 @@ entities:
|
||||
- |
|
||||
Enables the `path` command:
|
||||
- |
|
||||
`path : (unit + int) -> ((int * int) + text) -> cmd (unit + dir)`
|
||||
`path : (unit + int) -> ((int * int) + text) -> cmd (unit + (dir * int))`
|
||||
- |
|
||||
Optionally supply a distance limit as the first argument, and
|
||||
supply either a location (`inL`) or an entity (`inR`) as the second argument.
|
||||
|
@ -15,7 +15,8 @@ objectives:
|
||||
return $ fCount >= 4;
|
||||
};
|
||||
solution: |
|
||||
def goDir = \f. \d.
|
||||
def goDir = \f. \result.
|
||||
let d = fst result in
|
||||
if (d == down) {grab; f;} {turn d; move; f;}
|
||||
end;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
def goDir = \f. \d.
|
||||
def goDir = \f. \r.
|
||||
let d = fst r in
|
||||
if (d == down) {
|
||||
eggHere <- ishere "egg";
|
||||
if eggHere {grab; return ()} {};
|
||||
|
@ -1,4 +1,5 @@
|
||||
def goDir = \f. \d.
|
||||
def goDir = \f. \r.
|
||||
let d = fst r in
|
||||
if (d == down) {
|
||||
grab; return ()
|
||||
} {
|
||||
|
@ -1,4 +1,5 @@
|
||||
def goDir = \goalItem. \f. \d.
|
||||
def goDir = \goalItem. \f. \r.
|
||||
let d = fst r in
|
||||
if (d == down) {
|
||||
grab; return ()
|
||||
} {
|
||||
|
@ -1,4 +1,5 @@
|
||||
def goDir = \f. \d.
|
||||
def goDir = \f. \r.
|
||||
let d = fst r in
|
||||
if (d == down) {
|
||||
grab; return ()
|
||||
} {
|
||||
|
@ -64,7 +64,7 @@ import Swarm.Util (hoistMaybe)
|
||||
pathCommand ::
|
||||
HasRobotStepState sig m =>
|
||||
PathfindingParameters (Cosmic Location) ->
|
||||
m (Maybe Direction)
|
||||
m (Maybe (Direction, Int))
|
||||
pathCommand parms = do
|
||||
currentWalkabilityContext <- use walkabilityContext
|
||||
|
||||
@ -72,7 +72,7 @@ pathCommand parms = do
|
||||
eitherCachedPath <- retrieveCachedPath currentWalkabilityContext parms
|
||||
|
||||
case eitherCachedPath of
|
||||
Right foundCachedPath -> return $ Just $ nextDir foundCachedPath
|
||||
Right foundCachedPath -> return $ Just $ mkResult foundCachedPath
|
||||
Left _ -> do
|
||||
-- This is a short-circuiting optimization; if the goal location itself
|
||||
-- is not a walkable cell, then no amount of searching will reach it.
|
||||
@ -86,8 +86,9 @@ pathCommand parms = do
|
||||
foundPath <- hoistMaybe maybeFoundPath
|
||||
-- NOTE: This will not cache the fact that a path was not found.
|
||||
lift $ recordCache (fmap (^. subworld) parms) currentWalkabilityContext $ robotLoc :| foundPath
|
||||
return $ nextDir foundPath
|
||||
return $ mkResult foundPath
|
||||
where
|
||||
mkResult p = (nextDir p, length p)
|
||||
PathfindingParameters maybeDistanceLimit (Cosmic currentSubworld robotLoc) target = parms
|
||||
|
||||
computePath =
|
||||
|
@ -545,7 +545,7 @@ constInfo c = case c of
|
||||
command 2 short . doc "Obtain shortest path to the destination." $
|
||||
[ "Optionally supply a distance limit as the first argument."
|
||||
, "Supply either a location (`inL`) or an entity (`inR`) as the second argument."
|
||||
, "If a path exists, returns the direction to proceed along."
|
||||
, "If a path exists, returns the direction to proceed along and the remaining distance."
|
||||
]
|
||||
Push ->
|
||||
command 1 short . doc "Push an entity forward one step." $
|
||||
|
@ -742,7 +742,7 @@ inferConst c = case c of
|
||||
Selfdestruct -> [tyQ| cmd unit |]
|
||||
Move -> [tyQ| cmd unit |]
|
||||
Backup -> [tyQ| cmd unit |]
|
||||
Path -> [tyQ| (unit + int) -> ((int * int) + text) -> cmd (unit + dir) |]
|
||||
Path -> [tyQ| (unit + int) -> ((int * int) + text) -> cmd (unit + (dir * int)) |]
|
||||
Push -> [tyQ| cmd unit |]
|
||||
Stride -> [tyQ| int -> cmd unit |]
|
||||
Turn -> [tyQ| dir -> cmd unit |]
|
||||
|
Loading…
Reference in New Issue
Block a user