Exemplo n.º 1
0
            public double Lifespan = 45d;       // seconds

            #region Public Methods

            public void BotAdded(IMapObject item)
            {
                lock (_parentLock)
                {
                    this.Bot = (ArcBotNPC)item;
                    this.Rules = GetRules(this.Bot);

                    this.State = BotState.Added;
                }
            }
Exemplo n.º 2
0
            public double Lifespan = 45d;       // seconds

            #region Public Methods

            public void BotAdded(IMapObject item)
            {
                lock (_parentLock)
                {
                    this.Bot   = (ArcBotNPC)item;
                    this.Rules = GetRules(this.Bot);

                    this.State = BotState.Added;
                }
            }
Exemplo n.º 3
0
        private void RuleTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (_isDisposed)
            {
                return;
            }

            foreach (TrackedBot tracked in _trackedBots)
            {
                FitnessTracker rules = tracked.Rules;
                if (rules != null)
                {
                    rules.Update_AnyThread(_ruleElapsed);
                }
            }

            _ruleTimer.Start();
        }
Exemplo n.º 4
0
        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();
                }
            }
        }