public static string Search(List <Tuple <ScenarioStep, int> > history, Scenario scenario) { if (history.Count == 0) { return(scenario.Steps[0].Id); } var lastStep = history[history.Count - 1].Item1; var lastVar = history[history.Count - 1].Item2; var nexts = lastStep.Vars[lastVar].Next; foreach (var next in nexts) { ScenarioStep step = scenario.FindStep(next); bool allExists = true; foreach (HistoryItem prev in step.Prev) { if (!history.Exists((Tuple <ScenarioStep, int> item) => item.Item1.Id == prev.Id && item.Item2 == prev.Num)) { allExists = false; break; } } if (allExists) { return(next); } } return("<none>"); }
public static int ProcessStep(ScenarioStep step) { Console.WriteLine(step.Text); for (int i = 1; i <= step.Vars.Count; i++) { Console.Write(i); Console.Write(". "); Console.WriteLine(step.Vars[i - 1].Text); } string ans = ""; int res; while (true) { ans = Console.ReadLine(); bool tryRes = Int32.TryParse(ans, out res); if (tryRes) { if (res > 0 && res <= step.Vars.Count) { break; } } Console.WriteLine("Попробуйте наконец-то попасть по нужной кнопке!!! Этож, блин, слоооожно!!!!!"); } return(res - 1); }
public static void Main(string[] args) { Scenario scenario = ScenarioFilesParser.ParseScenario("test.json"); List <Tuple <ScenarioStep, int> > history = new List <Tuple <ScenarioStep, int> > (); while (true) { string nextId = TransitionSearcher.Search(history, scenario); if (nextId == "<none>") { break; } ScenarioStep nextStep = scenario.FindStep(nextId); if (nextStep == null) { Console.Write("ID "); Console.Write(nextId); Console.Write(" NOT FOUND"); } int var = ConsoleProcessor.ProcessStep(nextStep); history.Add(Tuple.Create(nextStep, var)); } }