Beispiel #1
0
        public void Setup()
        {
            Client = new BattleBotClient
            {
                OnError = (error, details) =>
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(error + "\n" + JsonConvert.SerializeObject(details));
                },
                OnReady = () =>
                {
                    Console.WriteLine("Ready! Token: " + Client.Token);
                    Client.JoinArena(new JoinArenaInfo()
                    {
                        Room         = "GreyTestingRoom",
                        Password     = "",
                        ClientName   = "GuyInGrey's AI",
                        BattleCount  = 1,
                        Team         = 1,
                        RoomCapacity = 2,
                        StartTime    = DateTime.Now.AddMinutes(5),
                    });
                },
                OnGameEnd = (winner, rounds) =>
                {
                    Console.WriteLine($"{winner} has won the game! ({rounds} rounds)");
                },
                OnTurn = (turnInfo, response, clientBot) =>
                {
                    response.SetScanner(60m);
                    var nearestObstacle = Client.Arena.Obstacles.GetNearest(Client.Arena.ClientBot);
                    if (Debug)
                    {
                        Console.WriteLine($"BotID: {clientBot.ID}; Nearest obstacle: {nearestObstacle.ID}");
                    }

                    var angle = clientBot.Position.AngleTo(nearestObstacle.Position);
                    angle = (angle + 180) % 360;

                    if (clientBot.Heading != angle)
                    {
                        response.SetMovement(MovementType.Turn, angle);
                        if (Debug)
                        {
                            Console.WriteLine($"Turning to {nearestObstacle.ID}; Angle {angle}");
                        }
                    }
                    else
                    {
                        response.SetMovement(MovementType.MoveForward, 0.05m);
                        if (Debug)
                        {
                            Console.WriteLine($"Moving to {nearestObstacle.ID}; Distance 4");
                        }
                    }

                    //if (clientBot.Position.DistanceTo(nearestObstacle.Position) > 5)
                    //{
                    //    var angle = clientBot.Position.AngleTo(nearestObstacle.Position);
                    //    angle = (angle + 180) % 360;
                    //    if (clientBot.Heading != angle)
                    //    {
                    //        response.SetMovement(MovementType.Turn, angle);
                    //        if (Debug) { Console.WriteLine($"Turning to {nearestObstacle.ID}; Angle {angle}"); }
                    //    }
                    //    else
                    //    {
                    //        response.SetMovement(MovementType.MoveForward, 4);
                    //        if (Debug) { Console.WriteLine($"Moving to {nearestObstacle.ID}; Distance 4"); }
                    //    }
                    //}

                    response.SetWeapon(WeaponType.Mortar,
                                       clientBot.Position.AngleTo(nearestObstacle.Position),
                                       clientBot.Position.DistanceTo(nearestObstacle.Position));
                },
            };
            Client.Socket.OnMessageSent     += Socket_OnMessageSend;
            Client.Socket.OnMessageReceived += Socket_OnMessageReceived;
            Client.Start(@"ws://ldsgamers.com:3000");
            _ = RunPings();
            Art.TextFont(Art.CreateFont("Consolas", 0.2f));
        }