Example #1
0
        /// <summary>
        /// Picks a random <see cref="PlayerProfile"/> which has the specified Position.
        /// </summary>
        public PlayerProfile PickRandom(Position position)
        {
            using (var playerProfileRepository = new RepositoryFactory().CreatePlayerProfileRepository())
             {
            var playerProfiles = playerProfileRepository.Find(playerProfile => playerProfile.Positions.Contains(position)).ToList();
            var pickedPlayerProfile = GetRandomPlayerProfile(playerProfiles);

            return pickedPlayerProfile;
             }
        }
Example #2
0
 private List<Position> GetAlternativePositions(Position positionWeNeed)
 {
     List<Position> alternativePositions;
      _alternativePositions.TryGetValue(positionWeNeed.Name, out alternativePositions);
      return alternativePositions;
 }
Example #3
0
 /// <summary>
 /// Gets a random <see cref="PlayerProfile"/> for a <see cref="Position"/>.
 /// </summary>
 private PlayerProfile GetPlayerProfile(Position position)
 {
     var playerProfiles = _playerProfiles.Where(x => x.Positions.Contains(position));
      var playerProfile = _listRandomizer.GetItem(playerProfiles);
      return playerProfile;
 }
Example #4
0
        private Player GeneratePlayer(Line line, Position position, AgeRange ageRange, int startNumber)
        {
            var player = new Player();

             player.Name = GetPlayerName();

             // A position is needed to randomly pick a player profile for a specific position.
             // The position can be passed into this method as an argument.
             // Also a line can be provided, then a position within that line will be randomly determined.
             // If no line and position is provided a position will be picked randomly.
             if (position == null)
             {
            // If no Line is provided, pick one randomly.
            if (line == null)
            {
               line = _listRandomizer.GetItem(_lines);
            }

            // Get random position for this line.
            var positions = _positions.Where(x => x.Line.Equals(line));
            position = _listRandomizer.GetItem(positions);
             }

             // A Position for getting a random player profile is determined now, so get the player profile.
             var playerProfile = GetPlayerProfile(position);

             // The profile name and percentage is stored for testing purposes only.
             player.PlayerProfile = playerProfile.Name;

             // Age.
             if (ageRange == null)
             {
            ageRange = new AgeRange(16, 36);
             }
             var age = GetPersonAge(ageRange);
             player.Age = age;

             // Randomly calculate skill scores.
             player.SkillScores = startNumber > 0
                                 ? _profileScoreCalculator.Calculate(startNumber, playerProfile, age)
                                 : _profileScoreCalculator.Calculate(playerProfile, age);

             foreach (var playerSkillScore in player.SkillScores)
             {
            playerSkillScore.Player = player;
             }

             // Now the skill scores for the player are determined, determine the real position for the player.
             // This position can be different from the position that either was passed into this method or picked randomly.
             var determinedPosition = _positionDeterminator.Determine(player.SkillScores);
             player.PreferredPosition = determinedPosition;

             player.Rating = PlayerRater.GetRating(player);

             return player;
        }
Example #5
0
 public Player Generate(Position position, AgeRange ageRange)
 {
     return GeneratePlayer(null, position, ageRange, 0);
 }
Example #6
0
 public Player Generate(Position position)
 {
     return GeneratePlayer(null, position, null, 0);
 }