public void IsSquadValid_ShouldReturnFalse_WhereNumberOfPlayersFromTeamIsGreaterThanMaxPlayersPerTeam()
        {
            // Arrange
            var mockFplPlayer = new FplPlayer();

            mockFplPlayer.NowCost = 250;
            mockFplPlayer.TeamId  = 10;
            var squad = new Dictionary <FplPlayerPosition, List <EvaluatedFplPlayer> > {
                {
                    FplPlayerPosition.Forward,
                    new List <EvaluatedFplPlayer>
                    {
                        new EvaluatedFplPlayer(mockFplPlayer, 0.01),
                        new EvaluatedFplPlayer(mockFplPlayer, 0.01),
                        new EvaluatedFplPlayer(mockFplPlayer, 0.01),
                        new EvaluatedFplPlayer(mockFplPlayer, 0.01)
                    }
                }
            };

            // Act
            var result = _sut.IsValidSquad(squad);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 2
0
        //Initial implementation uses weighted randomness to attempt to build squad within cost range
        private Dictionary <FplPlayerPosition, List <EvaluatedFplPlayer> > AttemptToBuildSquad(Dictionary <FplPlayerPosition, List <EvaluatedFplPlayer> > playerWishlist, out bool buildSuccesful, int retries, out int retriesRemaining)
        {
            var squad        = new Dictionary <FplPlayerPosition, List <EvaluatedFplPlayer> >();
            var playerLimits = new SquadPositionPlayerLimits();
            var rnd          = new Random();

            foreach (var position in playerWishlist)
            {
                var positionPlayerLimit = playerLimits.Limits[position.Key];
                var playersForPosition  = position.Value.OrderByDescending(x => GetWeightedRandomEval(x.Evaluation, rnd)).Take(positionPlayerLimit).ToList();
                squad.Add(position.Key, playersForPosition);
            }

            buildSuccesful   = _squadRuleService.IsValidSquad(squad);
            retriesRemaining = retries - 1;

            return(squad);