예제 #1
0
        public Competition CreateCompetition(AssemblyFile[] files, IEnumerable<TeamInfo> teams, IEnumerable<TeamInfo> networkTeams)
        {
            DynamicAssemblyTypeFinder dynamicAssemblyTypeFinder = new DynamicAssemblyTypeFinder();
              dynamicAssemblyTypeFinder.AddAll(files);

              IGame game = dynamicAssemblyTypeFinder.Create<IGame>().Single();
              Competition competition = new Competition(game);

              IEnumerable<string> teamNames = teams.Select(team => team.Name);
              foreach (IBotFactory botFactory in dynamicAssemblyTypeFinder.Create<IBotFactory>())
              {
            string teamName = Path.GetFileNameWithoutExtension(botFactory.GetType().Assembly.Location);
            if (teamNames.Contains(teamName))
            {
              competition.AddPlayer(new BotPlayer(teamName, botFactory.CreateBot()));
            }
              }

              INetworkBotFactory factory = dynamicAssemblyTypeFinder.Create<INetworkBotFactory>().Single();
              foreach (TeamInfo team in networkTeams)
              {
            competition.AddPlayer(new BotPlayer(team.Name, factory.CreateBot(team.Url)));
              }

              return competition;
        }
        public Competition CreateCompetition(AssemblyFile[] files)
        {
            DynamicAssemblyTypeFinder dynamicAssemblyTypeFinder = new DynamicAssemblyTypeFinder();
            dynamicAssemblyTypeFinder.AddAll(files);

            IGame game = new RockPaperScissorsPro.CompeteGameWrapper();

            Competition competition = new Competition(game);
            IEnumerable<IBotFactory> botFactoryList = dynamicAssemblyTypeFinder.Create<IBotFactory>();

            foreach (IBotFactory botFactory in botFactoryList)
            {
                //if unable to create botFactory, skip adding it to the list
                if (botFactory != null)
                {
                    string teamName = Team.ConvertFileToTeamName(botFactory.GetType().Assembly.Location);
                    competition.AddPlayer(new BotPlayer(teamName, null, botFactory));
                }
            }

            // look for any players that were downloaded but not in competition.  make sure they
            // get a bot that forfeits
            foreach (AssemblyFile f in files)
            {
                string teamName = Team.ConvertFileToTeamName(f.Path);
                if (!competition.ContainsPlayer(teamName))
                {
                    competition.AddPlayer(new BotPlayer(teamName, null, null));
                }
            }

            return competition;
        }