//Compare if 2 positions are in the right order. private bool ComparePositions(Position lower, Position upper, Lineup.PositionType type) { //If single, positions is not empty and players age group is not ignored if (Lineup.PositionType.Single.HasFlag(type) && lower.Player != null && upper.Player != null && !ContainsIgnoredAgeGroup(lower.Player.Rankings.Age) && !ContainsIgnoredAgeGroup(upper.Player.Rankings.Age)) { return((lower.Player.Rankings.SinglesPoints - upper.Player.Rankings.SinglesPoints) <= _maxSingleDiff); } //If mix double, positions is not empty and players age group is not ignored if (type == Lineup.PositionType.MixDouble && lower.Player != null && lower.OtherPlayer != null && upper.Player != null && upper.OtherPlayer != null && !ContainsIgnoredAgeGroup(lower.Player.Rankings.Age) && !ContainsIgnoredAgeGroup(upper.Player.Rankings.Age) && !ContainsIgnoredAgeGroup(lower.OtherPlayer.Rankings.Age) && !ContainsIgnoredAgeGroup(upper.OtherPlayer.Rankings.Age)) { return(((lower.Player.Rankings.MixPoints + lower.OtherPlayer.Rankings.MixPoints) - (upper.Player.Rankings.MixPoints + upper.OtherPlayer.Rankings.MixPoints)) <= _maxDoubleDiff); } //If double, positions is not empty and players age group is not ignored if (Lineup.PositionType.Double.HasFlag(type) && lower.Player != null && lower.OtherPlayer != null && upper.Player != null && upper.OtherPlayer != null && !ContainsIgnoredAgeGroup(lower.Player.Rankings.Age) && !ContainsIgnoredAgeGroup(upper.Player.Rankings.Age) && !ContainsIgnoredAgeGroup(lower.OtherPlayer.Rankings.Age) && !ContainsIgnoredAgeGroup(upper.OtherPlayer.Rankings.Age)) { return(((lower.Player.Rankings.DoublesPoints + lower.OtherPlayer.Rankings.DoublesPoints) - (upper.Player.Rankings.DoublesPoints + upper.OtherPlayer.Rankings.DoublesPoints)) <= _maxDoubleDiff); } return(true); }
//Checks positions for rulebreaks. private bool CheckPositions(List <Position> positions, Lineup.PositionType type) { bool success = true; for (int i = 1; i < positions.Count; i++) { for (int j = 0; j < i; j++) //Compare position with above positions. { //If positions are in wrong order, add rulebreaks. if (!ComparePositions(positions[i], positions[j], type)) { success = false; if (Lineup.PositionType.Double.HasFlag(type)) { _ruleBreaks.Add(new RuleBreak((type, i), 0, $"Double has too many points compared to position {j+1}")); _ruleBreaks.Add(new RuleBreak((type, i), 1, $"Double has too many points compared to position {j+1}")); } else { _ruleBreaks.Add(new RuleBreak((type, i), 0, $"Player has too many points compared to position {j+1}")); } break; } } } return(success); }
//Checks if a position is empty private bool CheckPositionNull(Position pos, Lineup.PositionType type) { if (pos.Player == null) { return(true); } if (Lineup.PositionType.Double.HasFlag(type) && pos.OtherPlayer == null) { return(true); } return(false); }
private bool SexGood(Lineup.PositionType positionType, Sex sex) { switch (positionType) { case Lineup.PositionType.MixDouble: return(true); case Lineup.PositionType.MensSingle: case Lineup.PositionType.MensDouble: return(sex == Sex.Male); case Lineup.PositionType.WomensSingle: case Lineup.PositionType.WomensDouble: return(sex == Sex.Female); default: return(false); } }
//Compare players' category points private bool ComparePlayerPointsType(Player lowerPlayer, Player higherPlayer, Lineup.PositionType comparePositionType) { if (comparePositionType == Lineup.PositionType.MixDouble) { return(CheckPoints(lowerPlayer.Rankings.MixPoints, higherPlayer.Rankings.MixPoints)); } if (Lineup.PositionType.Double.HasFlag(comparePositionType)) { return(CheckPoints(lowerPlayer.Rankings.DoublesPoints, higherPlayer.Rankings.DoublesPoints)); } return(CheckPoints(lowerPlayer.Rankings.SinglesPoints, higherPlayer.Rankings.SinglesPoints)); }