private void AddMatchup(string playerFaction, string opponentFaction, int wins, int totalGamesPlayed) { Matchup matchup = new Matchup() { PlayerFaction = playerFaction, OpponentFaction = opponentFaction, MatchesWon = wins, MatchesLost = totalGamesPlayed - wins, Winrate = Math.Round((double)wins / totalGamesPlayed, 2) }; Matchups.Add(matchup); }
private void LoadMatchups() { foreach (List <MatchupModel> matchups in Tournament.Rounds) { if (matchups.First().MatchupRound == SelectedRound) { Matchups.Clear(); foreach (MatchupModel m in matchups) { if (m.Winner == null || !UnplayedOnly) { Matchups.Add(m); } } } } if (Matchups.Count > 0) { SelectedMatchup = Matchups.First(); } }
public void Initialize() { int i; int x = Padding, y = Padding; for (i = 0; i < 32; i++) { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); y += RectangleSize.Height + Padding; if (i == 15) { x += 8 * (Padding + RectangleSize.Width); y = Padding; } } x = Padding + Padding + RectangleSize.Width; y = Padding + (Padding + RectangleSize.Height) / 2; for (i = 0; i < 16; i++) { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); Matchups[2 * i].NextRound = bm; Matchups[2 * i + 1].NextRound = bm; bm.PrevRound1 = Matchups[2 * i]; bm.PrevRound2 = Matchups[2 * i + 1]; y += 2 * (RectangleSize.Height + Padding); if (i == 7) { x += 6 * (Padding + RectangleSize.Width); y = Padding + (Padding + RectangleSize.Height) / 2; } } x = Padding + 2 * (Padding + RectangleSize.Width); y = Padding + 3 * (Padding + RectangleSize.Height) / 2; for (i = 0; i < 8; i++) { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); Matchups[2 * i + 32].NextRound = bm; Matchups[2 * i + 33].NextRound = bm; bm.PrevRound1 = Matchups[2 * i + 32]; bm.PrevRound2 = Matchups[2 * i + 33]; y += 4 * (RectangleSize.Height + Padding); if (i == 3) { x += 4 * (Padding + RectangleSize.Width); y = Padding + 3 * (Padding + RectangleSize.Height) / 2; } } x = Padding + 3 * (Padding + RectangleSize.Width); y = Padding + 7 * (Padding + RectangleSize.Height) / 2; for (i = 0; i < 4; i++) { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); Matchups[2 * i + 48].NextRound = bm; Matchups[2 * i + 49].NextRound = bm; bm.PrevRound1 = Matchups[2 * i + 48]; bm.PrevRound2 = Matchups[2 * i + 49]; y += 8 * (RectangleSize.Height + Padding); if (i == 1) { x += 2 * (Padding + RectangleSize.Width); y = Padding + 7 * (Padding + RectangleSize.Height) / 2; } } x = Padding + 4 * (Padding + RectangleSize.Width); y = Padding + 7 * (Padding + RectangleSize.Height) / 2; for (i = 0; i < 2; i++) { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); Matchups[2 * i + 56].NextRound = bm; Matchups[2 * i + 57].NextRound = bm; bm.PrevRound1 = Matchups[2 * i + 56]; bm.PrevRound2 = Matchups[2 * i + 57]; y += 8 * (Padding + RectangleSize.Height); } y = 15 * (Padding + RectangleSize.Height) / 2; { BracketMatchup bm = new BracketMatchup(); bm.X = x; bm.Y = y; Matchups.Add(bm); Matchups[60].NextRound = bm; Matchups[61].NextRound = bm; bm.PrevRound1 = Matchups[60]; bm.PrevRound2 = Matchups[61]; } }
public SwissBracket(BracketModel _model) : base(_model) { /* * This constructor extends the parent (round robin) version. * By the time we're "here," we already have our main data restored: * Players, Matches, and inherited Bracket fields. * Now, we need to recreate the Swiss-specific fields: * Matchups, PlayerByes, and PairingMethod. */ for (int r = 1; r <= NumberOfRounds; ++r) { List <IMatch> round = GetRound(r); if (round.Any(m => m.Players.Contains(null))) { // This round isn't populated yet. Break out: break; } // playersInRound is a list of all players (by index) // in matchups this round. We check for the missing player // to know who got a bye. List <int> playersInRound = new List <int>(); foreach (IMatch match in round) { // For each populated Match, add a Matchup to the private list: int defIndex = Players.FindIndex(p => p.Id == match.Players[(int)PlayerSlot.Defender].Id); int chalIndex = Players.FindIndex(p => p.Id == match.Players[(int)PlayerSlot.Challenger].Id); playersInRound.Add(defIndex); playersInRound.Add(chalIndex); Matchups.Add(new Matchup(defIndex, chalIndex, r)); } if (playersInRound.Count < Players.Count) { // Find the player with a bye this round: int byePlayerIndex = Enumerable .Range(0, Players.Count).ToList() .Except(playersInRound).First(); // Add him to Byes list and award a "Win" Outcome: PlayerByes.Add(Players[byePlayerIndex].Id); Rankings.Find(p => p.Id == Players[byePlayerIndex].Id) .AddMatchOutcome(Outcome.Win, true); } // Set ActiveRound (this finds the last populated round): ActiveRound = r; } // Determine the Pairing Method from examining round 1: // (default is Slide) this.PairingMethod = PairingMethod.Slide; if (NumberOfMatches > 0 && ActiveRound > 0) { #if CHOOSE_PAIRING // Find the top seed's first Match: int firstPlayerIndex = (0 == PlayerByes.Count) ? 0 : 1; IMatch firstPlayerMatch = GetRound(1) .Where(m => m.Players.Select(p => p.Id).Contains(this.Players[firstPlayerIndex].Id)) .First(); // Find the ID of the Player the top seed is matched against: int secondPlayerId = firstPlayerMatch.Players .Select(p => p.Id) .Where(i => i != this.Players[firstPlayerIndex].Id) .First(); if (Players[1 + firstPlayerIndex].Id == secondPlayerId) { // The second Player is also the second seed. // This must be Adjancent pairings. PairingMethod = PairingMethod.Adjacent; } else if (Players.Last().Id == secondPlayerId) { // The second Player is the last seed. // This must be Fold pairings. PairingMethod = PairingMethod.Fold; } #endif if (PlayerByes.Count > 0) { // If we added points for byes, we need to update rankings. // Call the parent (round robin) method: UpdateRankings(); } } }