public List<PlayerSkillScore> Calculate(int startNumberR1, PlayerProfile profile, int age)
        {
            const ProfileSkillPriority profileSkillPriorityPrimary = ProfileSkillPriority.Primary;
             const ProfileSkillPriority profileSkillPrioritySecondary = ProfileSkillPriority.Secondary;
             const ProfileSkillPriority profileSkillPriorityTertiary = ProfileSkillPriority.Tertiary;
             const ProfileSkillPriority profileSkillPriorityQuatenary = ProfileSkillPriority.Quatenary;
             const ProfileSkillPriority profileSkillPriorityRandom = ProfileSkillPriority.Random;

             var playerSkillScores = new List<PlayerSkillScore>();

             // Geef alle primary skills een score tussen de -30 en +30% van R1.
             // Onthoud de hoogste primary skill score, want dat is uitgangspunt voor de secondary skills.
             decimal highestPrimaryScore = 0;
             foreach (var primarySkill in profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityPrimary))
             {
            decimal randomPercentage = Randomizer.GetRandomNumber(-30, 30);
            decimal score = startNumberR1 + ((startNumberR1 * randomPercentage) / 100);

            if (score > highestPrimaryScore) highestPrimaryScore = score;

            int roundedScore = (int)decimal.Round(score, 0);
            if (roundedScore > 20) roundedScore = 20;
            if (roundedScore < 1) roundedScore = 1;

            var playerSkillScore = new PlayerSkillScore
            {
               PlayerSkill = primarySkill.Skill,
               Score = roundedScore
            };
            playerSkillScores.Add(playerSkillScore);
             }

             // Bepaal uitgangspunt voor secondary skills score: tussen de 60% en 80% van de hoogste primary skill score (=R3)
             decimal secondaryPercentage = Randomizer.GetRandomNumber(60, 80);
             decimal r3 = (highestPrimaryScore * secondaryPercentage) / 100;

             // Bepaal random (true/false) of er onderscheid wordt gemaakt tussen tertiary en secondary skills.
             // Zo niet, dan zijn tertiary skills ook gewoon secondary.
             var booleans = new Dictionary<bool, float> { { true, 2 }, { false, 1 } };
             bool useTertiarySkills = booleans.RandomElementByWeight(x => x.Value).Key;

             // Pak respectievelijk alleen de secondary skills of zowel de secondary als tertiary skills.
             IEnumerable<PlayerProfileSkill> secondarySkills = useTertiarySkills
            ? profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPrioritySecondary)
            : profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPrioritySecondary || x.SkillPriority == profileSkillPriorityTertiary);

             decimal highestSecondaryScore = 0;
             decimal lowestSecondaryScore = 20;
             foreach (var secondarySkill in secondarySkills)
             {
            // Neem een random percentage tussen de -30% en +30% van R3 en bepaal hiermee de score.
            decimal randomPercentage = Randomizer.GetRandomNumber(-30, 30);
            decimal score = r3 + ((r3 * randomPercentage) / 100);

            // Onthoud de hoogste en laagste secondary skill score, want dat is uitgangspunt voor de tertiary en quatenary skills.
            if (score > highestSecondaryScore) highestSecondaryScore = score;
            if (score < lowestSecondaryScore) lowestSecondaryScore = score;

            int roundedScore = (int)decimal.Round(score, 0);
            if (roundedScore > 20) roundedScore = 20;
            if (roundedScore < 1) roundedScore = 1;
            var playerSkillScore = new PlayerSkillScore
            {
               PlayerSkill = secondarySkill.Skill,
               Score = roundedScore
            };
            playerSkillScores.Add(playerSkillScore);
             }

             // Houtjetouwtje fix voor als een profiel geen secondary skills heeft...
             if (highestSecondaryScore == 0) highestSecondaryScore = r3;
             if (lowestSecondaryScore == 20) lowestSecondaryScore = r3;

             // Bepaal random (true/false) of er onderscheid wordt gemaakt tussen quatenary en tertiary skills.
             // Zo niet, dan zijn tertiary skills ook gewoon secondary.
             bool useQuatenarySkills = booleans.RandomElementByWeight(x => x.Value).Key;

             IEnumerable<PlayerProfileSkill> tertiarySkills = new List<PlayerProfileSkill>();
             IEnumerable<PlayerProfileSkill> quatenarySkills = new List<PlayerProfileSkill>();
             if (useTertiarySkills)
             {
            if (useQuatenarySkills)
            {
               tertiarySkills = profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityTertiary);
               quatenarySkills =
                  profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityQuatenary);
            }
            else
            {
               // De tertiary skills zijn zowel tertiary als quatenary.
               tertiarySkills = profile.PlayerProfileSkills.Where(
                  x => x.SkillPriority == profileSkillPriorityTertiary ||
                       x.SkillPriority == profileSkillPriorityQuatenary);
            }
             }
             else
             {
            if (useQuatenarySkills)
            {
               quatenarySkills = profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityQuatenary);
            }
            else
            {
               // De quatenary skills worden verplaatst naar de tertiary skills.
               tertiarySkills = profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityQuatenary);
               useTertiarySkills = true;
            }
             }

             if (useTertiarySkills)
             {
            // Bepaal uitgangspunt voor tertiary skills score: tussen de 60% en 80% van de hoogste secondary skill score (=R3)
            decimal tertiaryPercentage = Randomizer.GetRandomNumber(60, 80);
            decimal r4 = (highestSecondaryScore * tertiaryPercentage) / 100;

            foreach (var tertiarySkill in tertiarySkills)
            {
               // Neem een random percentage tussen de -30% en +30% van R4 en bepaal hiermee de score.
               decimal randomPercentage = Randomizer.GetRandomNumber(-30, 30);
               decimal score = r4 + ((r4 * randomPercentage) / 100);

               int roundedScore = (int)decimal.Round(score, 0);
               if (roundedScore > 20) roundedScore = 20;
               if (roundedScore < 1) roundedScore = 1;
               var playerSkillScore = new PlayerSkillScore
               {
                  PlayerSkill = tertiarySkill.Skill,
                  Score = roundedScore
               };
               playerSkillScores.Add(playerSkillScore);
            }
             }

             if (useQuatenarySkills)
             {
            foreach (var quatenarySkill in quatenarySkills)
            {
               // Pak een random nummer tussen 0 en de laagste secondary skill score.
               int score = Randomizer.GetRandomNumber(0, (int)decimal.Round(lowestSecondaryScore, 0));
               if (score > 20) score = 20;
               if (score < 1) score = 1;
               var playerSkillScore = new PlayerSkillScore
               {
                  PlayerSkill = quatenarySkill.Skill,
                  Score = score
               };
               playerSkillScores.Add(playerSkillScore);
            }
             }

             // De random skills krijgen een random waarde tussen 1 en de hoogste secondary skill.
             var randomSkills = profile.PlayerProfileSkills.Where(x => x.SkillPriority == profileSkillPriorityRandom);
             foreach (var randomSkill in randomSkills)
             {
            // Pak een random nummer tussen 1 en de hoogste secondary skill score.
            int score = Randomizer.GetRandomNumber(1, (int)decimal.Round(highestSecondaryScore, 0));
            if (score > 20) score = 20;
            var playerSkillScore = new PlayerSkillScore
            {
               PlayerSkill = randomSkill.Skill,
               Score = score
            };
            playerSkillScores.Add(playerSkillScore);
             }

             // Sorteer de playerskills.
             playerSkillScores.Sort((x, y) => x.PlayerSkill.Order.CompareTo(y.PlayerSkill.Order));

             return playerSkillScores;
        }
        public List<PlayerSkillScore> Calculate(PlayerProfile playerProfile, int age)
        {
            // Pak random nummer tussen 1 en 20 (=R1).
             var r1 = Randomizer.GetRandomNumber(1, 20);

             return Calculate(r1, playerProfile, age);
        }
