private static void Main() { OSSpecificConfiguration(); var delay = MachineStepDelayPrompt.Show(); var files = ProgramEntryPrompt.Show(); Console.Clear(); _machines = files.Select(TuringFileParser.CreateMachine).Where(machine => machine != null).ToList(); Console.WriteLine("Press any key to begin Turing Machine simulation..."); Console.ReadKey(); Console.Clear(); _painter = new TuringPainter(); KeyboardInput.OnUpArrowPressed += _painter.DecrementRootMachine; KeyboardInput.OnDownArrowPressed += _painter.IncrementRootMachine; KeyboardInput.OnEscapePressed += ExitTuringSimulator; KeyboardInput.BeginCaptureInput(); foreach (var machine in _machines) { machine.OnTuringStep += UpdateData(_painter); machine.Run(delay); } using (new HiddenConsoleCursor()) { while (_machines.Any(machine => machine.IsRunning)) { _painter.Paint(); } _painter.Paint(); } Console.SetCursorPosition(0, Console.WindowHeight); Console.Write("Simulation has finished. Press any key to exit the program..."); Console.ReadKey(); }
private static Action <TuringMachine> UpdateData(TuringPainter painter) { return(machine => painter.MachineData[machine.Id] = TuringPainter.ConstructRepresentation(machine)); }