/// <summary> /// Calls the given bot's <see cref="Bot.GetOutput(GameTickPacket)"/> method and /// updates its input through the interface DLL. /// </summary> /// <param name="bot"></param> private void RunBot(Bot bot) { while (true) { try { GameTickPacket gameTickPacket = RLBotInterface.GetGameTickPacket(); Controller botInput = bot.GetOutput(gameTickPacket); RLBotInterface.SetBotInput(botInput, bot.index); } catch (FlatbuffersPacketException) { // Ignore if the packet size is too small. No need to warn the user. } catch (Exception e) { // Don't crash the bot and give the user the details of the exception instead. Console.WriteLine(e.GetType()); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } botRunEvent.WaitOne(); } }
/// <summary> /// Calls the given bot's <see cref="Bot.GetOutput(GameTickPacket)"/> method and /// updates its input through the interface DLL. /// </summary> private void RunBot(Bot bot, AutoResetEvent botRunEvent) { BotLoopRenderer renderer = GetRendererForBot(bot); bot.Renderer = renderer; Console.WriteLine("Waiting for the RLBot Interface to initialize..."); while (!RLBotInterface.IsInitialized()) { Thread.Sleep(100); } Console.WriteLine("The RLBot Interface has been successfully initialized!"); Console.WriteLine("Running the bot loop..."); while (true) { try { renderer.StartPacket(); GameTickPacket gameTickPacket = RLBotInterface.GetGameTickPacket(); Controller botInput = bot.GetOutput(gameTickPacket); RLBotInterface.SetBotInput(botInput, bot.index); renderer.FinishAndSendIfDifferent(); } catch (FlatbuffersPacketException) { // Ignore if the packet size is too small. No need to warn the user. } catch (Exception e) { // Don't crash the bot and give the user the details of the exception instead. Console.WriteLine(e.GetType()); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } botRunEvent.WaitOne(); } }