/// <summary> /// Updates the variety penalty for the singles or doubles counterpart of a category that has just been added or /// removed. /// </summary> /// <param name="match"></param> /// <param name="added"></param> public void UpdateVarietyPenaltyForSimilarCategories(SportsMatch match, bool added) { // If a category's counterpart has just been added/removed, consider it when updating the variety penalty // e.g. if a badminton match has just been added, check the badmintonDoubles category for duplicates as well SportsMatchCategory cat = match.MatchType; switch (cat) { case SportsMatchCategory.Badminton: UpdateVarietyPenaltyAfterMatchUpdate(SportsMatchCategory.BadmintonDoubles, added); break; case SportsMatchCategory.BadmintonDoubles: UpdateVarietyPenaltyAfterMatchUpdate(SportsMatchCategory.Badminton, added); break; case SportsMatchCategory.TableTennis: UpdateVarietyPenaltyAfterMatchUpdate(SportsMatchCategory.TableTennisDoubles, added); break; case SportsMatchCategory.TableTennisDoubles: UpdateVarietyPenaltyAfterMatchUpdate(SportsMatchCategory.TableTennis, added); break; } }
/// <summary> /// Constructs an Event with a random amount of sports matches where the amount of participating players remains /// under the limit if one is given. /// </summary> /// <param name="teamOneId">The ID of one of the teams participating in this event.</param> /// <param name="teamTwoId">The ID of the other team participating in this event.</param> /// <param name="matchPool">List of matches from which the random matches in this event will be chosen.</param> /// <param name="avgPlayersPerTeam">The maximum amount of players per team that will be assigned to this event. /// </param> /// <param name="round">The round in which this event is planned.</param> /// <param name="playersPerMatchType"></param> /// <returns></returns> public static Event Random(int teamOneId, int teamTwoId, List <SportsMatch> matchPool, int avgPlayersPerTeam, Dictionary <SportsMatchCategory, int> playersPerMatchType) { var evnt = new Event(teamOneId, teamTwoId); // Add 1 to 3 random SportsMatch objects from the given pool. int amountToAdd = Globals.Rand.Next(1, 4); int allocatedPlayers = 0; for (int i = 0; i < amountToAdd; i++) { SportsMatch match = SportsMatch.Random(matchPool); // Check if the new match would stay within player limits int newPlayerCount = allocatedPlayers + match.PlayersPerTeam; if (newPlayerCount > avgPlayersPerTeam) { break; } // Check if there is enough space for the new match's sport within this round int newMatchTypeCount = playersPerMatchType[match.MatchType] + match.PlayersPerTeam; if (newMatchTypeCount > Globals.MatchTypePlayerLimitsPerTeam[match.MatchType]) { continue; } evnt.AddMatch(match); allocatedPlayers = newPlayerCount; playersPerMatchType[match.MatchType] = newMatchTypeCount; } return(evnt); }
public void AddMatch(SportsMatch match) { this.Matches.Add(match); UpdateVarietyPenaltyAfterMatchAddition(match.MatchType); UpdateVarietyPenaltyForSimilarCategories(match, true); UpdateRequiredRefereeAmount(match.MatchType, true); _categoryCounts[match.MatchType]++; }
public void RemoveMatchAtIndex(int matchIndex) { SportsMatch match = this.Matches[matchIndex]; UpdateVarietyPenaltyAfterMatchRemoval(match.MatchType); UpdateVarietyPenaltyForSimilarCategories(match, false); UpdateRequiredRefereeAmount(match.MatchType, false); _categoryCounts[match.MatchType]--; this.Matches.RemoveAt(matchIndex); }
public bool LegalSportsMatchSwap(SportsMatch old, SportsMatch @new) { if (old.MatchType == @new.MatchType) { return(LegalPlayerAssignment(old.MatchType, @new.PlayersPerTeam - old.PlayersPerTeam)); } int oldCategoryNewAmount = PlayersPerMatchType[old.MatchType] - old.PlayersPerTeam; int newCategoryNewAmount = PlayersPerMatchType[@new.MatchType] + @new.PlayersPerTeam; return(oldCategoryNewAmount <= Globals.MatchTypePlayerLimitsPerTeam[old.MatchType] && newCategoryNewAmount <= Globals.MatchTypePlayerLimitsPerTeam[@new.MatchType]); }
public void UpdateVarietyPenaltyAfterSwap(SportsMatch old, SportsMatch @new) { UpdateVarietyPenaltyAfterMatchRemoval(old.MatchType); UpdateVarietyPenaltyAfterMatchAddition(@new.MatchType); }
/// <summary> /// Updates this team's sports played and player count per round based on the removal of a given SportsMatch in /// a given round. /// </summary> /// <param name="match">The SportsMatch that has just been scheduled for this team.</param> /// <param name="roundIndex">The number of the round in which the given match was added.</param> public void UpdateAfterSportsMatchRemoval(SportsMatch match, int roundIndex) { this.RemoveSportsCategoryPlayed(match.MatchType); this.RoundPlayerCounts[roundIndex] -= match.PlayersPerTeam; }
/// <summary> /// Updates this team's sports played and player count per round based on the addition of a given SportsMatch in /// a given round. /// </summary> /// <param name="match">The SportsMatch that has just been scheduled for this team.</param> /// <param name="roundIndex">The number of the round in which the given match was added.</param> public void UpdateAfterSportsMatchAddition(SportsMatch match, int roundIndex) { this.AddSportsCategoryPlayed(match.MatchType); this.RoundPlayerCounts[roundIndex] += match.PlayersPerTeam; }