/*if (TeamsNumberOfHomeGames[firstTeamData.Team] <= TeamsNumberOfHomeGames[secondTeamData.Team]) * { * game = new Game(firstTeamData, secondTeamData); * } * else * { * game = new Game(secondTeamData, firstTeamData); * } * TeamsNumberOfHomeGames[game.Team1Data.Team]++; */ protected Game getGame(RoundRobinTeamData team1Data, RoundRobinTeamData team2Data) { string vsID = Game.CalculateVsId(team1Data.Team, team2Data.Team); if (!gameCloneCount.ContainsKey(vsID)) { gameCloneCount[vsID] = -1; } gameCloneCount[vsID]++; int index = gameCloneCount[vsID]; if (!gameClones.ContainsKey(vsID)) { gameClones.Add(vsID, new List <Game>()); } List <Game> clones = gameClones[vsID]; Game clone; if (clones.Count <= index) { clone = new Game(team1Data, team2Data); clones.Add(clone); } else { clone = clones[index]; } return(clone); }
public Game(RoundRobinTeamData team1Data, RoundRobinTeamData team2Data) { if (team1Data.Team.Division != team2Data.Team.Division) { throw new Exception("Teams must be in the same division"); } _team1Data = team1Data; _team2Data = team2Data; _division = Team1.Division; _teams = new Team[] { Team1, Team2 }; foreach (RoundRobinTeamData teamData in TeamDatas) { _teamGameResults.Add(teamData.Team.Id, new TeamGameResult(teamData)); } }
public void resetTeams(RoundRobinTeamData team1Data, RoundRobinTeamData team2Data) { // Remove old team data RoundRobinTeamData[] oldTeamDatas = TeamDatas.ToArray(); // Set up new team if (team1Data.Team.Division != team2Data.Team.Division) { throw new Exception("Teams must be in the same division"); } _team1Data = team1Data; _team2Data = team2Data; _division = Team1.Division; _teams = new Team[] { Team1, Team2 }; _teamGameResults.Clear(); foreach (RoundRobinTeamData teamData in TeamDatas) { _teamGameResults.Add(teamData.Team.Id, new TeamGameResult(teamData)); } // Reset tracking of played games for both old and new teams if (_winningTeam != null) { foreach (RoundRobinTeamData teamData in oldTeamDatas) { teamData.removePlayedGame(this); } foreach (RoundRobinTeamData teamData in TeamDatas) { if (!(new List <Game>(teamData.PlayedGames).Contains(this))) { teamData.addPlayedGame(this); } } } }
public TeamGameResult(RoundRobinTeamData teamdata) { _teamData = teamdata; }
protected List <RobinRound> CalculateRobinRoundsForDivision(Division division, bool includeByeGames = false) { if (division.Teams.Count < 2) { return(new List <RobinRound>()); } List <RoundRobinTeamData> TeamDatas = new List <RoundRobinTeamData>(); TeamDatas.AddRange(division.RoundRobinDatas); if (TeamDatas.Count % 2 == 1) { TeamDatas.Add(new RoundRobinTeamData(new ByeTeam())); } int numTeams = TeamDatas.Count; int numDays = (numTeams - 1); int halfSize = numTeams / 2; RoundRobinTeamData Team1Data = TeamDatas[0]; TeamDatas.RemoveAt(0); int TeamsSize = TeamDatas.Count; List <RobinRound> robinRounds = new List <RobinRound>(); for (int robinRoundNum = 0; robinRoundNum < numDays; robinRoundNum++) { List <Game> robinRoundGames = new List <Game>(); int teamIdx = robinRoundNum % TeamsSize; for (int idx = 0; idx < halfSize; idx++) { RoundRobinTeamData firstTeamData; if (idx == 0) { firstTeamData = Team1Data; } else { firstTeamData = TeamDatas[(robinRoundNum + idx) % TeamsSize]; } RoundRobinTeamData secondTeamData; if (idx == 0) { secondTeamData = TeamDatas[teamIdx]; } else { secondTeamData = TeamDatas[(robinRoundNum + TeamsSize - idx) % TeamsSize]; } if (!includeByeGames && !firstTeamData.IsBye && !secondTeamData.IsBye) { Game game = new Game(firstTeamData, secondTeamData); robinRoundGames.Add(game); } } robinRounds.Add(new RobinRound(robinRoundGames, robinRoundNum)); } return(robinRounds); }