/// <summary> /// Create matches following the first seeding match in an elimination tournament. Count of seeding matches has to be 2^n. /// </summary> protected Match[][] CreateBrackets(Match[] seedings) { Match[][] result; List <int> roundMatchCounts = new List <int>(); roundMatchCounts.Add(1); int maxMatchCount = 1; while (seedings.Length > maxMatchCount) { maxMatchCount *= 2; roundMatchCounts.Add(maxMatchCount); } roundMatchCounts.Reverse(); if (seedings.Length != maxMatchCount) { throw new ArgumentException("count of seeding matches passed in is not 2^n."); } result = new Match[roundMatchCounts.Count][]; result[0] = seedings; for (int round = 1; round < result.Length; round++) { result[round] = new Match[roundMatchCounts[round]]; for (int i = 0; i < roundMatchCounts[round]; i++) { result[round][i] = new EliminationMatch(result[round - 1][i * 2], result[round - 1][i * 2 + 1], 3); } } return(result); }
public DoubleEliminationTournament(string[] names, int setCount) : base(names, setCount) { LosersBracket = new Match[Matches.Length + 1][]; LosersBracket[0] = new Match[Matches[0].Length / 2]; for (int i = 0; i < LosersBracket[0].Length; i++) { LosersBracket[0][i] = new EliminationMatch(Matches[0][i * 2], Matches[0][i * 2 + 1], setCount, m => m.Result.Loser); } for (int round = 1; round < LosersBracket.Length; round++) { LosersBracket[round] = new Match[Matches[round].Length]; } }