Exemple #3
0
        /// <summary>
        /// Gets a profile for a versatile field player.
        /// </summary>
        public PlayerProfile GetVersatileProfile()
        {
            var playerProfile = new PlayerProfile
             {
            Id = "8a1078",
            LastModified = GetLastModified(),
            Name = "Versatile",
            Lines = new List<Line>
            {
               GetDefence(),
               GetMidfield(),
               GetAttack()
            },
            Positions = new List<Position>
            {
               GetSweeper(),
               GetCentreBack(),
               GetWingBack(),
               GetDefensiveMidfield(),
               GetCentralMidfield(),
               GetWideMidfield(),
               GetForwardMidfield(),
               GetStriker(),
               GetCentreForward(),
               GetWinger()
            }
             };

             // Alle lines behalve goalkeeper.

             // Alle positions behalve goalkeeper.

             AddSkillsToProfile(
            playerProfile: playerProfile,
            goalkeeping: ProfileSkillPriority.Quatenary,
            defending: ProfileSkillPriority.Primary,
            passing: ProfileSkillPriority.Primary,
            speed: ProfileSkillPriority.Primary,
            shooting: ProfileSkillPriority.Primary,
            heading: ProfileSkillPriority.Primary,
            tactics: ProfileSkillPriority.Random,
            fitness: ProfileSkillPriority.Random,
            talent: ProfileSkillPriority.Random,
            technique: ProfileSkillPriority.Primary,
            form: ProfileSkillPriority.Random,
            confidence: ProfileSkillPriority.Random);

             return playerProfile;
        }
