Edwarddv

Find the lines

Apr 14th, 2020
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1.  
  2.     public List<LineBundle> GetAllTheLines(GridPoint startingPoint) // This is the SLOW function
  3.     {
  4.  
  5.         List<LineBundle> linesInProgress = new List<LineBundle>();
  6.  
  7.         List<LineBundle> finalLines = new List<LineBundle>();
  8.  
  9.         linesInProgress.Add(new LineBundle(startingPoint));
  10.  
  11.  
  12.         while (linesInProgress.Count > 0 && maxSteps > 0)
  13.         {
  14.             List<int> removeTheseIndices = new List<int>();
  15.  
  16.             for (int j = linesInProgress.Count - 1; j >= 0; j--)
  17.             {
  18.                 GridPoint[] adjacentPoints = FindAllLegalAdjacentPoints(linesInProgress[j]); // Finds the Legal Grid points nearby
  19.  
  20.                 if (adjacentPoints.Length <= 0) // if there's nowhere else to go, the line is finished
  21.                 {   //transfer lineBundle from linesInProgress to finalLines, so it's no longer part of the calculation
  22.                     finalLines.Add(linesInProgress[j]);
  23.                     removeTheseIndices.Add(j);
  24.                 }
  25.                 else
  26.                 {
  27.  
  28.                     for (int i = 1; i < adjacentPoints.Length; i++) // every legal adjacent point found after the first needs to add a new line to the linesInProgress list
  29.                     {
  30.                         linesInProgress.Add(new LineBundle(linesInProgress[j])); // Make a copy of the line we already have
  31.                         linesInProgress[linesInProgress.Count - 1].AddPoint(adjacentPoints[i]); // Add the newly found points to it
  32.                     }
  33.                     linesInProgress[j].AddPoint(adjacentPoints[0]); // Add the first newly found point to the original line
  34.                 }
  35.             }
  36.  
  37.             for (int i = 0; i < removeTheseIndices.Count; i++) // this loop is forwards even though it's removing, because the indices where added to removeTheseIndices in a reverse for loop above
  38.             {
  39.                 linesInProgress.RemoveAt(removeTheseIndices[i]);
  40.             }
  41.         }
  42.  
  43.         return finalLines;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment