public static Bots Load(Stream stream) { var collection = SimulationBotCollection.Load(stream); var bots = new Bots(); bots.AddRange(collection); return(bots); }
public BattleSimulator(MT19937Generator rnd) { File = new FileInfo("parameters.xml"); SearchDepth = AppConfig.Data.SearchDepth; Rnd = rnd; Randomizer = new ParameterRandomizer(rnd); Bots = new Bots(); Results = new ConcurrentQueue <BattlePairing>(); }
private void LogStatus() { Bots.Save(File); var sorted = Bots.ByElo().ToList(); using (var writer = new StreamWriter("parameters.cs", false)) { foreach (var bot in sorted) { writer.WriteLine("// Elo: {0:0}, {1}, ID: {2}, Parent: {3}, Gen: {4}", bot.Elo, bot.Stats, bot.Id, bot.ParentId, bot.Generation); writer.WriteLine(BotData.ParametersToString(bot.DefPars)); writer.WriteLine(); } } }
public void Run() { lock (lockList) { if (File.Exists) { Bots.AddRange(SimulationBotCollection.Load(File)); } if (Bots.Count < 2) { Bots.Clear(); Bots.Add(GetDef()); Bots.Add(GetDef()); BestBot = Bots.GetHighestElo(); } } var keepRunning = true; while (true) { LogRankings(); LogStatus(); if (!keepRunning) { break; } Bots.CloneBots(Randomizer); Bots.Shrink(); var pairings = Bots.GetPairings(Rnd); var copy = pairings.ToList(); if (InParallel) { keepRunning = SimulateParallel(copy); } else { keepRunning = Simulate(copy); } Bots.Process(Results); } }
private void LogRankings() { var sorted = Bots.ByElo().ToList(); BestBot = Bots.GetHighestStableElo(); var parentId = BestBot == null ? -1 : BestBot.Id; Console.Clear(); var max = Math.Min(Console.WindowHeight - 2, Bots.Count); for (var pos = 1; pos <= max; pos++) { var bot = sorted[pos - 1]; if (bot == BestBot) { Console.ForegroundColor = ConsoleColor.Yellow; } else if (bot.IsStable) { Console.ForegroundColor = bot.ParentId == parentId ? ConsoleColor.Green : ConsoleColor.White; } else { Console.ForegroundColor = bot.ParentId == parentId ? ConsoleColor.DarkGreen : ConsoleColor.Gray; } Console.Write("{0,3}", pos); Console.Write(" {0:0000.0}", bot.Elo); Console.Write(", {0}", bot.Stats); Console.Write(", ID: {0,5}", bot.Id); Console.Write(bot.Locked ? '*' : ' '); Console.Write("(par: {0}, gen: {1})", bot.ParentId, bot.Generation); Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); }