Example #1
0
        public void Play(Match match)
        {
            // Totally random match results for now...
             // Possible stuff contains 5 zeroes, 4 ones, 3 twos, 3 threes, etc.
             var possibleStuff = new Dictionary<int, float> { { 0, 5 }, { 1, 4 }, { 2, 3 }, { 3, 3 }, { 4, 2 }, { 5, 1 } };

             match.HomeScore = possibleStuff.RandomElementByWeight(x => x.Value).Key;
             match.AwayScore = possibleStuff.RandomElementByWeight(x => x.Value).Key;

             // Take penalty shoot out, if necessary.
             bool matchEndedInDraw = match.HomeScore == match.AwayScore;
             if (matchEndedInDraw && !match.DrawPermitted)
             {
            var possiblePenaltyScores = new Dictionary<int, float> { { 5, 5 }, { 4, 5 }, { 3, 4 }, { 2, 1 }, { 1, 1 } };

            match.HomePenaltyScore = possiblePenaltyScores.RandomElementByWeight(x => x.Value).Key;
            match.AwayPenaltyScore = possiblePenaltyScores.RandomElementByWeight(x => x.Value).Key;
            match.PenaltiesTaken = true;

            // Randomly pick a winner if the penalty shootout also ended undecisive.
            bool penaltyDraw = match.HomePenaltyScore == match.AwayPenaltyScore;
            if (penaltyDraw)
            {
               bool homeTeamWins = _randomizer.GetRandomBoolean();
               if (homeTeamWins)
               {
                  match.HomePenaltyScore++;
               }
               else
               {
                  match.AwayPenaltyScore++;
               }
            }
             }

             match.MatchStatus = MatchStatus.Ended;

             //TODO Onderstaande nog afmaken...

             // Determine the best team.
             //Team bestTeam = match.HomeTeam;
             //Team worstTeam = match.AwayTeam;
             //if (match.AwayTeam.Rating > match.HomeTeam.Rating)
             //{
             //   bestTeam = match.AwayTeam;
             //   worstTeam = match.HomeTeam;
             //}

             //// Determine difference between teams.
             //decimal ratio = bestTeam.Rating / worstTeam.Rating;

             //const decimal maxRatioWorstTeamCanWin = 2;
             //const decimal maxRatioDrawPossible = 2;

             //// Can the worst team win?
             //bool worstTeamCanWin = ratio <= maxRatioWorstTeamCanWin;
             //// Is a draw possible?
             //bool drawPossible = ratio <= maxRatioDrawPossible;
        }
Example #2
0
        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;
        }
Example #3
0
        public string GetTeamName()
        {
            //Bron: http://www.namegenerator.biz/place-name-generator.php

             var cities = new List<string>
             {
            "Falcondel",
            "Lochway",
            "Mallowice",
            "Whitemont",
            "Summerbutter",
            "Clearham",
            "Castleham",
            "Butterrock",
            "Westspring",
            "Westernesse",
            "Tenby",
            "Highview",
            "Dracmere",
            "Hollowston",
            "Wildesage",
            "Shadowbrook",
            "Buttercastle",
            "Silveroak",
            "Crystalcourt",
            "Springwinter",
            "Redwind",
            "Highfort",
            "Wyvernmere",
            "Whitemere",
            "Shadowgate",
            "Iceham",
            "Deeplake",
            "Freywyn",
            "Deeracre",
            "Shadowhal",
            "Deermead",
            "Starrydel",
            "Eastgriffin",
            "Marblewolf",
            "Woodmaple",
            "Edgeburn",
            "Highholt",
            "Coldfog",
            "Redash",
            "Hedgecliff",
            "Valhollow",
            "Byglass",
            "Westfay",
            "Greyhurst",
            "Fairfalcon",
            "Delland",
            "Glassmist",
            "Springbarrow",
            "Bykeep",
            "Grasslake",
            "Janlea",
            "Belwald",
            "Bellmare",
            "Brookden",
            "Hollowdel",
            "Iceacre",
            "Shadowlea",
            "Rockland",
            "Marbleborough",
            "Woodbeach",
            "Dorfield",
            "Lorbridge",
            "Bridgevale",
            "Alverton",
            "Larton",
            "Tunstead",
            "Wolfort",
            "Swanford",
            "Gormsey",
            "Deepbeech",
            "Woodfort",
            "Fayfield",
            "Edgeness",
            "Esterbeech",
            "Rosetown",
            "Hollowlyn",
            "Morfort",
            "Vertbrook",
            "Clearice",
            "Silveredge",
            "Mallowfield",
            "Fairmere",
            "Marblefield",
            "Norden",
            "Starryton",
            "Dracbarrow",
            "Wellden",
            "Crystalbeach",
            "Shadowmeadow",
            "Silverash",
            "Eastmarsh",
            "Pinevale",
            "Ericliff",
            "Janpond",
            "Raymont",
            "Marshfield",
            "Buttermeadow",
            "Bluedragon",
            "Deepburn",
            "Dracborough",
            "Estercrest",
            "Byway",
            "Mallowhedge",
            "Shorehal",
            "Fielddale",
            "Northfield",
             };

             var suffixes = new Dictionary<string, float>
             {
            { "Rangers", 1 },
            { "City", 2 },
            { "Rovers", 1 },
            { "FC", 3 },
            { "Town", 1 },
            { "United", 2 },
            { "Athletic", 1 },
            { "", 3 },
             };

             // Get random city.
             string teamName = _listRandomizer.GetItem(cities);

             // Combine city with (optional) suffix.
             string suffix = suffixes.RandomElementByWeight(x => x.Value).Key;
             if (!string.IsNullOrEmpty(suffix))
             {
            teamName = $"{teamName} {suffix}";
             }

             return teamName;
        }