public void New(bool startEmpty, bool randomSettings) { FlyingBeanOptions beanOptions = new FlyingBeanOptions(); ItemOptions itemOptions = new ItemOptions(); if (randomSettings) { double newBeanProb = beanOptions.NewBeanProbOfWinner; double scanFrequency = beanOptions.TrackingScanFrequencySeconds; beanOptions = MutateUtility.MutateSettingsObject(beanOptions, new MutateUtility.MuateArgs(.5d)); beanOptions.NewBeanProbOfWinner = newBeanProb; // leave these one alone beanOptions.TrackingScanFrequencySeconds = scanFrequency; itemOptions = MutateUtility.MutateSettingsObject(itemOptions, new MutateUtility.MuateArgs(.5d)); } FinishLoad(new FlyingBeanSession(), beanOptions, itemOptions, null, null, startEmpty); }
public static ThrusterMap Mutate(ThrusterMap map, MutateUtility.MuateArgs args, bool shouldNormalize = true) { var flattened = map.Flattened.ToArray(); // ensure it's a clone int changeCount = args.GetChangeCount(flattened.Length); if (changeCount == 0 && flattened.Length > 0) { changeCount = 1; } foreach (int index in UtilityCore.RandomRange(0, flattened.Length, changeCount)) { // Mutate the value double newValue = MutateUtility.Mutate(flattened[index].Item3, args.DefaultFactor); // Cap it if (newValue < 0) { newValue = 0; } else if (newValue > 1) { newValue = 1; } // Store the mutated value flattened[index] = Tuple.Create(flattened[index].Item1, flattened[index].Item2, newValue); } if (shouldNormalize) { flattened = Normalize(flattened); } return new ThrusterMap(flattened, map.AllThrusters, map.BotToken); }
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { const double LIFESPAN = 45; // seconds const double MINSCORE = .5; const int LEVEL = 1; lock (_lock) { if (_isDisposed) { return; } foreach (TrackedBot tracked in _trackedBots) { switch (tracked.State) { case BotState.Adding: case BotState.Removing: break; case BotState.None: #region None // Create a bot BotDNA dna = null; BotDNA winningBot = _winningBot; if (winningBot == null) { dna = GetRandomDNA(_itemOptions, _shellColors).Item1; } else { // Create a mutated copy of the winning design dna = UtilityCore.Clone(winningBot); dna.UniqueID = Guid.NewGuid(); dna.Generation++; if (dna.Parts != null) { MutateUtility.Mutate(dna.Parts, _mutateArgs); } } tracked.State = BotState.Adding; tracked.Lifespan = StaticRandom.NextPercent(LIFESPAN, .1); // randomizing the lifespan a bit to stagger when bots get killed/created Point3D position = Math3D.GetRandomVector_Circular(HOMINGRADIUS / 4d).ToPoint(); _dreamWorld.Add(new OfflineWorld.AddBotArgs(position, null, tracked.BotAdded, dna, LEVEL, new Point3D(0, 0, 0), HOMINGRADIUS, this.WeaponDNA)); #endregion break; case BotState.Added: #region Added // See if this should die double age = (DateTime.UtcNow - tracked.Bot.CreationTime).TotalSeconds; if (age > tracked.Lifespan) { FitnessTracker rules = tracked.Rules; tracked.Rules = null; // set it to null as soon as possible so that the rules tick doesn't do unnecessary work double score = rules.Score / age; if (score > MINSCORE && score > _winningScore) { BotDNA winningDNA = tracked.Bot.DNAFinal; if (winningDNA != null) // it should be non null long before this point, but just make sure { _winningScore = score; _winningBot = winningDNA; } } // Kill it tracked.State = BotState.Removing; _dreamWorld.Remove(new OfflineWorld.RemoveArgs(tracked.Bot.Token, tracked.BotRemoved)); } #endregion break; } _timer.Start(); } } }