Exemple #4
0
        /// <summary>
        /// Gets the profile for a Wide midfield.
        /// </summary>
        public PlayerProfile GetWideMidfieldProfile()
        {
            var playerProfile = new PlayerProfile
             {
            Id = "015c48",
            LastModified = GetLastModified(),
            Name = "Wide Midfield",
            Lines = new List<Line>
            {
               GetMidfield()
            },
            Positions = new List<Position>
            {
               GetWideMidfield()
            }
             };

             AddSkillsToProfile(
            playerProfile: playerProfile,
            goalkeeping: ProfileSkillPriority.Quatenary,
            defending: ProfileSkillPriority.Tertiary,
            passing: ProfileSkillPriority.Primary,
            speed: ProfileSkillPriority.Tertiary,
            shooting: ProfileSkillPriority.Tertiary,
            heading: ProfileSkillPriority.Random,
            tactics: ProfileSkillPriority.Secondary,
            fitness: ProfileSkillPriority.Random,
            talent: ProfileSkillPriority.Random,
            technique: ProfileSkillPriority.Secondary,
            form: ProfileSkillPriority.Random,
            confidence: ProfileSkillPriority.Random);

             return playerProfile;
        }
Exemple #5
0
        private void AddSkillsToProfile(
         PlayerProfile playerProfile,
         ProfileSkillPriority goalkeeping,
         ProfileSkillPriority defending,
         ProfileSkillPriority passing,
         ProfileSkillPriority speed,
         ProfileSkillPriority shooting,
         ProfileSkillPriority heading,
         ProfileSkillPriority tactics,
         ProfileSkillPriority fitness,
         ProfileSkillPriority talent,
         ProfileSkillPriority technique,
         ProfileSkillPriority form,
         ProfileSkillPriority confidence)
        {
            playerProfile.PlayerProfileSkills = new List<PlayerProfileSkill>();

             // Note: in the order the skills are added here also causes the order of skills for the player.

             using (var playerSkillRepository = new RepositoryFactory().CreatePlayerSkillRepository())
             {
            // Add Goalkeeping skill.
            var playerSkill = playerSkillRepository.GetGoalkeeping();
            var profileSkill = new PlayerProfileSkill(playerSkill, goalkeeping);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Defending skill.
            playerSkill = playerSkillRepository.GetDefending();
            profileSkill = new PlayerProfileSkill(playerSkill, defending);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Passing skill.
            playerSkill = playerSkillRepository.GetPassing();
            profileSkill = new PlayerProfileSkill(playerSkill, passing);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Speed skill.
            playerSkill = playerSkillRepository.GetSpeed();
            profileSkill = new PlayerProfileSkill(playerSkill, speed);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Technique skill.
            playerSkill = playerSkillRepository.GetTechnique();
            profileSkill = new PlayerProfileSkill(playerSkill, technique);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Shooting skill.
            playerSkill = playerSkillRepository.GetShooting();
            profileSkill = new PlayerProfileSkill(playerSkill, shooting);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Heading skill.
            playerSkill = playerSkillRepository.GetHeading();
            profileSkill = new PlayerProfileSkill(playerSkill, heading);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Tactics skill.
            playerSkill = playerSkillRepository.GetTactics();
            profileSkill = new PlayerProfileSkill(playerSkill, tactics);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Talent skill.
            playerSkill = playerSkillRepository.GetTalent();
            profileSkill = new PlayerProfileSkill(playerSkill, talent);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Fitness skill.
            playerSkill = playerSkillRepository.GetFitness();
            profileSkill = new PlayerProfileSkill(playerSkill, fitness);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Form skill.
            playerSkill = playerSkillRepository.GetForm();
            profileSkill = new PlayerProfileSkill(playerSkill, form);
            playerProfile.PlayerProfileSkills.Add(profileSkill);

            // Add Confidence skill.
            playerSkill = playerSkillRepository.GetConfidence();
            profileSkill = new PlayerProfileSkill(playerSkill, confidence);
            playerProfile.PlayerProfileSkills.Add(profileSkill);
             }
        }