private IEnumerable <JogadorHistorico> ReplaceOneOpponents( IEnumerable <JogadorHistorico> team, IBestPlayerStrategy strategy, int round, IList <JogadorHistorico> jogadores, IList <JogadorHistorico> blockedPlayers) { var worstPlayer = team .Where(x => PlayerHaveOpponents(x, team)) .OrderBy(strategy.FunctionWorstPlayer) .ThenBy(x => x.JogosNum) .ThenBy(x => x.PrecoNum) .FirstOrDefault(); var newPlayers = strategy.DoTheMagic(round, jogadores, 1, worstPlayer.PosicaoId, blockedPlayers).Single(); team = team.Append(newPlayers); team = team .Where(x => x.JogadorHistoricoId != worstPlayer.JogadorHistoricoId) .OrderBy(x => x.PosicaoId) .ToList(); if (team.Count() != 13) { throw new Exception("Não deu bom ao retirar um jogador no método ReplaceOneOpponents!"); } blockedPlayers.Add(newPlayers); return(team); }
public IEnumerable <Results> CalculateResults( IList <JogadorHistorico> jogadores, IBestPlayerStrategy strategy, EsquemaPosicoes esquemaPosicoes) { var maxRound = jogadores.Max(x => x.RodadaId); for (int round = 0; round < maxRound; round++) { if (jogadores.Any(x => x.RodadaId == round + 1)) { var team = GetTeam(round, jogadores, strategy, esquemaPosicoes); if (strategy.AllowOpponents == false) { team = ReplaceOpponents(team, strategy, round, jogadores); } var result = new Results() { Round = round + 1, Score = team.Sum(x => GetNextRoundScore(x)), TeamPrice = team.Distinct().Sum(x => x.PrecoNum) }; yield return(result); } } }
public SimulateResults GetSimulate( string type, IBestPlayerStrategy strategy, EsquemaPosicoes esquemaPosicoes, IList <JogadorHistorico> jogadores = null) { var result = new SimulateResults() { Type = $"{type} [{esquemaPosicoes.Esquema.Nome}]", Results = CalculateResults(jogadores ?? _players, strategy, esquemaPosicoes) .ToList() }; result.Mean = result.Results.Sum(x => x.Score) / result.Results.Count; result.TotalScore = result.Results.Sum(x => x.Score); result.PriceMean = result.Results.Sum(x => x.TeamPrice) / result.Results.Count(x => x.TeamPrice > 0); result.EsquemaId = esquemaPosicoes.EsquemaId; result.EsquemaNome = esquemaPosicoes.Esquema.Nome; return(result); }
private IEnumerable <JogadorHistorico> GetTeam(int round, IList <JogadorHistorico> jogadores, IBestPlayerStrategy strategy, EsquemaPosicoes esquema) { return(new List <JogadorHistorico>(strategy.DoTheMagic(round, jogadores, esquema.Goleiro, 1)) .Concat(strategy.DoTheMagic(round, jogadores, esquema.Laterais, 2)) .Concat(strategy.DoTheMagic(round, jogadores, esquema.Zagueiros, 3)) .Concat(strategy.DoTheMagic(round, jogadores, esquema.Meias, 4)) .Concat(strategy.DoTheMagic(round, jogadores, esquema.Atacantes, 5)) .Concat(strategy.DoTheMagic(round, jogadores, esquema.Tecnico, 6)) .Concat(strategy.DoTheMagic(round, jogadores, 1))); }
private IEnumerable <JogadorHistorico> ReplaceOpponents(IEnumerable <JogadorHistorico> team, IBestPlayerStrategy strategy, int round, IList <JogadorHistorico> jogadores) { var blockedPlayers = team.ToList(); while (HaveOpponents(team)) { team = ReplaceOneOpponents(team, strategy, round, jogadores, blockedPlayers); } ; return(team); }