static void Main(string[] args) { string path = @"..\..\TuringMachinePrograms\" + File.ReadAllText(@"..\..\name.txt"); MultytapeTuringMachine.StartFromFile(path); Console.ReadLine(); }
static public void StartFromFile(string filePath) { MultytapeTuringMachine multytapeTuringMachine = null; int tapesAmount = 0; List <List <char> > words = new List <List <char> >(); using (StreamReader file = new StreamReader(filePath)) { while (!file.EndOfStream) { if ((char)file.Peek() == '#') { file.ReadLine(); } else { string line = file.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { if (line.ToLower().Contains("numbers =")) { int index = line.IndexOf('='); tapesAmount = int.Parse(line.Substring(++index)); } else if (line.Contains("word=")) { int index = line.IndexOf('='); words.Add(new List <char>(line.Substring(++index).ToCharArray())); } else if (multytapeTuringMachine == null) { multytapeTuringMachine = new MultytapeTuringMachine(tapesAmount, words); } if (multytapeTuringMachine != null) { string[] parts = line.Split(new char[] { ',', '-' }); int current_state = Convert.ToInt32(parts[0]); string current_symbols = parts[1]; string new_symbols = parts[3]; int new_state = Convert.ToInt32(parts[2]); List <Direct> directs = new List <Direct>(); foreach (var direct in parts[4].ToCharArray()) { if (direct == 'N') { directs.Add(Direct.N); } else if (direct == 'R') { directs.Add(Direct.R); } else if (direct == 'L') { directs.Add(Direct.L); } } multytapeTuringMachine.AddCommand(current_symbols, current_state, new MCommand(new_symbols, new_state, directs)); } } } } } Console.WriteLine(multytapeTuringMachine.Execute()); Console.ReadLine(); }