コード例 #1
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);
                    }
                }
            }
        }
コード例 #2
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
        }