/// <summary> /// /// </summary> /// <param name="players"></param> /// <param name="finder"></param> /// <param name="divider"></param> /// <param name="seed"></param> /// <param name="playersPerTeam"></param> /// <param name="eloRange"></param> /// <returns></returns> private Tuple<Team, Team> chooseTeams( List<Player> players, IPlayerFinder finder, ITeamDivider divider, Player seed, int playersPerTeam, int eloRange ) { List<Player> possible = finder.FindPlayers( players, seed.GetElo(), eloRange ); if ( !possible.Contains( seed ) ) { possible.Add( seed ); } if ( possible.Count >= 2 * playersPerTeam ) { possible.Remove( seed ); return divider.DividePlayers( possible, playersPerTeam, seed ); } //Return a tuple of EmptyTeams because we never got enough players together return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() ); }
/// <summary> /// Choose teams based upon placement into Elo buckets /// </summary> /// <param name="players"></param> /// <param name="finder"></param> /// <param name="seed"></param> /// <param name="playersPerTeam"></param> /// <param name="eloRange"></param> /// <returns></returns> private Tuple<Team, Team> chooseTeams( List<Player> players, IPlayerFinder finder, Player seed, int playersPerTeam, int eloRange ) { //Find possible players List<Player> possible = finder.FindPlayers( players, seed.GetElo(), eloRange ); //Add seed to possible players if not already present if ( !possible.Contains( seed ) ) possible.Add( seed ); //Check if there are enough players if ( possible.Count >= 2 * playersPerTeam ) { //Remove seed from list of possible players possible.Remove( seed ); //Bucket players into teams return bucketPlayers( possible, playersPerTeam, seed ); } //Return a tuple of EmptyTeams since we don't have enough players for two Teams return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() ); }
/// <summary> /// /// </summary> /// <param name="players"></param> /// <param name="divider"></param> /// <param name="finder"></param> /// <param name="seed"></param> /// <param name="playersPerTeam"></param> /// <param name="eloRange"></param> /// <param name="maxElo"></param> /// <param name="minElo"></param> /// <returns></returns> private Tuple<Team, Team> chooseTeams( List<Player> players, ITeamDivider divider, IPlayerFinder finder, Player seed, int playersPerTeam, int eloRange, int maxElo, int minElo ) { int max = 0; int min = 0; //Check if the range of Elos to check hits the max if ( seed.GetElo() + eloRange / 2 > maxElo ) { //Set max to maxElo max = maxElo; //Set min min = seed.GetElo() - (eloRange / 2) - (maxElo - seed.GetElo()); } else { //Check if the range of Elos to check hits the min if ( seed.GetElo() - eloRange / 2 < minElo ) { //Set min to minElo min = minElo; //Set max max = seed.GetElo() + (eloRange / 2) + (seed.GetElo() - minElo); } else { //Set max max = seed.GetElo() + eloRange / 2; //Set min min = seed.GetElo() - eloRange / 2; } } //Get possible players List<Player> possible = finder.FindPlayers( players, max, max - min ); //Add seed to list of possible players if ( !possible.Contains( seed ) ) { possible.Add( seed ); } //Check if there are enough players to make a match if ( possible.Count >= 2 * playersPerTeam ) { //Enough players possible.Remove( seed ); //Divide the players into two teams return divider.DividePlayers( possible, playersPerTeam, seed ); } else { //Not enough players, expand the Elo range if ( eloRange < maxElo - minElo ) return chooseTeams( players, divider, finder, seed, playersPerTeam, eloRange * 2, maxElo, minElo ); } //Return a tuple of EmptyTeams because we never got enough players together return new Tuple<Team, Team>( new EmptyTeam(), new EmptyTeam() ); }