Skip to content

Instantly share code, notes, and snippets.

@Kyle-Falconer
Created October 29, 2013 13:23
Show Gist options
  • Save Kyle-Falconer/7214565 to your computer and use it in GitHub Desktop.
Save Kyle-Falconer/7214565 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment