Moved simple bot code to own class
This commit is contained in:
parent
1910094e27
commit
88bc7b9216
@ -1,7 +1,7 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
using Bobo.System.Maze.Console.Bot;
|
||||||
using HightechICT.Amazeing.Client.Rest;
|
using HightechICT.Amazeing.Client.Rest;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
string apiAuthorization = "HTI Thanks You [OZL]";
|
string apiAuthorization = "HTI Thanks You [OZL]";
|
||||||
string baseUrl = @"https://maze.hightechict.nl/";
|
string baseUrl = @"https://maze.hightechict.nl/";
|
||||||
@ -35,42 +35,9 @@ if (!registered)
|
|||||||
|
|
||||||
Console.WriteLine($"Player '{username}' registered");
|
Console.WriteLine($"Player '{username}' registered");
|
||||||
|
|
||||||
Random random = new Random();
|
Console.WriteLine($"Starting SimpleBot");
|
||||||
|
|
||||||
Console.WriteLine($"Entering maze '{mazeName}'");
|
await SimpleBot.Run(mazeName, mazeClient);
|
||||||
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!");
|
|
||||||
|
|
||||||
async Task<bool> RegisterPlayer(string username, bool reset = false)
|
async Task<bool> RegisterPlayer(string username, bool reset = false)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user