Beispiel #1
0
 /// <summary>
 /// Exécute la simulation dans son ensemble !
 /// </summary>
 public static async void DoTurns()
 {
     if (turnRunning) return;
     turnRunning = true;
     Console.WriteLine("Running simulator...");
     int turnCount = 0;
     while (turnRunning)
     {
         //System.Diagnostics.Debug.WriteLine("One turns...");
         OneBot[] bots = null;
         int count = 0;
         lock (lockListBot)
         {
             count = AllBot.Count;
             if (count > 0)
             {
                 bots = new OneBot[count];
                 AllBot.CopyTo(bots);
             }
         }
         if (count == 0)
         {
             if (Settings.EndlessMode)
  
             {
                 // Disabled: Will spam the console until a bot joins.
                 // Console.WriteLine("Last bot left. Endless mode is active, continuing");
             }
             else
             {
                 Console.WriteLine("No more BOT, ending simulator.");
                 turnRunning = false;
             }
         }
         else
         {
             for (int i = 0; i < bots.Length; i++)
             {
                 Console.WriteLine($"Turn #{turnCount} Bot {bots[i].bot.Name}");
                 await bots[i].StartNewTurn();
                 DateTime start = DateTime.UtcNow;
                 while ((bots[i].State != BotState.Ready) && (DateTime.UtcNow - start).TotalSeconds < Settings.MaxDelaySecondByTurn)
                 {
                     Thread.Sleep(2);
                 }
                 if (bots[i].State != BotState.Ready)
                 {
                     // trop long, ajout pénalité !
                     // TODO: rien pour le moment
                 }
                 Thread.Sleep(Settings.DelayBetweenEachBotTurn);
             }
             // on génère de l'énergie si nécessaire
             MainGame.RefuelMap();
             turnCount++;
             if (turnCount % MainGame.Settings.EnergyPodLessEvery == 0)
             {
                 if (Settings.EnergyPodMax > Settings.EnergyPodMin)
                     Settings.EnergyPodMax--;
             }
         }
     }
     Console.WriteLine("End of running.");
 }