/// <summary>
        /// 
        /// </summary>
        /// <param name="players"></param>
        /// <param name="teamChooser"></param>
        /// <param name="seedChooser"></param>
        /// <param name="playersPerTeam"></param>
        /// <returns></returns>
        private List<Tuple<Team, Team>> chooseAllTeams( List<Player> players, ITeamChooser teamChooser, ISeedChooser seedChooser, int playersPerTeam )
        {
            List<Tuple<Team, Team>> games = new List<Tuple<Team, Team>>();
            List<Player> t = new List<Player>( players );
            List<Player> played = new List<Player>();
            int count = 0;

            seedChooser.Initialize();

            while ( t.Count >= 2 * playersPerTeam )
            {
                Player seed = seedChooser.ChooseSeed( t );

                if ( seed != null )
                {
                    Tuple<Team, Team> game = teamChooser.ChooseTeams( t, seed, playersPerTeam );
                    count++;

                    if ( game == null || isEmptyGame( game ) )
                    {
                        seedChooser.IgnorePlayer( seed );

                        continue;
                    }

                    games.Add( game );

                    foreach ( Player p in game.Item1.Players )
                    {
                        if ( played.Contains( p ) )
                            Console.WriteLine( "Bad!" );

                        t.Remove( p );
                        played.Add( p );
                    }

                    foreach ( Player p in game.Item2.Players )
                    {
                        if ( played.Contains( p ) )
                            Console.WriteLine( "Bad!" );

                        t.Remove( p );
                        played.Add( p );
                    }
                }
            }

            return games;
        }
예제 #2
0
        /// <summary>
        /// Run multiple rounds of simultaneous games so that each player is only in one game at a time.
        /// </summary>
        /// <param name="numGames">The number of games to run simultaneously</param>
        /// <param name="numRounds">The number of rounds of simultaneous games</param>
        public void RunOnly( int numGames, int numRounds, ISeedChooser seedChooser )
        {
            for ( int i = 0; i < numRounds; i++ )
            {
                //Play a round of matches

                //Randomize players
                List<Player> t = _players.RandomOrdering().ToList();
                //List of games
                List<Tuple<Team, Team>> games = new List<Tuple<Team, Team>>();
                //Get players that are online for this round
                List<Player> players = getSubset( t, NUM_PLAYERS_ONLINE_AT_ONCE );

                int count = 0;

                //Initialize seed chooser
                seedChooser.Initialize();

                //Create games
                while ( count < numGames )
                {
                    //Get a seed
                    Player seed = seedChooser.ChooseSeed( players );

                    if ( seed != null )
                    {
                        //Make a game
                        Tuple<Team, Team> game = TeamChooser.ChooseTeams( players, seed, PLAYERS_PER_TEAM );

                        //Check if the game is valid
                        if ( game != null && !isEmptyGame( game ) )
                        {
                            //Add to list of games to play
                            games.Add( game );

                            //Remove players so that they aren't in any games in this round
                            foreach ( Player p in game.Item1.Players )
                                players.Remove( p );

                            foreach ( Player p in game.Item2.Players )
                                players.Remove( p );
                        }
                        else
                        {
                            //Ignore a seed that couldn't make a valid game
                            seedChooser.IgnorePlayer( seed );
                        }
                    }

                    count++;
                }

                //Play out the games for this round
                playGames( games );
            }

            outputGameInfo( numGames * numRounds );
        }