packages feed

swarm-0.6.0.0: data/scenarios/Testing/836-pathfinding/_836-automatic-waypoint-navigation/patrol.sw

def goDir = \f. \r.
  let d = fst r in
  if (d == down) {
    eggHere <- ishere "egg";
    if eggHere {grab; return ()} {};
    return ()
  } {
    turn d;

    // An obstruction might arise after
    // navigation direction is determined
    // but before we move.
    try {
      move;
    } {};
    f;
  }
  end;

def followRoute = \loc.
    nextDir <- path (inL ()) (inL loc);
    case nextDir return $ goDir $ followRoute loc;
    end;

def visitNextWaypoint = \nextWpIdx.
    nextWaypointQuery <- waypoint "wp" nextWpIdx;
    followRoute $ snd nextWaypointQuery;

    visitNextWaypoint $ nextWpIdx + 1;
    end;

def go =
    visitNextWaypoint 0;
    end;

go;