Ejemplo n.º 1
0
        public IAction PrepareInstance(IAction action, IAlgorithmContext algorithmContext)
        {
            if (action is IContextInitializable contextInitializable)
            {
                contextInitializable.Initialize(algorithmContext);
            }
            if (action is IScenariosAccess scenarioAccessObj)
            {
                scenarioAccessObj.SetTargetScenario(_scenarioRepository.Scenarios.FirstOrDefault(x => x.Id.Equals(((IScenariosAccess)action).TargetScenarioId)));
            }
            if (action is IUsersGeolocationAccess geolocationAccessObj)
            {
                geolocationAccessObj.SetNeedTargets(() => _usersRepository.Users.ToArray());
            }
            if (action is IMessagesSender messagesSender)
            {
                messagesSender.SetNeedTargets(() => _usersRepository.Users.ToArray());
            }
            if (action is IScenariosEnumerator scenariosEnumerator)
            {
                var scenariosActionSource = new ScenarioActionSource(_usersRepository.SystemUser, ScenarioStartupSource.OtherScenario, ScenarioAction.Execute);
                scenariosEnumerator.SetCasts(() =>
                                             _scenarioRepository
                                             .Scenarios
                                             .Where(x =>
                                                    x.IsAccessAvailable(scenariosActionSource))
                                             .Select(x => x.CreateCast())
                                             .ToArray());
            }

            return(action);
        }
Ejemplo n.º 2
0
        protected override void _runAlgorithm(IAlgorithmContext context)
        {
            DungeonTiles workingTiles = context.D.Tiles;

            bool[,] algMask = context.Mask;
            _ctx            = context;

            if (this.WallStrategy == WallFormation.Tiles)
            {
                throw new NotImplementedException();
            }

            bool[,] existingDataMask = new bool[workingTiles.Height, workingTiles.Width];

            for (int y = 0; y < workingTiles.Height; ++y)
            {
                for (int x = 0; x < workingTiles.Width; ++x)
                {
                    existingDataMask[y, x] = algMask[y, x] && (workingTiles[y, x].Physics == Tile.MoveType.Wall);
                }
            }

            // Prime the dungeon tiles by opening them all up (as appropriate).
            // "Ignore" shouldn't wipe existing data, but...
            switch (BuildStrategy)
            {
            case ExistingDataHandling.Ignore:
            case ExistingDataHandling.Avoid:
                workingTiles.SetAllToo(Tile.MoveType.Open_HORIZ, existingDataMask);
                break;

            case ExistingDataHandling.Overwrite:
                workingTiles.SetAllToo(Tile.MoveType.Open_HORIZ, algMask);
                break;

            default:
                throw new NotImplementedException();
            }

            // Run algorithm with the appropriate mask
            // ... "Ignore" SHOULD build walls over existing data
            Rectangle startRegion = new Rectangle(0, 0, workingTiles.Width, workingTiles.Height);

            switch (BuildStrategy)
            {
            case ExistingDataHandling.Avoid:
                this.Divide(workingTiles, startRegion, existingDataMask, algMask, context.R);
                break;

            case ExistingDataHandling.Ignore:
            case ExistingDataHandling.Overwrite:
                this.Divide(workingTiles, startRegion, algMask, algMask, context.R);
                break;

            default:
                throw new NotImplementedException();
            }

            _ctx = null;
        }
Ejemplo n.º 3
0
        protected override void _runAlgorithm(IAlgorithmContext context)
        {
            DungeonTiles workingDungeon = context.D.Tiles;
            ISet <Tile>  deadEnds       = new HashSet <Tile>();

            for (int i = 0; i < this.FillPasses; ++i)
            {
                for (int y = 0; y < workingDungeon.Height; ++y)
                {
                    for (int x = 0; x < workingDungeon.Width; ++x)
                    {
                        if (!context.Mask[y, x] || workingDungeon[y, x].Physics == Tile.MoveType.Wall)
                        {
                            continue;
                        }
                        bool physicsDeadEnd   = (workingDungeon[y, x].Physics.SidesOpened() == 1);
                        bool adjacentsdeadEnd = (workingDungeon.GetAdjacentOpensFor(x, y) == 1);
                        if (!physicsDeadEnd && !adjacentsdeadEnd)
                        {
                            continue;
                        }
                        workingDungeon[y, x].Physics = workingDungeon[y, x].Physics.CloseOff(Tile.MoveType.Open_HORIZ);
                    }
                }
                workingDungeon.Parent.CreateGroup(deadEnds);
            }
        }
Ejemplo n.º 4
0
        static void MakeAWithdrawl(IAlgorithmContext context)
        {
            Console.WriteLine("Enter amount: ");
            string input = Console.ReadLine();

            if (double.TryParse(input, out var amount))
            {
                Console.WriteLine();
                Console.WriteLine("Opening Balance");
                Console.WriteLine(context.Balance.ToString("C", context.Culture));

                Console.WriteLine();

                IAlgorithmOutput output = context.Withdraw(amount);

                Console.WriteLine("Input");
                Console.WriteLine(amount.ToString("C", context.Culture));
                Console.WriteLine("Output");
                Console.WriteLine(output.Output);
                Console.WriteLine("Balance");
                Console.WriteLine(context.Balance.ToString("C", context.Culture));
            }
            else
            {
                Console.WriteLine("Couldn't parse input...");
            }
        }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (CancelExecutionAction)actionHolder.Action;
     action1View.Refresh(actionHolder, algoContext);
 }
Ejemplo n.º 6
0
        public static IConstructorElement Create(ActionHolder actionHolder, IAlgorithmContext algoContext)
        {
            IConstructorElement element;

            if (actionHolder.Action is ExecuteAction)
            {
                element = new ExecuteActionView();
            }
            else if (actionHolder.Action is SetReturnValueAction)
            {
                element = new ReturnScenarioValueView();
            }
            else if (actionHolder.Action is IfAction)
            {
                element = new IfActionView();
            }
            else if (actionHolder.Action is WhileAction)
            {
                element = new WhileActionView();
            }
            else if (actionHolder.Action is CancelExecutionAction)
            {
                element = new CancelExecutionActionView();
            }
            else
            {
                throw new NotImplementedException();
            }
            element.Refresh(actionHolder, algoContext);
            return(element);
        }
Ejemplo n.º 7
0
 protected override void _runAlgorithm(IAlgorithmContext context)
 {
     // Find all dead ends and do a depth-first search for the first tile
     // that has greater than two openings, and build a weighted list of
     // dead-end halls
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _checkerAction   = (CheckerAction)actionHolder.Action;
     textBlock.Text   = _checkerAction.ComparisonType.Caption;
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _pair            = (CheckerOperatorPair)ActionHolder.Action;
     operatorView.Refresh(actionHolder, algoContext);
     actionView.Refresh(new ActionHolder((IAction)_pair.Checker), algoContext);
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (WhileAction)actionHolder.Action;
     actionView.Refresh(new ActionHolder(_action.Action), algoContext);
     checkerView.Refresh(new ActionHolder(_action.Checker), algoContext);
 }
Ejemplo n.º 11
0
 public ExecutionContext(IAlgorithmContext algorithmContext, string input, string previousValue, OutputChangedDelegates output, SafeCancellationToken cancellationTokenSource)
 {
     OutputChanged           = output;
     CancellationTokenSource = cancellationTokenSource;
     AlgorithmContext        = algorithmContext;
     Input         = input;
     PreviousValue = previousValue;
 }
Ejemplo n.º 12
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     AlgorithmContext = algoContext;
     ActionHolder     = actionHolder;
     Model            = new ActionModel();
     Model.Refresh(ActionHolder);
     DataContext = Model;
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (ExecuteAction)actionHolder.Action;
     action1View.Refresh(_action.MasterActionHolder, algoContext);
     action2View.Refresh(_action.InputValue, algoContext);
     Action2EqualizeToAction1();
 }
Ejemplo n.º 14
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (IfAction)actionHolder.Action;
     actionIfView.Refresh(new ActionHolder(_action.ActionIf), algoContext);
     actionElseView.Refresh(new ActionHolder(_action.ActionElse), algoContext);
     checkerView.Refresh(new ActionHolder(_action.Checker), algoContext);
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (SetReturnValueAction)actionHolder.Action;
     action1View.Refresh(actionHolder, algoContext);
     action2View.Refresh(_action.InputValue, algoContext);
     action2View.MasterAction = _action;
 }
Ejemplo n.º 16
0
 public ExecutionContext(IAlgorithmContext algorithmContext, string input, string previousValue, OutputChangedDelegates output, ExecutionContext parentContext, SafeCancellationToken cancellationTokenSource)
 {
     OutputChanged           = output;
     AlgorithmContext        = algorithmContext;
     Input                   = input;
     PreviousValue           = previousValue;
     CancellationTokenSource = cancellationTokenSource;
     ParentContext           = parentContext;
     ExecutionNesting        = ParentContext.ExecutionNesting + 1;
 }
Ejemplo n.º 17
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     AlgorithmContext = algoContext;
     ActionHolder     = actionHolder;
     _action          = (CheckerAction)actionHolder.Action;
     action1View.Refresh(_action.TargetAction1Holder, algoContext);
     action2View.Refresh(_action.TargetAction2Holder, algoContext);
     comparisonView.Refresh(actionHolder, algoContext);
     Action2EqualizeToAction1();
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _operatorPair    = (CheckerOperatorPair)actionHolder.Action;
     tbOperator1.Text
         = _operatorPair.Operator == LogicalOperator.And || _operatorPair.Operator == LogicalOperator.AndNot ? "И" : "ИЛИ";
     tbOperator2.Text
         = _operatorPair.Operator == LogicalOperator.AndNot || _operatorPair.Operator == LogicalOperator.OrNot ? "НЕ" : string.Empty;
 }
