using HightechICT.Amazeing.Client.Rest; using LogConsole = System.Console; namespace Bobo.System.Maze.Bot { public class BumpBot { public static async Task Run(string mazeName, AmazeingClient mazeClient) { Random random = new Random(); LogConsole.WriteLine($"Entering maze '{mazeName}'"); PossibleActionsAndCurrentScore result = await mazeClient.EnterMaze(mazeName); do { await Task.Delay(100); // select a way to go MoveAction[] moves = result.PossibleMoveActions.ToArray(); MoveAction[] notExploredMoves = moves.Any(m => !m.HasBeenVisited) ? moves.Where(m => !m.HasBeenVisited).ToArray() : moves; if (moves.All(m => m.HasBeenVisited)) { LogConsole.WriteLine("All adjacent tiles have been visited! Selecting next path random."); } else { LogConsole.WriteLine($"{string.Join(", ", notExploredMoves.Select(m => m.Direction.ToString()))} have not been visited, selecting next move."); } int selected = random.Next(notExploredMoves.Length - 1); MoveAction moveAction = notExploredMoves[selected]; LogConsole.WriteLine($"Moving {moveAction.Direction}, I have {(!moveAction.HasBeenVisited ? "not" : string.Empty)} been here."); result = await mazeClient.Move(moveAction.Direction); LogConsole.WriteLine($"New tile has {(!result.CanExitMazeHere ? "no" : string.Empty)} exit."); } while (!result.CanExitMazeHere); await mazeClient.ExitMaze(); LogConsole.WriteLine($"Exited the maze!"); } } }