private IsInRoute : Grid`Point ==> bool
IsInRoute(p) ==
( let r = conc routes in ifcard {r(x) | x insetinds r & r(x) = p} > 0 thenreturntrue elsereturnfalse
);
-- operations moving or changing the location
private StartNewRoute : () ==> ()
StartNewRoute() ==
( let r = routes(len routes) in iflen r > 1 then
(
routes := routes ^ [r(1,...,len routes(len routes)-1)];
);
);
public ReturnToBase : () ==> ()
ReturnToBase() == skip;
private Move : Grid`Point ==> ()
Move(p) == duration(1000)
( let r = routes(len routes) in routes(len routes) := r ^ [p]
)
pre GetBatUsage()*2 <= batCap and batCap > 1 and let cp = routes(len routes)(len routes(len routes)) in p.X <> cp.X or p.Y <> cp.Y post p = routes(len routes)(len routes(len routes));
if FindRouteToDestination() then
(
Robot`dataReader.Read();
Util`PrintDebug("Succes");
) else
(
Util`PrintDebug("No route found, has reached dead end");
);
ReturnToBase();
private FindRouteToDestination : () ==> bool
FindRouteToDestination () ==
( whilenot IsDestination(GetPos()) and GetBatUsage()*2 <= batCap do
( let neighbourPoints = {n|n inset GetNeighbourPoints()
& workingGrid.IsValidGridPoint(n)} in ifcard neighbourPoints > 0 then
(
DiscoverUnknownNeighbourPoints(neighbourPoints); let nextMove = GetNextMove(neighbourPoints) in if nextMove <> nilthen
(
Move(nextMove);
Util`PrintDebug("Moved to pos:");
Util`PrintValue(GetPos())
) else
( if DoesRouteHaveMoreOptions() then
RestartNewRoute() else returnfalse; -- no routes to destination. Dead end
);
) else
RestartNewRoute();
); returntrue; -- route found
);
private DiscoverUnknownNeighbourPoints : setof Grid`Point ==> ()
DiscoverUnknownNeighbourPoints(neighbourPoints) ==
( let unknownPoints = {p| p inset neighbourPoints
& workingGrid.GetPointAvalibility(p.X,p.Y)=<Unknown>} in
( let knownMappings = { p |-> obs.GetPointAvalibility(p)
| obs inset obsSensors, p inset unknownPoints
& obs.GetDirection() = GetPointDirection(p)} in
workingGrid.SetPointMP(knownMappings)
);
) preforall p inset neighbourPoints & workingGrid.IsValidGridPoint(p);
public SetDiscoverInfo: Grid`Point * Grid`Point * int ==> ()
SetDiscoverInfo(startingPoint, destination, batCapacity) ==
(
workingGrid := new Grid(startingPoint, MAX_POINT);
workingGrid.SetPointMP({startingPoint |-> <Free>});
batCap:= batCapacity;
dest:= destination;
routes := [ [startingPoint] ];--first route first point = startingPoint
) pre ValidatePoint(MAX_POINT,destination) and
ValidatePoint(MAX_POINT, startingPoint) and
batCapacity >=2;
public AddObstacleSensor: ObstacleSensor ==> ()
AddObstacleSensor(obs) ==
obsSensors := obsSensors union {obs};
public isFinished : () ==> ()
isFinished () == skip;
sync per isFinished => not busy;
thread while busy do
( let res = FindRoute() in
World`env.handleEvent(res.#1, res.#2, res.#3, res.#4);
busy := false;
);
sync
per FindRoute => #fin(SetDiscoverInfo) > #fin(FindRoute);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.