Professional Documents
Culture Documents
Portfoliojava
Portfoliojava
ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.concurrent.Task;
import javafx.stage.Stage;
/**
* Purpose: This class represents a Round-Robin tournament where each team
* plays every other team.
* @author Team Green
*
*/
public class RoundRobinTournament extends Tournament
{
//Number of rounds, matchups, and matchups per round
private int numOfRounds;
private int numOfMatchups;
private int numOfMatchPerRound;
private ArrayList<Round> rounds; //The rounds in this tournament
private ArrayList<Team> matchupList; //Matchup list used to divide up matches
/**
/*
* (non-Javadoc)
*
* @see Tournament#createMatchups()
*/
@Override
protected void createMatchups()
{
int numOfTeams = teams.size();
matchupList = new ArrayList<Team>();
//Determine number of rounds
if (numOfTeams % 2 == 0)
{
numOfRounds = numOfTeams - 1;
}
else
{
numOfRounds = numOfTeams;
@Override
protected void createRounds()
{
rounds = new ArrayList<Round>();
//For each round, create the required number of matchups
for ( int i = 0; i < numOfRounds; i++ )
{
ArrayList<Matchup> matchesInRound = new ArrayList<Matchup>();
//For each match, get corresponding teams
for ( int j = 0; j < numOfMatchPerRound; j++ )
{
Team teamA = matchupList.get(j);
Team teamB;
teamB = matchupList.get(j + matchupList.size() - 1 - (j * 2));
if ( teamA.getTeamID() == 0 || teamB.getTeamID() == 0 )
{
//Do nothing, bystander match
}
else
{
//Create the new matchup
Matchup match = new Matchup( teamA, teamB );
matchesInRound.add( match );
}
}
//Create a Round from the list of matchups
rounds.add( new Round(matchesInRound));
//Swap around list order to divide up the next matches
int endOfListIndex = matchupList.size() - 1;
/**
* Purpose: Retrieves the list of rounds for this tournament.
* @return List of rounds
*/
public ArrayList<Round> getRounds()
{
return rounds;
}