Esempio n. 1
0
        public RegionManager(
            IRegionFactory regionFactory,
            IMapManager mapManager,
            ITeamFactory teamFactory,
            IMenuFactory menuFactory,
            IDecisionManager decisionManager,
            BattlefieldFactory battlefieldFactory,
            IInput input,
            IOutput output,
            IChanceService chanceService)
        {
            _mapManager         = mapManager;
            _teamFactory        = teamFactory;
            _decisionManager    = decisionManager;
            _menuFactory        = menuFactory;
            _battlefieldFactory = battlefieldFactory;

            _input         = input;
            _output        = output;
            _chanceService = chanceService;

            IEnumerable <WorldRegion> allRegionEnums = EnumHelperMethods.GetAllValuesForEnum <WorldRegion>();
            IEnumerable <Region>      allRegions     = regionFactory.GetRegions(allRegionEnums);

            _regionalMap = mapManager.GetRegionalMap(allRegions.ToArray());
        }
Esempio n. 2
0
 public FlagshipVisitorService(FlagshipContext flagshipContext)
 {
     this.flagshipContext = flagshipContext;
     decisionManager      = flagshipContext.DecisionManager;
     sender           = flagshipContext.Sender;
     exceptionHandler = flagshipContext.ExceptionHandler;
     logger           = flagshipContext.Logger;
 }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        WorldStateManager.currentAgents.Add(this);
//		Debug.Log ("ID = " + ID);
        knowledgeBase    = new KnowledgeBase(this);
        this.sModule     = new SensorModule(this);
        decisionManager  = new SwarmOpsDecisionManager(knowledgeBase, sensorModule);
        flightController = new NewFlightController(this.gameObject, this.sensorModule);
    }
Esempio n. 4
0
        public Form1(IDecisionManager decisionManager, IComparerPreparator preparator)
        {
            InitializeComponent();
            CenterToScreen();

            DecisionManager = decisionManager;
            Preparator      = preparator;

            DrawInitialState(preparator);
        }
Esempio n. 5
0
        public FlagshipContext(string environmentId, string apiKey, FlagshipOptions options = null)
        {
            EnvironmentId    = environmentId;
            ApiKey           = apiKey;
            Options          = options;
            Logger           = options?.Logger ?? new DefaultLogger();
            ExceptionHandler = options?.ExceptionHandler ?? new DefaultExceptionHandler(Logger);
            Sender           = new Sender(this);

            var decisionMode = options?.DecisionMode ?? Mode.API;

            if (decisionMode == Mode.Bucketing)
            {
                DecisionManager = new BucketingClient(this);
            }
            else
            {
                DecisionManager = new APIDecisionManager(this);
            }
        }
Esempio n. 6
0
        public TArea Advance(IDecisionManager decisionManager, Team advancingTeam)
        {
            TArea newArea;

            if (typeof(TArea) == typeof(Region))
            {
                Region currentRegion = CurrentArea as Region;

                RegionCompletedEventArgs e = new RegionCompletedEventArgs(currentRegion);
                currentRegion?.OnRegionCompleted(e);
            }
            if (typeof(TArea) == typeof(SubRegion))
            {
                SubRegion currentSubRegion = CurrentArea as SubRegion;

                SubRegionCompletedEventArgs e = new SubRegionCompletedEventArgs(currentSubRegion);
                currentSubRegion?.OnSubRegionCompleted(e);
            }

            MapPath <TArea, TAreaId> currentPath = MapPaths.First(p => p.From.Equals(CurrentArea));

            List <TArea> availableAreas = currentPath.To.GetAvaialableAreas().ToList();

            if (availableAreas.Count == 0)
            {
                newArea = null;
            }
            else if (availableAreas.Count == 1)
            {
                newArea = availableAreas[0];
            }
            else
            {
                newArea = decisionManager.PickNextArea(currentPath.To, advancingTeam);
            }

            CurrentArea = newArea;
            return(newArea);
        }
Esempio n. 7
0
 public void CleanUp()
 {
     if (flightController != null)
     {
         flightController.CleanUp();
     }
     if (knowledgeBase != null)
     {
         knowledgeBase.CleanUp();
     }
     if (sModule != null)
     {
         sModule.CleanUp();
     }
     if (decisionManager != null)
     {
         decisionManager.CleanUp();
     }
     flightController = null;
     knowledgeBase    = null;
     sModule          = null;
     decisionManager  = null;
 }
 public MockRegionFactory(IDecisionManager decisionManager)
 {
     RealFactory = new RegionFactory(decisionManager);
 }
Esempio n. 9
0
        public void Run(IDecisionManager decisionManager, IComparerPreparator preparator)
        {
            bool isWorking = true;

            while (isWorking)
            {
                Console.WriteLine("Welcome to the comparer application.");
                ParticipatorsContainer container = new ParticipatorsContainer(); //мб чтобы убрать дублирование кода можно было бы через делегат для ex.Message,
                //но особого упрощения кода в этом не вижу
                try
                {
                    container = preparator.Prepare(); //есть контейнер файлов, в котором есть имя и полный путь каждого файла из папки
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
                container.RemainderOfInitialCapacity = container.Capacity;

                Round round = preparator.CreateRound(container.Capacity, container.ObjectsArray);

                bool roundActive = true;
                while (roundActive)
                {
                    round = decisionManager.CreateNewRoundIfNeeded(round, container);

                    Console.WriteLine();
                    Console.WriteLine($"Current Stage: {round.Stage}. Round: {round.RoundNumber} out of {round.Pairs.Count + container.NextRoundObjectsArray.Count}");
                    Console.WriteLine($"Choose the best between: {round.Pairs[0].First().FileName} and {round.Pairs[0].Last().FileName}");
                    Console.WriteLine($"To make your decision write down \"{round.Pairs[0].First().FileName}\" or \"{round.Pairs[0].Last().FileName}\"");

                    string choice = Console.ReadLine().ToLower();
                    if (choice == round.Pairs[0].First().FileName.ToLower() || choice == round.Pairs[0].Last().FileName.ToLower())
                    {
                        decisionManager.MakeDecision(choice, round, container);
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Unknown input. Please, try again");
                    }

                    if (decisionManager.CheckWinCondition(container))
                    {
                        Console.WriteLine();
                        Console.WriteLine($"The winner is {container.NextRoundObjectsArray[0].FileName}!");
                        Console.WriteLine();
                        roundActive = false;
                    }
                }

                bool continueNeeded = false;
                while (!continueNeeded)
                {
                    Console.WriteLine("Would you like to restart the comparer application?\nWrite down \"yes\" or \"no\"");
                    string answer = Console.ReadLine().ToLower();
                    if (answer == "yes")
                    {
                        Console.WriteLine();
                        continueNeeded = true;
                    }
                    else if (answer == "no")
                    {
                        continueNeeded = true;
                        isWorking      = false;
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Unknown command");
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Start the Flagship SDK.
        /// </summary>
        /// <param name="envId">Environment id provided by Flagship.</param>
        /// <param name="apiKey">Api authentication key provided by Flagship.</param>
        /// <param name="config">Custom flagship configuration.</param>
        public static void Start(string envId, string apiKey, FlagshipConfig config = null)
        {
#if NET40 || NETSTANDARD2_0
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
#else
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#endif

            if (config == null)
            {
                config = new DecisionApiConfig();
            }
            var fsInstance = GetInstance();

            fsInstance._config = config;

            if (config.LogManager == null)
            {
                config.LogManager = new FsLogManager();
            }

            if (string.IsNullOrWhiteSpace(envId) || string.IsNullOrWhiteSpace(apiKey))
            {
                fsInstance.SetStatus(FlagshipStatus.NOT_INITIALIZED);
                Log.LogError(config, Constants.INITIALIZATION_PARAM_ERROR, Constants.PROCESS_INITIALIZATION);
                return;
            }

            config.EnvId  = envId;
            config.ApiKey = apiKey;

            fsInstance.SetStatus(FlagshipStatus.STARTING);
            var httpClient = new HttpClient()
            {
                Timeout = config.Timeout ?? TimeSpan.FromMilliseconds(Constants.REQUEST_TIME_OUT)
            };

            IDecisionManager decisionManager = fsInstance._configManager?.DecisionManager;

            if (decisionManager != null && decisionManager is BucketingManager bucketingManager)
            {
                bucketingManager.StopPolling();
            }

            if (config.DecisionMode == DecisionMode.BUCKETING)
            {
                decisionManager = new BucketingManager((BucketingConfig)config, httpClient, Murmur.MurmurHash.Create32());
                _ = ((BucketingManager)decisionManager).StartPolling();
            }
            else
            {
                decisionManager = new ApiManager(config, httpClient);
            }

            var trackingManager = new TrackingManager(config, httpClient);

            decisionManager.StatusChange += DecisionManager_StatusChange;

            if (fsInstance._configManager == null)
            {
                fsInstance._configManager = new ConfigManager(config, decisionManager, trackingManager);
            }
            else
            {
                fsInstance._configManager.DecisionManager = decisionManager;
                fsInstance._configManager.TrackingManager = trackingManager;
            }

            fsInstance.SetStatus(FlagshipStatus.READY);
            Log.LogInfo(config, string.Format(Constants.SDK_STARTED_INFO, Constants.SDK_VERSION),
                        Constants.PROCESS_INITIALIZATION);
        }
Esempio n. 11
0
 public RegionFactory(IDecisionManager decisionManager)
 {
     DecisionManager = decisionManager;
 }
Esempio n. 12
0
 public ConfigManager(FlagshipConfig config, IDecisionManager decisionManager, ITrackingManager trackingManager)
 {
     DecisionManager = decisionManager;
     Config          = config;
     TrackingManager = trackingManager;
 }