#pragma warning restore 67

        public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
        {
            AlgorithmContext = algoContext;
            ActionHolder     = actionHolder;
            _action          = (ComplexCheckerAction)actionHolder.Action;
            Children.Clear();
            foreach (var pair in _action.CheckerOperations)
            {
                Insert(pair);
            }
        }
Ejemplo n.º 20
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     if (Model == null)
     {
         Model       = new ActionModel();
         DataContext = Model;
     }
     Model.Refresh(ActionHolder);
 }
Ejemplo n.º 21
0
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     AlgorithmContext = algoContext;
     ActionHolder     = actionHolder;
     _action          = (ComplexAction)actionHolder.Action;
     Children.Clear();
     foreach (var holder in _action.ActionHolders)
     {
         Insert(holder);
     }
 }
Ejemplo n.º 22
0
        /// <see cref="InfestationAlgorithmBase._runAlgorithm(IAlgorithmContext)"/>
        protected override void _runAlgorithm(IAlgorithmContext context)
        {
            Library _l = context.L;
            Dungeon _d = context.D;
            Random  _r = context.R;

            // Add one thing to each group in the dungeon
            foreach (TileGroupInfo group in _d.Groups.Where(grp => context.Mask.ContainsAny(grp.Tiles)))
            {
                InfestationInfo randomItem = _l.AllInfestations.Where(info => info.Category == InfestationType.Item)
                                             .Random(_r);
                _d.Infestations.Associate(group, randomItem);
            }
        }
Ejemplo n.º 23
0
 protected override void _runInternal(IAlgorithmContext context)
 {
     foreach (var cb in this.Callbacks)
     {
         foreach (var alg in Algorithms)
         {
             alg.AttachCallback(cb);
         }
     }
     foreach (IAlgorithm alg in Algorithms)
     {
         alg.Run(context);
         this.RunCallbacks(context);
     }
 }
Ejemplo n.º 24
0
        public IAction CreateInstance(Type type, IAlgorithmContext algorithmContext)
        {
            var action = (IAction)Activator.CreateInstance(type);

            PrepareInstance(action, algorithmContext);
            if (action is ExecuteAction executeAction)
            {
                executeAction.InputValue.Action = CoreActions.Utils.Default(action.ValueType);
            }
            else if (action is SetReturnValueAction setReturnValueAction)
            {
                setReturnValueAction.InputValue.Action = CoreActions.Utils.Default(algorithmContext.ValueType);
            }
            return(action);
        }
Ejemplo n.º 25
0
        protected override void _runAlgorithm(IAlgorithmContext context)
        {
            context.D.Tiles.SetAllToo(Tile.MoveType.Wall, context.Mask);
            foreach (var cb in this.Callbacks)
            {
                RoomBuilder?.AttachCallback(cb);
                MazeCarver?.AttachCallback(cb);
                DeadEndFiller?.AttachCallback(cb);
            }

            RoomBuilder?.Run(context);
            this.RunCallbacks(context);
            MazeCarver?.Run(context);
            this.RunCallbacks(context);
            DeadEndFiller?.Run(context);
            this.RunCallbacks(context);
        }
Ejemplo n.º 26
0
 public IAction PrepareInstance(IAction action, IAlgorithmContext algorithmContext)
 {
     if (action is IContextInitializable contextInitializable)
     {
         contextInitializable.Initialize(algorithmContext);
     }
     if (action is IScenariosAccess scenarioAccessObj)
     {
         scenarioAccessObj.SetTargetScenario(_scenarioRepository.Scenarios.FirstOrDefault(x => x.Id.Equals(((IScenariosAccess)action).TargetScenarioId)));
     }
     if (action is IUsersGeolocationAccess geolocationAccessObj)
     {
         geolocationAccessObj.SetNeedTargets(() => _usersRepository.Users.ToArray());
     }
     if (action is IMessagesSender messagesSender)
     {
         messagesSender.SetNeedTargets(() => _usersRepository.Users.ToArray());
     }
     return(action);
 }
Ejemplo n.º 27
0
        /// <see cref="AlgorithmBase._runInternal(IAlgorithmContext)"/>
        protected override void _runInternal(IAlgorithmContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("Can't infest without any context!");
            }
            if (context.D == null)
            {
                throw new ArgumentNullException("Can't infest nothing!");
            }
            if (context.Mask == null)
            {
                context.Mask = context.D.Tiles.DefaultMask;
            }

            if (context.L == null || context.L.AllInfestations == null || context.L.AllInfestations.Count == 0)
            {
                // We have nothing to do if there is nothing to infest with
                return;
            }

            _runAlgorithm(context);
        }
Ejemplo n.º 28
0
 protected override void _runAlgorithm(IAlgorithmContext context)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 protected override void _runInternal(IAlgorithmContext context)
 {
     return;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Runs the internal Infestation Algorithm, after the base implementation takes care of any
 /// common parameter checking. Implementor can assume the context is valid.
 /// </summary>
 /// <param name="context">The context in which this Algorithm is to be run.</param>
 protected abstract void _runAlgorithm(IAlgorithmContext context);