private void RemoveBot(int playerIndex) { var botProcess = BotProcesses.FirstOrDefault(b => b.Bot.PlayerIndex == playerIndex); if (botProcess != null) { ActiveBots.TryRemove(playerIndex, out var waitHandle); botProcess.Stop(); BotProcesses.Remove(botProcess); Console.WriteLine($"{botProcess.Bot.Name} removed."); } }
/// <summary> /// Adds a bot to the <see cref="BotProcesses"/> list if the index is not there already. /// </summary> /// <param name="bot"></param> private void AddBot(string name, int team, int playerIndex) { // Only add a bot if botProcesses doesn't contain the index given in the parameters. if (!BotProcesses.Any(b => b.Bot.PlayerIndex == playerIndex)) { var botProcess = new BotProcess <T>(name, team, playerIndex); BotProcesses.Add(botProcess); Console.WriteLine($"Added bot {name} for Team {team + 1}."); var waitHandle = botProcess.Start(GameInterface); ActiveBots.TryAdd(playerIndex, waitHandle); } }