private void UpdateSim() { SimOpt.SimOpts.TotRunCycle++; DnaEngine.ExecRobs(SimOpt.SimOpts.Costs, _robotsManager.Robots); //updateshots can write to bot sense, so we need to clear bot senses before updating shots foreach (var rob in _robotsManager.Robots.Where(r => r.Exists && r.DnaDisabled == false)) { Senses.EraseSenses(rob); } _shotsManager.UpdateShots(_robotsManager); //Botsareus 6/22/2016 to figure actual velocity of the bot incase there is a collision event foreach (var rob in _robotsManager.Robots.Where(r => r.Exists)) { rob.OldPosition = rob.Position; } _robotsManager.UpdateBots(); //to figure actual velocity of the bot incase there is a collision event foreach (var rob in _robotsManager.Robots.Where(r => r.Exists && !(r.OldPosition.X == 0 & r.OldPosition.Y == 0))) { rob.ActualVelocity = rob.Position - rob.OldPosition; } var allChlr = (int)_robotsManager.Robots.Where(r => r.Exists).Sum(r => r.Chloroplasts); _robotsManager.TotalChlr = allChlr / 16000; //Panda 8/23/2013 Calculate total unit chloroplasts if (_robotsManager.TotalChlr < SimOpt.SimOpts.MinVegs && Vegs.TotalVegs != -1) { Vegs.VegsRepopulate(_robotsManager, _bucketManager); //Will be -1 first cycle after loading a sim. Prevents spikes. } Vegs.feedvegs(_robotsManager, SimOpt.SimOpts.MaxEnergy); //Kill some robots to prevent of memory var totlen = _robotsManager.Robots.Where(r => r.Exists).Sum(r => r.Dna.Count); if (totlen > 4000000) { var maxdel = 1500 * (_robotsManager.TotalRobots * 425 / totlen); foreach (var rob in _robotsManager.Robots.Where(r => r.Exists).OrderByDescending(r => r.Energy + r.Body * 10).Take(maxdel).ToArray()) { _robotsManager.KillRobot(rob); } } if (totlen > 3000000) { foreach (var rob in _robotsManager.Robots) { rob.LastMutationDetail.Clear(); } } RenderField(); }
public void StartSimulation(bool startLoaded = false) { DnaEngine.LoadSysVars(); if (!startLoaded) { SimOpt.SimOpts.TotBorn = 0; } if (!startLoaded) { _shotsManager = new ShotsManager(); _bucketManager = new BucketManager(SimOpt.SimOpts); _robotsManager = new RobotsManager(_bucketManager, _shotsManager); } var standardRadius = SimOpt.SimOpts.FixedBotRadii ? Robot.RobSize / 2.0 : 415.475; _shotsManager.MaxBotShotSeparation = Math.Pow(standardRadius, 2) + Math.Pow(SimOpt.SimOpts.MaxVelocity * 2 + Robot.RobSize / 3.0, 2); if (!startLoaded) { LoadRobots(); } else { Vegs.CoolDown = -SimOpt.SimOpts.RepopCooldown; Vegs.TotalVegs = -1; } _active = true; Main(); }