public NotIdenticalTeam(ITeamParameters parameters) : base()
 {
     for (int i = 0; i < parameters.NumberOfSeenShepherds; i++)
     {
         Members.Add(AgentFactory.GetShepherd(parameters));
     }
 }
Beispiel #2
0
        public async Task <AuthenticationResponse> Authenticate(AgentName agentName, string username, string password)
        {
            AuthenticationResponse response;

            try
            {
                response = await Constants.ApiConstants.YggdrasilUrl
                           .AppendPathSegment("authenticate")
                           .PostJsonAsync(new AuthenticationRequest()
                {
                    Agent       = AgentFactory.GetAgent(agentName),
                    Username    = username,
                    Password    = password,
                    RequestUser = true
                })
                           .ReceiveJson <AuthenticationResponse>();
            }
            catch (FlurlHttpException ex)
            {
                var error = await ex.GetResponseJsonAsync <ApiError>();

                var errorWriter = Console.Error;
                errorWriter.WriteLine(error.ErrorMessage);

                throw new Exception($"An error occurred while authenticating: {error.ErrorMessage}.");
            }

            return(response);
        }
        public MainGameScreen(Renderer renderer, ContentManager contentManager, string mapPathToLoad)
            : base(contentManager)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }
            if (contentManager == null)
            {
                throw new ArgumentNullException("contentManager");
            }
            if (String.IsNullOrEmpty(mapPathToLoad))
            {
                throw new ArgumentNullException("mapPathToLoad");
            }

            simulationManager = new SimulationManager(DateTime.Now, contentManager.ThoughtPool);
            jobFactory        = new JobFactory(contentManager);
            agentFactory      = new AgentFactory(renderer, contentManager, jobFactory);
            roomFactory       = new RoomFactory(renderer, contentManager);

            simulationManager.HadThought += HandleEmployeeHadThought;
            simulationManager.EmployeeThirstSatisfied += HandleEmployeeThirstSatisfied;
            simulationManager.EmployeeHungerSatisfied += HandleEmployeeHungerSatisfied;

            this.mapPathToLoad = mapPathToLoad;
        }
        protected string GenerateAgent(AgentType agentType, SystemType systemType)
        {
            var agentFactory = new AgentFactory();
            var agent        = agentFactory.CreateAgent(agentType, systemType);

            return(agent.ToString());
        }
Beispiel #5
0
        public double CountFitness(Team team, int seed, bool verbose = false)
        {
            Random r = new Random(seed);

            var fitness = 0.0;

            for (int i = 0; i < parameters.PositionsOfShepherdsSet.Count; i++)
            {
                var seedForSheep = r.Next();

                var sheep = AgentFactory.GetSheep(parameters.PositionsOfSheepSet[i], parameters.SheepType, seedForSheep);

                team.ClearPath();
                team.SetPositions(parameters.PositionsOfShepherdsSet[i]);

                var countFitness = CountFitness(team, sheep);

                if (verbose)
                {
                    Log(i, countFitness, seedForSheep, parameters.PositionsOfShepherdsSet[i], parameters.PositionsOfSheepSet[i]);
                }

                if (!double.IsNaN(fitness))
                {
                    fitness += countFitness;
                }
            }

            return(fitness);
        }
