public void Run() { string[] inputs = Inputs.ToArray(); List <int> positions = new List <int>(); for (int i = 0; i < N; i++) { int b = int.Parse(inputs[i]); positions.Add(b); Console.Error.WriteLine($"\"{b}\","); } int max = 0; for (int i = 0; i < 2; i++) { Duct duct = new Duct(L, positions, i == 0); Console.Error.WriteLine(duct.ToString()); int times = 0; while (duct.HasRobots) { duct.Run(); duct.Remove(); Console.Error.WriteLine(duct.ToString()); times++; } times--; if (times > max) { max = times; } } Console.WriteLine(max); }
public void Move(Duct duct) { this.TurnPlayed = true; if (OnLeft) { this.X--; if (duct.Robots.Any(x => ((x.X == this.X - 1 && !x.TurnPlayed) || (x.X == this.X && x.TurnPlayed)) && x.OnLeft != this.OnLeft)) { this.NeedToTurn = true; } } else { this.X++; if (duct.Robots.Any(x => ((x.X == this.X + 1 && !x.TurnPlayed) || (x.X == this.X && x.TurnPlayed)) && x.OnLeft != this.OnLeft)) { this.NeedToTurn = true; } } }