Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<LineBundle> GetAllTheLines(GridPoint startingPoint) // This is the SLOW function
- {
- List<LineBundle> linesInProgress = new List<LineBundle>();
- List<LineBundle> finalLines = new List<LineBundle>();
- linesInProgress.Add(new LineBundle(startingPoint));
- while (linesInProgress.Count > 0 && maxSteps > 0)
- {
- List<int> removeTheseIndices = new List<int>();
- for (int j = linesInProgress.Count - 1; j >= 0; j--)
- {
- GridPoint[] adjacentPoints = FindAllLegalAdjacentPoints(linesInProgress[j]); // Finds the Legal Grid points nearby
- if (adjacentPoints.Length <= 0) // if there's nowhere else to go, the line is finished
- { //transfer lineBundle from linesInProgress to finalLines, so it's no longer part of the calculation
- finalLines.Add(linesInProgress[j]);
- removeTheseIndices.Add(j);
- }
- else
- {
- 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
- {
- linesInProgress.Add(new LineBundle(linesInProgress[j])); // Make a copy of the line we already have
- linesInProgress[linesInProgress.Count - 1].AddPoint(adjacentPoints[i]); // Add the newly found points to it
- }
- linesInProgress[j].AddPoint(adjacentPoints[0]); // Add the first newly found point to the original line
- }
- }
- 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
- {
- linesInProgress.RemoveAt(removeTheseIndices[i]);
- }
- }
- return finalLines;
- }
Advertisement
Add Comment
Please, Sign In to add comment