public string[] FindGreedyPath(bool resetAfter = true) { Reset(); int steps = 0; var path = new List <string>(); bool finished = false; while (!finished) { var neighbourTiles = layout.GetNeighbours(X, Y, false); if (neighbourTiles[Facing] == '#') { StepForward(); steps++; } else { if (steps > 0) { path.Add(steps.ToString()); } steps = 0; var left = neighbourTiles[Facing.CounterClockWiseByQuarter()]; var right = neighbourTiles[Facing.ClockWiseByQuarter()]; if (right == '#') { path.Add("R"); TurnRight(); } else if (left == '#') { path.Add("L"); TurnLeft(); } else { finished = true; } } } if (!HasVisitedAllScaffolds()) { throw new Exception("Finished greedy path search without covering all scaffolds, make sure scaffold layout is valid!"); } if (resetAfter) { Reset(); } return(path.ToArray()); }
public void TurnLeft() { Facing = Facing.CounterClockWiseByQuarter(); }