Ejemplo n.º 1
0
 private MatchPivot(uint id, uint editionId, uint matchNumber, uint bestOf, uint roundId, uint?minutes,
                    uint winnerId, uint?winnerSeed, uint?winnerEntryId, uint?winnerRank, uint?winnerRankPoints,
                    uint loserId, uint?loserSeed, uint?loserEntryId, uint?loserRank, uint?loserRankPoints,
                    bool walkover, bool retirement, bool disqualification, bool unfinished, string rawSuperTieBreak) : base(id, null, null)
 {
     Edition          = Get <EditionPivot>(editionId);
     MatchNumber      = matchNumber;
     BestOf           = (BestOfPivot)bestOf;
     Round            = Get <RoundPivot>(roundId);
     Minutes          = minutes;
     Winner           = Get <PlayerPivot>(winnerId);
     WinnerSeed       = winnerSeed;
     WinnerEntry      = !winnerEntryId.HasValue ? null : Get <EntryPivot>(winnerEntryId.Value);
     WinnerRank       = winnerRank;
     WinnerRankPoints = winnerRankPoints;
     Loser            = Get <PlayerPivot>(loserId);
     LoserSeed        = loserSeed;
     LoserEntry       = !loserEntryId.HasValue ? null : Get <EntryPivot>(loserEntryId.Value);
     LoserRank        = loserRank;
     LoserRankPoints  = loserRankPoints;
     Walkover         = walkover;
     Retirement       = retirement;
     Disqualification = disqualification;
     Unfinished       = unfinished;
     RawSuperTieBreak = rawSuperTieBreak;
     PointGrid        = GridPointPivot.GetByLevelAndRound(Edition.Level.Id, Round.Id);
     Edition.AddMatch(this);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the number of points gained by a specified player for this edition. The gain might vary regarding of the ruleset.
        /// </summary>
        /// <param name="player">A <see cref="PlayerPivot"/></param>
        /// <param name="rankingVersion">A <see cref="RankingRulePivot"/> (ruleset of current ranking).</param>
        /// <returns>Number of points for this player at this edition; 0 if any argument is <c>Null</c>.</returns>
        internal uint GetPlayerPoints(PlayerPivot player, RankingVersionPivot rankingVersion)
        {
            uint points = 0;

            if (player == null || rankingVersion == null)
            {
                return(points);
            }

            // If qualifcation rule applies and player comes from qualifications for this edition.
            if (rankingVersion.ContainsRule(RankingRulePivot.IncludingQualificationBonus) && PlayerIsQualified(player))
            {
                points = QualificationPointPivot.GetByLevelAndDrawSize(Level.Id, DrawSize)?.Points ?? 0;
            }

            // Cumulable points (round robin).
            points += (uint)Matches
                      .Where(match => match.Winner == player && match.Round.IsRoundRobin)
                      .Sum(match => match.PointGrid?.Points ?? 0);

            var bestWin = Matches
                          .Where(match => match.Winner == player && !match.Round.IsRoundRobin && !match.Round.IsBronzeReward)
                          .OrderBy(match => match.Round.Importance)
                          .FirstOrDefault();
            var bestLose = Matches
                           .Where(match => match.Loser == player && !match.Round.IsRoundRobin && !match.Round.IsBronzeReward)
                           .OrderBy(match => match.Round.Importance)
                           .FirstOrDefault();

            if (Matches.Any(match => match.Round.IsBronzeReward && match.Players.Contains(player)))
            {
                if (Matches.Any(match => match.Winner == player && match.Round.IsBronzeReward))
                {
                    // Third place points.
                    points += Matches
                              .First(match => match.Winner == player && match.Round.IsBronzeReward)
                              .PointGrid?.Points ?? 0;
                }
                else
                {
                    // Fourth place points.
                    points += GridPointPivot.GetByLevelAndRound(Level.Id, RoundPivot.GetQuarterFinal().Id)?.Points ?? 0;
                }
            }
            else
            {
                // Unable to detect a lose by walkover the next round than a win by walkover.
                // In that case, points from the win by walkover are ignored.
                if (bestLose == null)
                {
                    points += bestWin?.PointGrid?.Points ?? 0;
                }
                else if (bestWin != null)
                {
                    var lastWinRound = RoundPivot.GetByImportance(bestLose.Round.Importance + 1);
                    var grid         = bestWin.PointGrid;
                    if (bestWin.Round.Importance > lastWinRound.Importance)
                    {
                        grid = GridPointPivot.GetByLevelAndRound(Level.Id, lastWinRound.Id);
                    }
                    points += grid?.Points ?? 0;
                }
                else
                {
                    points += bestLose.PointGrid?.ParticipationPoints ?? 0;
                }
            }

            return(points);
        }