Ejemplo n.º 1
0
        /// <summary>
        /// This returns a random winner for the type requested (could return null)
        /// WARNING: Don't modify the returned dna directly, make a copy first
        /// </summary>
        public ShipDNA GetWinner(string name)
        {
            var current = _current;             // store local because it's volatile

            if (current == null)
            {
                return(null);
            }

            // Find the set for the name requested
            WinningSet set = current.Item2.Where(o => o.ShipName == name).FirstOrDefault();

            if (set == null)
            {
                return(null);
            }

            // Get all the beans across all the lineages
            var beans = set.BeansByLineage.SelectMany(o => o.Item2).ToArray();

            // Pick a random one
            int index = StaticRandom.Next(beans.Length);

            if (beans[index].Ship == null)
            {
                return(beans[index].DNA);
            }
            else
            {
                return(beans[index].Ship.GetNewDNA());
            }
        }
Ejemplo n.º 2
0
        public Match(WinningSet nbWinningSets)
        {
            this.NbWinningSets = (int)nbWinningSets;
            this.Sets          = new List <Set>((int)nbWinningSets);
            this.CurrentSet    = new Set(this);

            switch (nbWinningSets)
            {
            case WinningSet.BEST_OF_THREE:
                this.ScoreMatch = new BestOfThreeScoreMatch(this);
                break;

            case WinningSet.BEST_OF_FIVE:
                this.ScoreMatch = new BestOfFiveScoreMatch(this);
                break;

            default:
                break;
            }
            //dispatch event to current handling ScoreGame object
            this.TeamScoredHandler += this.CurrentSet.OnTeamScored;

            this.MatchStarted   = false;
            this.MatchFinnished = false;

            //register events
            this.CurrentSet.TeamScoredHandler          += CurrentSet.CurrentGame.ScoreGame.OnTeamScored;
            this.CurrentSet.CurrentGame.GameWonHandler += CurrentSet.ScoreSet.OnGameWonHandler;
            this.CurrentSet.SetWonHandler += ScoreMatch.OnSetWonHandler;
        }
Ejemplo n.º 3
0
        private static WinningSet GetWinnersSprtName(string name, WinningSet existing, WinningBean[] candidates, int maxLineages, int maxPerLineage, bool tracksLivingInstances)
        {
            if (candidates == null)
            {
                #region Validate Existing

                //TODO: See if the constraints are more restrictive
                //if (existing != null)
                //{
                //    if (existing.BeansByLineage.Length > maxLineages)
                //    {

                //    }
                //}

                #endregion
                return(existing);
            }

            // Group the candidates up by lineage
            var candidateLineage = candidates.GroupBy(o => tracksLivingInstances ? o.Ship.Lineage : o.DNA.ShipLineage).ToArray();

            List <Tuple <string, WinningBean[]> > retVal = new List <Tuple <string, WinningBean[]> >();

            // Shoot through all the unique lineages across existing and candidate
            foreach (string lineage in UtilityCore.Iterate(
                         existing == null ? null : existing.BeansByLineage.Select(o => o.Item1),
                         candidateLineage.Select(o => o.Key)).
                     Distinct())
            {
                var matchingCandidate = candidateLineage.Where(o => o.Key == lineage).FirstOrDefault();

                // Get the top beans for this lineage
                retVal.Add(GetWinnersSprtLineage(lineage,
                                                 existing == null ? null : existing.BeansByLineage.Where(o => o.Item1 == lineage).FirstOrDefault(),
                                                 matchingCandidate == null ? null : matchingCandidate.ToArray(),
                                                 maxPerLineage, tracksLivingInstances));
            }

            // Sort, take top
            return(new WinningSet(name,
                                  retVal.OrderByDescending(o => o.Item2.Max(p => p.Score)).
                                  Take(maxLineages).
                                  ToArray()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This returns how many lineages are currently being tracked for the name passed in
        /// </summary>
        /// <remarks>
        /// You can compare this returned value to this.MaxLineages to see how many are still available, or whatever
        /// </remarks>
        public int GetNumUsedLineages(string name)
        {
            var current = _current;             // store local because it's volatile

            if (current == null)
            {
                return(0);
            }

            // Find the set for the name requested
            WinningSet set = current.Item2.Where(o => o.ShipName == name).FirstOrDefault();

            if (set == null)
            {
                return(0);
            }

            // Just return the number of lineages
            return(set.BeansByLineage.Length);
        }
Ejemplo n.º 5
0
 public WinnerList(bool tracksLivingInstances, int maxLineages, int maxPerLineage, WinningSet[] current)
     : this(tracksLivingInstances, maxLineages, maxLineages)
 {
     _current = Tuple.Create(DateTime.UtcNow, current);
 }
Ejemplo n.º 6
0
        private static WinningSet GetWinnersSprtName(string name, WinningSet existing, WinningBean[] candidates, int maxLineages, int maxPerLineage, bool tracksLivingInstances)
        {
            if (candidates == null)
            {
                #region Validate Existing

                //TODO: See if the constraints are more restrictive
                //if (existing != null)
                //{
                //    if (existing.BeansByLineage.Length > maxLineages)
                //    {

                //    }
                //}

                #endregion
                return existing;
            }

            // Group the candidates up by lineage
            var candidateLineage = candidates.GroupBy(o => tracksLivingInstances ? o.Ship.Lineage : o.DNA.ShipLineage).ToArray();

            List<Tuple<string, WinningBean[]>> retVal = new List<Tuple<string, WinningBean[]>>();

            // Shoot through all the unique lineages across existing and candidate
            foreach (string lineage in UtilityCore.Iterate(
                existing == null ? null : existing.BeansByLineage.Select(o => o.Item1),
                candidateLineage.Select(o => o.Key)).
                Distinct())
            {
                var matchingCandidate = candidateLineage.Where(o => o.Key == lineage).FirstOrDefault();

                // Get the top beans for this lineage
                retVal.Add(GetWinnersSprtLineage(lineage,
                    existing == null ? null : existing.BeansByLineage.Where(o => o.Item1 == lineage).FirstOrDefault(),
                    matchingCandidate == null ? null : matchingCandidate.ToArray(),
                    maxPerLineage, tracksLivingInstances));
            }

            // Sort, take top
            return new WinningSet(name,
                retVal.OrderByDescending(o => o.Item2.Max(p => p.Score)).
                Take(maxLineages).
                ToArray());
        }