From 88bc7b92168b31a74a57da5bdf85c20d7bf9003f Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 10 Jul 2023 12:17:05 +0200 Subject: [PATCH] Moved simple bot code to own class --- Bobo.Systems.Maze.Console/Program.cs | 39 +++------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/Bobo.Systems.Maze.Console/Program.cs b/Bobo.Systems.Maze.Console/Program.cs index 2a93107..a93c787 100644 --- a/Bobo.Systems.Maze.Console/Program.cs +++ b/Bobo.Systems.Maze.Console/Program.cs @@ -1,7 +1,7 @@ // See https://aka.ms/new-console-template for more information +using Bobo.System.Maze.Console.Bot; using HightechICT.Amazeing.Client.Rest; using System.Net; -using System.Xml.Linq; string apiAuthorization = "HTI Thanks You [OZL]"; string baseUrl = @"https://maze.hightechict.nl/"; @@ -35,42 +35,9 @@ if (!registered) Console.WriteLine($"Player '{username}' registered"); -Random random = new Random(); +Console.WriteLine($"Starting SimpleBot"); -Console.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)) - { - 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!"); +await SimpleBot.Run(mazeName, mazeClient); async Task RegisterPlayer(string username, bool reset = false) {