Exemplo n.º 1
0
        public Squad CombineSingleSquad(int squadSize, List <SquadPlayer> idAndSkills, List <AlgDynamicSequenceModel> algSequenceData)
        {
            int[] indexedResult = new int[squadSize];
            int   noPlayers     = idAndSkills.Count();

            Stack <int> stack = new Stack <int>(squadSize);

            stack.Push(0);

            while (stack.Count > 0)
            {
                int index = stack.Count - 1;
                int value = stack.Pop();
                while (value < noPlayers)
                {
                    indexedResult[index++] = value++;
                    stack.Push(value);
                    if (index != squadSize)
                    {
                        continue;
                    }

                    int  seqIndex = 0;
                    bool pass     = true;
                    while (pass && (seqIndex < algSequenceData.Count()))
                    {
                        AlgDynamicSequenceModel asd = algSequenceData
                                                      .FirstOrDefault(p => p.ItterationOrder.Equals(seqIndex));
                        if (!_algorithmCheckMeanValue.CheckSkillMeanValue(indexedResult, idAndSkills, asd))
                        {
                            pass = false;
                            break;
                        }
                        seqIndex++;
                    }

                    if (pass)
                    {
                        Squad squad = new Squad();
                        squad = _algorithmIndexesToSquads.ConvertResultIndexesToIds(indexedResult, idAndSkills);
                        return(squad);
                    }
                    break;
                }
            }
            return(null);
        }
        public IEnumerable <AlgDynamicSequenceModel> ProvideSequenceData(AlgorithmInput algorithmInput)
        {
            int iterationOrder = 0;

            foreach (PlayingSkill playingSkill in (PlayingSkill[])Enum.GetValues(typeof(PlayingSkill)))
            {
                string skillType = Enum.GetName(typeof(PlayingSkill), playingSkill);
                AlgDynamicSequenceModel algSeqData = new AlgDynamicSequenceModel()
                {
                    Deviation       = algorithmInput.InitialDeviation + iterationOrder, //each subsequent deviation in search algorithm is increased by 1
                    Name            = skillType,
                    ItterationOrder = iterationOrder++,
                    //Skill = playingSkill,
                    SquadSize = algorithmInput.SquadSize
                };
                switch (skillType)
                {
                case "Shooting":
                    algSeqData.Average  = algorithmInput.AvgShooting;
                    algSeqData.AvgAprox = algorithmInput.AvgAproxSho;
                    break;

                case "Skating":
                    algSeqData.Average  = algorithmInput.AvgSkating;
                    algSeqData.AvgAprox = algorithmInput.AvgAproxSka;
                    break;

                case "Checking":
                    algSeqData.Average  = algorithmInput.AvgChecking;
                    algSeqData.AvgAprox = algorithmInput.AvgAproxChe;
                    break;
                }

                yield return(algSeqData);
            }
        }
Exemplo n.º 3
0
        public bool CheckSkillMeanValue(int[] indexedResult, List <SquadPlayer> allPlayers, AlgDynamicSequenceModel asd)
        {
            int    average = asd.Average + asd.AvgAprox;
            double sumMin  = ((double)average - asd.Deviation) * asd.SquadSize;
            double sumMax  = ((double)average + asd.Deviation) * asd.SquadSize;

            int sum = allPlayers.Where((item, index) => indexedResult.Contains(index))
                      .Select(p =>
            {
                if (asd.Name.Equals("Shooting"))
                {
                    return(p.Shooting);
                }
                else if (asd.Name.Equals("Skating"))
                {
                    return(p.Skating);
                }
                else
                {
                    return(p.Checking);
                }
            })
                      .Sum();

            if (sum >= sumMin && sum <= sumMax)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }