Advertisement
agmike

Track search using custom stack

Aug 27th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1.     define int StateScan = 0;
  2.     define int StateJnLeft = 1;
  3.     define int StateJnRight = 2;
  4.     define int StateExit = -1;
  5.  
  6.     final RFHumpRoute Scan()
  7.     {
  8.         RFHumpRoute node;
  9.         LTrackSearch it = new LTrackSearch().DistanceLimit(4000.0f)
  10.                                             .SleepAfter(10000)
  11.                                             .DepthLimit(50)
  12.                                             .Begin(Owner, LTrackSearch.Forward, 0));
  13.         while (true) {
  14.             switch (it.State()) {
  15.                 default: break;
  16.                 case StateScan: {
  17.                     if (it.MoveNextTrackside()) {
  18.                         RFHumpMarker marker = cast <RFHumpMarker> it.CurrentTrackside();
  19.                         if (marker and marker.HumpTrack >= 0) {
  20.                             if (marker.HumpTrack > 0) {
  21.                                 node = new RFHumpRoute();
  22.                                 node.TrackNumber = marker.HumpTrack;
  23.                                 node.Marker = marker;
  24.                             }
  25.                             it.PopState();
  26.                         }
  27.                         else if (it.OnJunction()) {
  28.                             int dir = it.GetArrivedDirection();
  29.                             if  (dir == LTrackSearch.Backward) {
  30.                                 node = new RFHumpRoute();
  31.                                 node.JnId = junc.GetId();
  32.                                 it.SetState(StateJnLeft, node);
  33.                                 it.PushState();
  34.                                 it.SetState(StateScan);
  35.                                 it.SetDirection(LTrackSearch.Left);
  36.                             }
  37.                         }
  38.                     }
  39.                     else
  40.                         it.SetState(StateExit, null);
  41.                     continue;
  42.                 }
  43.                 case StateJnLeft: {
  44.                     RFHumpRoute parent = cast <RFHumpRoute> it.StateData();
  45.                     parent.Left = node;
  46.                     it.SetState(StateJnRight);
  47.                     it.PushState();
  48.                     it.SetState(StateScan);
  49.                     it.SetDirection(LTrackSearch.Right);
  50.                     continue;
  51.                 }
  52.                 case StateJnRight: {
  53.                     RFHumpRoute parent = cast <RFHumpRoute> it.StateData();
  54.                     parent.Right = node;
  55.                     node = parent;
  56.                     it.PopState();
  57.                     continue;
  58.                 }
  59.             }
  60.         }
  61.         return node;
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement