Kyle-Falconer
10/29/2013 - 1:23 PM

A method for round-robin assigning teams to play each other, given a list of Team objects and returning a list of Match, each containing two

A method for round-robin assigning teams to play each other, given a list of Team objects and returning a list of Match, each containing two Team objects.

public List<Match> roundRobin(List<Team> teamList){
  //Round-Robin construction of initial match list.
  List<Match> matches= new ArrayList<Match>();
  for(int i=0;i<teamList.size();i++){
    for(int j=i+1; j<teamList.size();j++){
        Match nextMatch = new Match(teamList.get(i),teamList.get(j));
        matches.add(nextMatch);
    }
  }
  setMatchList(matches);
  return matches;
}