public bool IsPenalty(Player player, Position position, out IncorrectPosition penalty) { if (player.PositionPrimary == position) { penalty = null; return(false); } bool usedSecondary = player.PositionSecondary == position; EffectiveGrade effectiveGrade = new EffectiveGrade(player, position); double score; if (usedSecondary) { score = weights.SecondaryPosition.Score; } else if (Tools.PositionCouldBeSecondary(position, player)) { score = weights.IncorrectPosition.Score; } else { score = weights.IncorrectPosition.Score * 3; } if (player.PositionPrimary == Position.Lead && player.GradePrimary != Grade.G1) { score += weights.GoodLeadsMoveUp.Score; } else if (player.PositionPrimary == Position.Skip && player.GradePrimary == Grade.G1) { score += weights.GoodSkipsGetSkip.Score; } if (!incorrectPositions.TryGetValue(player, out HistoryOfPenalty historical)) { historical = new HistoryOfPenalty(); // todo adjust history depending on severity } penalty = new IncorrectPosition { player = player, givenPosition = position, wantedPosition = player.PositionPrimary, grade = effectiveGrade.grade, score = score, usedSecondary = usedSecondary, historical = historical, }; return(true); }
public bool IsPenalty(Match match, out UnbalancedTeams penalty) { int difference = 0; for (int position = 0; position < Team.MaxSize; position++) { if (match.PositionShouldBeFilled((Position)position)) { difference += new EffectiveGrade(match.Team1.Player(position), (Position)position).Score(); difference -= new EffectiveGrade(match.Team2.Player(position), (Position)position).Score(); } } if (difference == 0) { penalty = null; return(false); } if (difference < 0) { difference = -difference; } EffectiveGrade[] team1Grades = new EffectiveGrade[Team.MaxSize]; EffectiveGrade[] team2Grades = new EffectiveGrade[Team.MaxSize]; for (int position = 0; position < Team.MaxSize; position++) { if (match.PositionShouldBeFilled((Position)position)) { team1Grades[position] = new EffectiveGrade(match.Team1.Player(position), (Position)position); team2Grades[position] = new EffectiveGrade(match.Team2.Player(position), (Position)position); } } penalty = new UnbalancedTeams { match = match, historical = new HistoryOfPenalty(), score = weights.UnbalancedTeams.Score * difference / match.Size, team1Grades = team1Grades, team2Grades = team2Grades, }; return(true); }