private void ModifyRandomSportsMatchPlayerAmount(int modification) { (Event evnt, int roundIndex) = this.GetRandomEventWithRoundIndex(); // Quit if there aren't any matches to modify if (evnt.Matches.Count == 0) { return; } SportsMatch match = evnt.GetRandomSportsMatch(); // Ensure that doubles categories retain an even amount of players if (match.MatchType == SportsMatchCategory.BadmintonDoubles || match.MatchType == SportsMatchCategory.TableTennisDoubles) { modification *= 2; } // Add the modification to a random match's player count, but only if it's within the allowed limits int modifiedPlayerAmount = match.PlayersPerTeam + modification; if (match.PlayerAmountIsAllowed(modifiedPlayerAmount)) { bool roundAllowsModification = Rounds[roundIndex].ModifyPlayerAssignmentIfWithinLimit(match.MatchType, modification); if (roundAllowsModification) { match.PlayersPerTeam = modifiedPlayerAmount; this.ModifyEventTeamStatsPlayerCounts(roundIndex, evnt, modification); } } }
public void AddSportsMatchFromPool(List <SportsMatch> matchPool) { // Add a random SportsMatch from the pool to a random event in the schedule (Event evnt, int roundIndex) = this.GetRandomEventWithRoundIndex(); var match = SportsMatch.Random(matchPool); // Only add the match if the sports facilities have enough capacity during the round if (Rounds[roundIndex].ModifyPlayerAssignmentIfWithinLimit(match.MatchType, match.PlayersPerTeam)) { evnt.AddMatch(match); // Update the involved teams' statistics this.UpdateEventTeamStatsAfterSportsMatchAddition(roundIndex, evnt, match); } }
private void SwapSportsMatches() { // Generate indices and get SportsMatch objects (Event e0, int r0) = this.GetRandomEventWithRoundIndex(); int m0Index = Globals.Rand.Next(e0.Matches.Count); (Event e1, int r1) = this.GetRandomEventWithRoundIndex(); int m1Index = Globals.Rand.Next(e1.Matches.Count); // Quit if either event has no matches to swap if (e0.Matches.Count == 0 || e1.Matches.Count == 0) { return; } SportsMatch m0 = e0.Matches[m0Index]; SportsMatch m1 = e1.Matches[m1Index]; // Only swap if the two matches have the same amount of players and the round's sport limits allow for it bool legalSwap = Rounds[r0].LegalSportsMatchSwap(m0, m1) && Rounds[r1].LegalSportsMatchSwap(m1, m0); if (m0.PlayersPerTeam != m1.PlayersPerTeam || !legalSwap) { return; } // Swap the SportsMatch objects e0.Matches[m0Index] = m1; e1.Matches[m1Index] = m0; // Update stats // Update players per match type in the affected rounds Rounds[r0].ModifyPlayerAssignment(m0.MatchType, -m0.PlayersPerTeam); Rounds[r1].ModifyPlayerAssignment(m1.MatchType, -m1.PlayersPerTeam); Rounds[r0].ModifyPlayerAssignment(m1.MatchType, m1.PlayersPerTeam); Rounds[r1].ModifyPlayerAssignment(m0.MatchType, m0.PlayersPerTeam); // Remove the current SportsMatches this.UpdateEventTeamStatsAfterSportsMatchRemoval(r0, e0, m0); this.UpdateEventTeamStatsAfterSportsMatchRemoval(r1, e1, m1); // Add new SportsMatches this.UpdateEventTeamStatsAfterSportsMatchAddition(r0, e0, m1); this.UpdateEventTeamStatsAfterSportsMatchAddition(r1, e1, m0); // Update the events' variety penalties e0.UpdateVarietyPenaltyAfterSwap(m0, m1); e1.UpdateVarietyPenaltyAfterSwap(m1, m0); }
private void RemoveSportsMatch() { (Event e, int roundIndex) = this.GetRandomEventWithRoundIndex(); // Quit if there are no matches to remove if (e.Matches.Count == 0) { return; } int matchIndex = Globals.Rand.Next(e.Matches.Count); SportsMatch match = e.Matches[matchIndex]; this.UpdateEventTeamStatsAfterSportsMatchRemoval(roundIndex, e, match); this.Rounds[roundIndex].ModifyPlayerAssignment(match.MatchType, -match.PlayersPerTeam); e.RemoveMatchAtIndex(matchIndex); }
/// <summary> /// Updates the round player counts and sports played for both teams of a given event based on the removal of a /// given SportsMatch. /// </summary> /// <param name="roundIndex">The round in which the SportsMatch was removed.</param> /// <param name="evnt">The event to which the SportsMatch was removed.</param> /// <param name="match">The SportsMatch that was just removed from the given event in the given round.</param> private void UpdateEventTeamStatsAfterSportsMatchRemoval(int roundIndex, Event evnt, SportsMatch match) { _teamStats[evnt.TeamOneId].UpdateAfterSportsMatchRemoval(match, roundIndex); _teamStats[evnt.TeamTwoId].UpdateAfterSportsMatchRemoval(match, roundIndex); }