Beispiel #1
0
        /// <summary>
        /// This returns a candidate that still needs to be spawned and scored
        /// </summary>
        public Tuple <long, ShipDNA> GetCandidate(string shipName)
        {
            // Find the finalists that still need more spawned
            TrackingCandidate[] finalists = _finalists.Where(o => o.DNA.ShipName == shipName && o.NumStarted < this.FinalistCount).ToArray();

            TrackingCandidate finalist = null;

            if (finalists.Length > 0)
            {
                // Pick a random one
                finalist = finalists[StaticRandom.Next(finalists.Length)];
            }
            else
            {
                // See if there are any candidates waiting to go in the finalist list
                ShipDNA dna = this.Candidates.Pop(shipName);
                if (dna == null)
                {
                    return(null);
                }

                finalist = new TrackingCandidate(dna);
                _finalists.Add(finalist);
            }

            // Exit Function
            return(Tuple.Create(finalist.Token, finalist.DNA));
        }
Beispiel #2
0
        private void TransitionToFinal()
        {
            List <TrackingCandidate> finalists = new List <TrackingCandidate>();

            #region Find finished finalists

            // Get all the finalists that are finished
            int index = 0;
            while (index < _finalists.Count)
            {
                TrackingCandidate finalist = _finalists[index];
                int numStarted             = finalist.NumStarted;

                if (numStarted >= this.FinalistCount && numStarted == finalist.NumFinished)
                {
                    if (!Math1D.IsNearZero(finalist.GetAverage()))              // don't let zero scores into the final (the way to get a zero score is to become a candidate, but then each attempt resulted in a zero score)
                    {
                        finalists.Add(finalist);
                    }

                    _finalists.RemoveAt(index);
                }
                else
                {
                    index++;
                }
            }

            #endregion

            if (finalists.Count > 0)
            {
                this.Final.StoreWinners(finalists.Select(o => new WinnerList.WinningBean(o.DNA, o.GetAverage(), 0d)).ToArray());
            }
        }
Beispiel #3
0
        public void ShipCreated(long candidateToken, Bot ship)
        {
            // Find the candidate list that this referes to
            TrackingCandidate finalist = _finalists.Where(o => o.Token == candidateToken).FirstOrDefault();

            if (finalist == null)
            {
                throw new ArgumentException("Didn't find the candidate referenced by the token");
            }

            // Store the ship's token
            finalist.StartedShip(ship.PhysicsBody.Token);
        }
Beispiel #4
0
        private void TransitionToCandidates(Tuple <long, WinnerList.WinningBean>[] deadLive, Tuple <long, WinnerList.WinningBean>[] deadFinalists, long[] removedTokens)
        {
            // These are ships that died, and were on the live winner list
            if (deadLive != null && deadLive.Length > 0)
            {
                foreach (var win in deadLive)
                {
                    // Store this as a finalist
                    this.Candidates.Add(win.Item2.Ship.GetNewDNA(), win.Item2.Score);
                }
            }

            // Apply final scores to the dead finalists
            if (deadFinalists != null && deadFinalists.Length > 0)
            {
                foreach (var final in deadFinalists)
                {
                    TrackingCandidate finalist = _finalists.Where(o => o.Contains(final.Item1)).FirstOrDefault();
                    if (finalist == null)
                    {
                        throw new ApplicationException("Didn't find the finalist passed in: " + final.Item1);
                    }

                    finalist.FinishedShip(final.Item1, final.Item2.Score);
                }
            }

            // There is a chance that a ship died before getting added to _livingFinalistTopScores.  If that happens, then it never gets into deadFinalists.
            // So look for this case, and set directly into _finalists
            if (removedTokens != null && removedTokens.Length > 0)
            {
                long[] uniqueDead = removedTokens;
                if (deadFinalists != null && deadFinalists.Length > 0)
                {
                    uniqueDead = removedTokens.Where(o => !deadFinalists.Any(p => o == p.Item1)).ToArray();
                }

                foreach (long dead in uniqueDead)
                {
                    TrackingCandidate finalist = _finalists.Where(o => o.Contains(dead)).FirstOrDefault();
                    if (finalist != null)
                    {
                        finalist.FinishedShip(dead, 0d);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// This returns the scores of the currently living candidates.
        /// Item1=CurrentlyLiving
        /// Item2=Scores of previous runs
        /// </summary>
        public Tuple <WinnerList.WinningBean, double[]>[] GetCandidateScoreDump()
        {
            List <Tuple <WinnerList.WinningBean, double[]> > retVal = new List <Tuple <WinnerList.WinningBean, double[]> >();

            foreach (long token in _livingFinalistTopScores.Keys)
            {
                TrackingCandidate finalist = _finalists.Where(o => o.Contains(token)).FirstOrDefault();
                if (finalist == null)
                {
                    throw new ApplicationException("Didn't find ship's token in the finalist list: " + token.ToString());
                }

                retVal.Add(Tuple.Create(_livingFinalistTopScores[token], finalist.GetFinishedScores()));
            }

            // Exit Function
            return(retVal.ToArray());
        }
Beispiel #6
0
        private void TransitionToCandidates_OLD(long[] removed, Tuple <long, WinnerList.WinningBean>[] wins)
        {
            #region Wins

            // These are ships that died, and were on the live winner list

            if (wins != null && wins.Length > 0)
            {
                foreach (var win in wins)
                {
                    // See if this was a finalist
                    TrackingCandidate finalist = _finalists.Where(o => o.Contains(win.Item1)).FirstOrDefault();
                    if (finalist != null)
                    {
                        finalist.FinishedShip(win.Item1, win.Item2.Score);
                    }
                    else
                    {
                        // This was a new life, store it as a finalist
                        this.Candidates.Add(win.Item2.Ship.GetNewDNA(), win.Item2.Score);
                    }
                }
            }

            #endregion
            #region Losses

            // These are ships that died, but weren't on the live winner list

            long[] losses = wins == null ? removed : removed.Except(wins.Select(o => o.Item1)).ToArray();

            foreach (long loss in losses)
            {
                TrackingCandidate finalist = _finalists.Where(o => o.Contains(loss)).FirstOrDefault();
                if (finalist != null)
                {
                    // It couldn't compete with the other live winners
                    finalist.FinishedShip(loss, 0d);
                }
            }

            #endregion
        }
Beispiel #7
0
        /// <summary>
        /// This returns a candidate that still needs to be spawned and scored
        /// </summary>
        public Tuple<long, ShipDNA> GetCandidate(string shipName)
        {
            // Find the finalists that still need more spawned
            TrackingCandidate[] finalists = _finalists.Where(o => o.DNA.ShipName == shipName && o.NumStarted < this.FinalistCount).ToArray();

            TrackingCandidate finalist = null;
            if (finalists.Length > 0)
            {
                // Pick a random one
                finalist = finalists[StaticRandom.Next(finalists.Length)];
            }
            else
            {
                // See if there are any candidates waiting to go in the finalist list
                ShipDNA dna = this.Candidates.Pop(shipName);
                if (dna == null)
                {
                    return null;
                }

                finalist = new TrackingCandidate(dna);
                _finalists.Add(finalist);
            }

            // Exit Function
            return Tuple.Create(finalist.Token, finalist.DNA);
        }