/// <summary> /// returns a team with the lowest opponent cost to the teams of the currently composed matchup /// </summary> private Team FindRandomLowestCostOpponents(Matchup currentMatchup) { int bestWeight = 100000; List <Team> listoflowcostteams = new List <Team>(); for (int i = 0; i < teamsInThisSet.Count; i++) { //if this team isn't already picked if (teamsThatHaveBeenMatched[i] == false) { int totalTeamWeight = FindTotalTeamWeight(currentMatchup, i); //if team's weight is equal to the lowest found weight thusfar, add them to a list of teams with the lowest weight to the team. if their weight is lower than that, reset the list with them if (totalTeamWeight == bestWeight) { listoflowcostteams.Add(teamsInThisSet[i]); } else if (totalTeamWeight < bestWeight) { bestWeight = totalTeamWeight; listoflowcostteams = new List <Team>(); listoflowcostteams.Add(teamsInThisSet[i]); } } } //return a random team with the lowest weight from the list Random rnd = new Random(); return(listoflowcostteams[rnd.Next(0, listoflowcostteams.Count)]); }
/// <summary> /// combines teams together /// </summary> private void MatchTeamWithOpposingTeams(int index) { //add this first Team to a Matchup Matchup currentmatch = new Matchup(teamsInThisSet[index]); //mark team as matched up teamsThatHaveBeenMatched[teamsInThisSet[index].teamIndex] = true; //recursively add other teams until the total number of teams in a match have been reached finishedMatchups.Add(RecursivelyCompareteams(currentmatch)); }
/// <summary> /// adds more teams until you reach the set limit of teams for each matchup /// </summary> private Matchup RecursivelyCompareteams(Matchup currentMatchup) { //stop if you've filled matchup if (currentMatchup.teams.Count >= Int32.Parse(NumTeamsPerMatchField.Text)) { return(currentMatchup); } //adds a random Team that's available with the lowest cost to the existing teams currentMatchup.teams.Add(FindRandomLowestCostOpponents(currentMatchup)); //mark Team as matched teamsThatHaveBeenMatched[currentMatchup.teams[currentMatchup.teams.Count - 1].teamIndex] = true; //add another Team return(RecursivelyCompareteams(currentMatchup)); }
/// <summary> /// returns the total team weight of a given team /// </summary> private int FindTotalTeamWeight(Matchup currentMatchup, int teamIndex) { int weight = 0; //find the total weight of this team to all the other teams for (int j = 0; j < currentMatchup.teams.Count; j++) { for (int k = 0; k < currentMatchup.teams[j].teamMembers.Count; k++) { for (int l = 0; l < teamsInThisSet[teamIndex].teamMembers.Count; l++) { weight += teamsInThisSet[teamIndex].teamMembers[l].opponentWeights[currentMatchup.teams[j].teamMembers[k].teamIndex]; } } } return(weight); }