Beispiel #6
0
        private void LoadPlugins()
        {
            string[] plugins = Directory.GetFiles("plugins");
            foreach (string plugin in plugins)
            {
                if (plugin.EndsWith(".dll"))
                {
                    Assembly assembly = Assembly.LoadFrom(plugin);

                    Type[] providedTypes = assembly.GetTypes();
                    foreach (Type t in providedTypes)
                    {
                        if (t.Name != "AgentFactory" && t.BaseType != null && t.BaseType.Name == "AgentFactory" && IsAssemblyOK(plugin, t))
                        {
                            AgentFactory factory = (AgentFactory)Activator.CreateInstance(t);
                            try
                            {
                                string tmp = factory.Creators;
                                typeTextures.Add(factory.ProvidedAgentTypeName, Image.FromFile(plugin.Replace(".dll", "") + ".png"));
                                factories.Add(factory);
                            }
                            catch {
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public static void TestClassInitialize(TestContext testContext)
        {
            Test.Info(string.Format("{0} Class Initialize", testContext.FullyQualifiedTestClassName));
            Test.FullClassName = testContext.FullyQualifiedTestClassName;

            //add the common initialization
            if (StorageAccount == null)
            {
                StorageAccount = GetCloudStorageAccountFromConfig(useHttps: useHttps);
                Test.Info("Got storage account from config: {0}", StorageAccount.ToString(true));
            }

            //init the blob helper for blob related operations
            blobUtil  = new CloudBlobUtil(StorageAccount);
            queueUtil = new CloudQueueUtil(StorageAccount);
            tableUtil = new CloudTableUtil(StorageAccount);
            fileUtil  = new CloudFileUtil(StorageAccount);
            random    = new Random();

            SetCLIEnv(testContext);

            if (null == CommandAgent)
            {
                CommandAgent = AgentFactory.CreateAgent(testContext.Properties);
            }
        }
Beispiel #8
0
        public static string GenerateASCIINameWithInvalidCharacters(int length, char[] InvalidChars = null)
        {
            if (null == InvalidChars)
            {
                InvalidChars = InvalidFileNameCharacters;
            }

            int           numberOfInavlidCharacters = RandomGen.Next(1, length);
            int           numberOfValidCharacters   = length - numberOfInavlidCharacters;
            StringBuilder sb = new StringBuilder(GenerateNameFromRange(numberOfValidCharacters, ValidASCIIRange));
            var           invalidCharList = new List <char>(InvalidFileNameCharacters);

            if (AgentFactory.GetLanguage() == Language.NodeJS)
            {
                invalidCharList.Remove('"');
                invalidCharList.Remove('\'');
            }

            if (AgentFactory.GetOSType() != OSType.Windows)
            {
                // remove bash control characters
                invalidCharList.Remove('(');
                invalidCharList.Remove('$');
            }

            for (int i = 0; i < numberOfInavlidCharacters; i++)
            {
                int  position         = RandomGen.Next(sb.Length);
                char invalidCharacter = invalidCharList[RandomGen.Next(invalidCharList.Count)];
                sb.Insert(position, invalidCharacter);
            }

            return(sb.ToString());
        }
Beispiel #9
0
        public Task Process(Level context)
        {
            var enemyUnits      = SetupEnemies(context.Id);
            var playerGameUnits = AgentFactory.GenerateGameUnits(enemyUnits);

            context.GameUnits.AddRange(playerGameUnits);
            return(Task.CompletedTask);
        }
 public static IEnumerable <GameUnit> GenerateGameUnits(this AgentFactory factory, IEnumerable <Unit> units)
 {
     foreach (var unit in units)
     {
         var agent = factory.CreateFor(unit);
         yield return(new GameUnit(unit, agent));
     }
 }
        private string GenerateAgent()
        {
            var randAgent  = GenerateRandomNumber(2);
            var randSystem = GenerateRandomNumber(3);

            var agentFactory = new AgentFactory();

            return(agentFactory.CreateAgent((AgentType)randAgent, (SystemType)randSystem).ToString());
        }
Beispiel #12
0
        public override void InitAgent()
        {
            CommandAgent = AgentFactory.CreateAgent(TestContext.Properties);

            SetCLIEnv(TestContext);

            Test.Start(TestContext.FullyQualifiedTestClassName, TestContext.TestName);
            OnTestSetup();
        }
Beispiel #13
0
        public static void RegisterAgentFactory(AgentFactory agentFactory)
        {
            IDiagnosable diagnosable = agentFactory as IDiagnosable;

            if (diagnosable != null)
            {
                ProcessAccessManager.RegisterComponent(diagnosable);
            }
        }
Beispiel #14
0
    // Use this for initialization
    void Start()
    {
        var agent = (Citizen)AgentFactory.CreateAgent(AgentClass.Adult);

        agent.setAgent_name("Joe Smith");

        AgentFactory.CreateAgent(AgentClass.Adult);

        BuildingFactory.createBuilding(BuildingClass.Residential);
    }
        public IdenticalTeam(ITeamParameters parameters) : base()
        {
            if (parameters.NumberOfShepherds == 0)
            {
                return;
            }

            Members.Add(AgentFactory.GetShepherd(parameters));
            Resize(parameters.NumberOfShepherds);
        }
Beispiel #16
0
        public I_AgentSet Generate(int agent_seed, AgentInitMode mode)
        {
            List <I_Agent> agent_list = new List <I_Agent>();

            RandomPool.Declare(SeedEnum.AgentSeed, agent_seed);
            foreach (var node in this.MyNetwork.NodeList)
            {
                var agent = new AgentFactory().Generate(node, this.InitOpinion, this.GreenSigma, this.RedSigma, mode);
                agent_list.Add(agent);
            }
            return(new BaseAgentSet(agent_list, agent_seed));
        }
Beispiel #17
0
        public LevelEnemyUnitSetupProcessor(AgentFactory agentFactory, IItemTemplateRepository itemTemplateRepository, IRandomizer randomizer, IUnitIdPool unitIdPool, UnitBuilder unitBuilder, IAbilityRepository abilityRepository, ISpellRepository spellRepository, ICardEffectsRepository cardEffectsRepository)
        {
            AgentFactory           = agentFactory;
            ItemTemplateRepository = itemTemplateRepository;
            Randomizer             = randomizer;
            UnitIdPool             = unitIdPool;
            UnitBuilder            = unitBuilder;
            AbilityRepository      = abilityRepository;
            SpellRepository        = spellRepository;
            CardEffectsRepository  = cardEffectsRepository;

            GlobalLootTable = GenerateLootTable();
        }
        public void CreateDirectoryWith255Unicodes()
        {
            if (OSType.Windows != AgentFactory.GetOSType())
            {
                return;
            }

            foreach (var dirName in FileNamingGenerator.GenerateValidateUnicodeName(FileNamingGenerator.MaxFileNameLength))
            {
                this.CreateDirectoryInternal(dirName, traceCommand: false);
                CommandAgent.Clear();
            }
        }
Beispiel #19
0
        protected JsonResult Json <TAgent, TViewModel, TRequestData>(Guid itemId, TRequestData agentParameters)
            where TAgent : Agent <TViewModel>
            where TViewModel : BaseViewModel, new()
        {
            var agentContext = new AgentContext(IgnitionControllerContext, SitecoreContext, new NullPage(), SitecoreContext.GetItem <IModelBase>(itemId))
            {
                AgentParameters = agentParameters,
            };
            var agent = AgentFactory.CreateAgent <TAgent, TViewModel>(agentContext);

            agent.PopulateModel();

            return(Json(agent.ViewModel));
        }
        protected ActionResult GetViewResult <TAgent, TViewModel, TParams>(TParams parameters, Dictionary <string, object> viewdata)
            where TAgent : Agent <TViewModel>
            where TViewModel : BaseViewModel, new()
            where TParams : IParamsBase
        {
            var moduleName = GetType().Name.Replace(GetType().Namespace ?? string.Empty, string.Empty).Replace("Controller", string.Empty);

            Context.ContextPage         = GetContextItem <IPage>(true, true);
            Context.ModuleWrapperName   = moduleName;
            Context.RenderingParameters = parameters;
            Context.ViewData            = viewdata;
            var agent = AgentFactory.CreateAgent <TAgent, TViewModel>(Context);

            agent.PopulateModel();
            return(View(agent.ViewPath, agent.ViewModel));
        }
Beispiel #21
0
        protected ViewResult View <TAgent, TViewModel, TParams>(object agentParameters)
            where TAgent : Agent <TViewModel>
            where TViewModel : BaseViewModel, new()
            where TParams : class, IParamsBase
        {
            var moduleName = GetType().Name.Replace(GetType().Namespace ?? string.Empty, string.Empty).Replace("Controller", string.Empty);

            Context.ContextPage         = GetContextItem <IPage>(true, true);
            Context.ModuleWrapperName   = moduleName;
            Context.RenderingParameters = GetRenderingParameters <TParams>();
            Context.AgentParameters     = agentParameters;
            var agent = AgentFactory.CreateAgent <TAgent, TViewModel>(Context);

            agent.PopulateModel();
            return(View(agent.ViewPath, agent.ViewModel));
        }
Beispiel #22
0
        public void Init(int Humans, int Assassins)
        {
            var agentFactory = new AgentFactory();
            var humanFactory = new HumanFactory();

            for (int i = 0; i < Humans; i++)
            {
                humans.Add(humanFactory.CreateHuman());
            }

            for (int i = 0; i < Assassins; i++)
            {
                humans.Add(agentFactory.CreateHuman(humans));
            }

            field.Update(this.humans);
        }
Beispiel #23
0
    // Use this for initialization
    void Start()
    {
        // 生成羊群,已在SheepGroup类中实现

        if (Config.randomBorn)
        {
            RandomBorn();
        }

        // 添加目标点
        GameObject go = Resources.Load <GameObject>("Prefabs/target") as GameObject;

        target = Instantiate(go, Config.targetPos, Quaternion.identity);

        // 添加牧羊犬
        go       = AgentFactory.GetAgent();
        shepherd = Instantiate(go, Config.shepherdPos, Quaternion.identity);
    }
Beispiel #24
0
    public void AddAgent(AgentFactory agent, string role = null)
    {
        Agent a = agent.GetAgent();

        if (role != null)
        {
            a.SetRole(role);
        }
        else
        {
            if (a.role == null)
            {
                throw new ArgumentNullException("[MICELIO] Impossível inserir um agente sem uma role definida." +
                                                " Adicione uma role antes de inserir o objeto ou na criação dele.");
            }
        }
        this.agents.Add(a);
    }
Beispiel #25
0
        protected static void SetCLIEnv(TestContext testContext)
        {
            //add the language specific initialization
            lang = AgentFactory.GetLanguage(testContext.Properties);

            isMooncake = Utility.GetTargetEnvironment().Name == "AzureChinaCloud";

            string mode = Test.Data.Get("IsResourceMode");

            if (!string.IsNullOrEmpty(mode))
            {
                isResourceMode = bool.Parse(mode);
            }

            if (lang == Language.PowerShell)
            {
                if (isResourceMode)
                {
                    PowerShellAgent.ImportModules(Constants.ResourceModulePaths);;
                }
                else
                {
                    PowerShellAgent.ImportModules(Constants.ServiceModulePaths);
                }

                string snapInName = Test.Data.Get("PSSnapInName");
                if (!string.IsNullOrWhiteSpace(snapInName))
                {
                    PowerShellAgent.AddSnapIn(snapInName);
                }

                //set the default storage context
                PowerShellAgent.SetStorageContext(StorageAccount.ToString(true));
            }
            else if (lang == Language.NodeJS)
            {
                NodeJSAgent.GetOSConfig(Test.Data);

                // use ConnectionString parameter by default in function test
                NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true);

                FileUtil.GetOSConfig(Test.Data);
            }
        }
Beispiel #26
0
        private bool IsAssemblyOK(string plugin, Type t)
        {
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "");
            AppDomain    appDomain = AppDomain.CreateDomain("AppHostDomain", null, setup);
            AgentFactory factory   = (AgentFactory)(appDomain.CreateInstanceFromAndUnwrap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, plugin), t.FullName));



            NameSpaceChecker tmp   = (NameSpaceChecker)(appDomain.CreateInstanceFromAndUnwrap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReflectionChecker.dll"), "ReflectionChecker.NameSpaceChecker"));
            string           error = "";

            if (tmp.IsAddonInvalid(out error))
            {
                return(false);
            }
            return(true);
        }
Beispiel #27
0
        protected ViewResult View <TAgent, TViewModel, TParams>(object agentParameters)
            where TAgent : Agent <TViewModel>
            where TViewModel : BaseViewModel, new()
            where TParams : class, IParamsBase
        {
            var contextPage         = GetContextItem <IPage>(true, true) ?? new NullPage();
            var datasourceItem      = GetDataSourceItem();
            var renderingParameters = GetRenderingParameters <TParams>();
            var agentContext        = new AgentContext(IgnitionControllerContext, SitecoreContext, contextPage, datasourceItem)
            {
                AgentParameters     = agentParameters,
                RenderingParameters = renderingParameters
            };

            var agent = AgentFactory.CreateAgent <TAgent, TViewModel>(agentContext);

            agent.PopulateModel();

            return(View(agent.ViewPath, agent.ViewModel));
        }
Beispiel #28
0
        /// <summary
        /// >Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer.
        /// </summary>
        /// <param name="filePath">Path to the .tmx file to load</param>
        /// <param name="renderer">Renderer object used to load tileset textures</param>
        public TiledMap(string filePath, Renderer renderer, AgentFactory agentFactory, string contentRoot = "")
        {
            this.agentFactory = agentFactory;

            MapContent mapContent = new MapContent(filePath, renderer, contentRoot);

            TileWidth  = mapContent.TileWidth;
            TileHeight = mapContent.TileHeight;

            PixelWidth  = mapContent.Width * TileWidth;
            PixelHeight = mapContent.Height * TileHeight;

            HorizontalTileCount = mapContent.Width;
            VerticalTileCount   = mapContent.Height;

            CreateLayers(mapContent);
            CalculateTilePositions(mapContent.Orientation);
            CalculatePathNodeNeighbors();
            CreateMapCells(mapContent);
            InitializeMapCells();
        }
Beispiel #29
0
        private void StartHerding()
        {
            ButtonPause.Enabled  = true;
            ButtonResume.Enabled = false;

            ButtonStepBack.Enabled    = false;
            ButtonStepForward.Enabled = false;

            TransformPositions();
            var parameters = (OptimizationParameters) new XmlSerializer(typeof(OptimizationParameters)).Deserialize(new StringReader(richTextBoxParameters.Text));

            if (checkBoxRandom.Checked)
            {
                parameters.PositionsOfShepherds = parameters.PositionsOfShepherds.Randomize(0, 400).ToList();
                parameters.PositionsOfSheep     = parameters.PositionsOfSheep.Randomize(0, 400).ToList();
            }

            var sheep = AgentFactory.GetSheep(parameters.PositionsOfSheep, parameters.SheepType, parameters.SeedForRandomSheepForBest);

            var shepherds = richTextBoxShepherds.Text.Split('\n')
                            .Where(x => string.IsNullOrEmpty(x) == false)
                            .Select(x => repository.LoadShepherd(x));

            var team = TeamFactory.GetNotIdenticalTeam(shepherds.Cast <ThinkingAgent>().ToList());

            team.Resize(parameters.PositionsOfShepherds.Count());
            team.SetPositions(parameters.PositionsOfShepherds);

            world = new ViewableWorld(
                HerdingX,
                HerdingY,
                checkBoxAnimationMode.Checked ? MilisecondsBetweenSteps : 0,
                team,
                sheep);

            world.Start(parameters.TurnsOfHerding);

            paint = true;
        }
    public string CreateFollowUp()
    {
        SaleEntity sale = AgentFactory.GetSaleAgent().GetSaleEntity(SuperStateManager.GetCurrentId("sale"));

        if (sale != null)
        {
            AppointmentAgent  agent = new AppointmentAgent();
            AppointmentEntity app   = agent.CreateDefaultAppointmentEntityByType(SuperOffice.Data.TaskType.Appointment);
            app.Contact     = sale.Contact;
            app.Person      = sale.Person;
            app.Associate   = sale.Associate;
            app.Description = "Sample Follow-up from Sale " + sale.SaleId;
            app.StartDate   = DateTime.Today.AddDays(7);
            app.EndDate     = app.StartDate;
            app             = agent.SaveAppointmentEntity(app);
            return(app.AppointmentId.ToString());
        }
        else
        {
            return(String.Empty);
        }
    }