From 1910094e27c0c46df5c77ae90aeab562648e77f6 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 10 Jul 2023 11:08:13 +0200 Subject: [PATCH] Created simple random selection bot. --- Bobo.Systems.Maze.Console/Program.cs | 40 +++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/Bobo.Systems.Maze.Console/Program.cs b/Bobo.Systems.Maze.Console/Program.cs index a5521af..2a93107 100644 --- a/Bobo.Systems.Maze.Console/Program.cs +++ b/Bobo.Systems.Maze.Console/Program.cs @@ -7,6 +7,7 @@ string apiAuthorization = "HTI Thanks You [OZL]"; string baseUrl = @"https://maze.hightechict.nl/"; string username = "Hi Hightech!"; +string mazeName = "Example Maze"; Console.WriteLine("Starting bot..."); @@ -34,15 +35,42 @@ if (!registered) Console.WriteLine($"Player '{username}' registered"); -PossibleActionsAndCurrentScore result = await mazeClient.EnterMaze("Test"); +Random random = new Random(); + +Console.WriteLine($"Entering maze '{mazeName}'"); +PossibleActionsAndCurrentScore result = await mazeClient.EnterMaze(mazeName); -ConsoleKeyInfo input; do { - input = Console.ReadKey(); - input. -} -while (result != null); + 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)) + { + Console.WriteLine("All adjacent tiles have been visited! Selecting next path random."); + } + else + { + Console.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]; + + Console.WriteLine($"Moving {moveAction.Direction}, I have {(!moveAction.HasBeenVisited ? "not" : string.Empty)} been here."); + + result = await mazeClient.Move(moveAction.Direction); + + Console.WriteLine($"New tile has {(!result.CanExitMazeHere ? "no" : string.Empty)} exit."); + +} while (!result.CanExitMazeHere); + +await mazeClient.ExitMaze(); + +Console.WriteLine($"Exited the maze!"); async Task RegisterPlayer(string username, bool reset = false) {