private async Task GoToExit(PossibleActionsAndCurrentScore options) { while (true) { // Looking for exit! if (options.CanExitMazeHere) { //Console.WriteLine("Enter please"); //Console.ReadLine(); await _client.ExitMaze(); return; } // Looking for known route to exit point var stack = _exitCrumbs.OrderBy(st => st.Count).FirstOrDefault(); if (stack != null) { var dir = stack.Peek(); var step = ReverseDir(dir); options = await MakeMove(step, _exitCrumbs, _collectCrumbs, _crawlCrumbs); continue; } // No known EP. Find the most useful direction to hopefully find one var mostUsefulDirection = MostUsefulDirForLocatingExitPoint(options, _crawlCrumbs); if (mostUsefulDirection != null) { options = await MakeMove(mostUsefulDirection.Direction, _exitCrumbs, _collectCrumbs, _crawlCrumbs); continue; } // Back-track if no new directions were found if (_crawlCrumbs.Any()) { var dir = ReverseDir(_crawlCrumbs.Peek()); options = await MakeMove(dir, _exitCrumbs, _collectCrumbs, _crawlCrumbs); continue; } Console.WriteLine("No possible route to Exit Point!"); } }
public async Task ExitMaze() { IncreaseInvocationCount(); await _amazeingClientImplementation.ExitMaze(); }