예제 #1
0
 public IEnumerable<Position> GetByLine(Line line)
 {
     using (var positionRepository = new RepositoryFactory().CreatePositionRepository())
      {
     var positions = positionRepository.Find(x => x.Line.Equals(line));
     return positions;
      }
 }
예제 #2
0
 public Player Generate(Line line, AgeRange ageRange)
 {
     return GeneratePlayer(line, null, ageRange, 0);
 }
예제 #3
0
 public Player Generate(Line line, int startNumber)
 {
     return GeneratePlayer(line, null, null, startNumber);
 }
예제 #4
0
 public Player Generate(Line line)
 {
     return GeneratePlayer(line, null, null, 0);
 }
예제 #5
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;
        }
예제 #6
0
        private IEnumerable<Player> GeneratePlayersForLine(Line line, int howMany, int averageRating)
        {
            var players = new List<Player>();

             int generated = 0;
             while (generated < howMany)
             {
            var player = _playerGenerator.Generate(line, averageRating);

            // Only add the player if his line is the expected one.
            if (player.PreferredPosition.Line.Equals(line))
            {
               players.Add(player);
               generated++;
            }
             }

             return players;
        }