Ejemplo n.º 1
0
    public void Execute()
    {
        if (Target != null)
        {
            var sequence = new CommandSequence();

            IAction action = Events.Prepare <GoTinyAction>();
            action.Configure(Target);
            sequence.Add(action);

            action = Events.Prepare <ColorCycleAction>();
            action.Configure(Target);
            sequence.Add(action);

            action = Events.Prepare <GoTinyAction>();
            action.Configure(Target);
            sequence.Add(action);

            sequence.OnCompleted((ep) => { this.Completed(); });
            sequence.Execute();
        }
        else
        {
            this.Completed();
        }
    }
Ejemplo n.º 2
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            var input     = ChooseInput(possibleElements);
            var generated = input.GetNextElement();

            CommandSequence.Add(CommandType.Generate, generated, this, input.Molecule.ID);
            return(generated);
        }
Ejemplo n.º 3
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Quintessence), this);

            AddPendingElement(Element.Air);
            AddPendingElement(Element.Water);
            AddPendingElement(Element.Fire);
            CommandSequence.Add(CommandType.Generate, Element.Earth, this);
            return(Element.Earth);
        }
Ejemplo n.º 4
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            Used = true;

            CommandSequence.Add(CommandType.Generate, m_elementSequence.First(), this);
            foreach (var element in m_elementSequence.Skip(1))
            {
                AddPendingElement(element);
            }

            return(m_elementSequence.First());
        }
Ejemplo n.º 5
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Salt), this);
            CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Salt), this);

            var firstElement  = possibleElements.First();
            var secondElement = firstElement == Element.Mors ? Element.Vitae : Element.Mors;

            CommandSequence.Add(CommandType.Generate, firstElement, this);
            AddPendingElement(secondElement);
            return(firstElement);
        }
Ejemplo n.º 6
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            var inputs = new HashSet <Element>(PeriodicTable.Cardinals);

            while (inputs.Any())
            {
                var element = Parent.RequestElement(inputs);
                CommandSequence.Add(CommandType.Consume, element, this);
                inputs.Remove(element);
            }

            CommandSequence.Add(CommandType.Generate, Element.Quintessence, this);
            return(Element.Quintessence);
        }
Ejemplo n.º 7
0
        public IComposerSequence Open(
            string name,
            Modes mode = Modes.None)
        {
            var panel = composer.GetPanel(name);

            Requires.NotNull(panel, nameof(panel));

            ICommand command;

            if (mode == Modes.Modal)
            {
                command = new CommandOpenPanelModal(panel, modesController);
            }
            else
            {
                command = new CommandOpenPanelNone(panel, modesController);
            }

            sequence.Add(command);

            return(this);
        }
Ejemplo n.º 8
0
        public ComposerSequence(
            CommandSequence root,
            IModesController modesController,
            Composer composer)
        {
            Requires.NotNull(root, nameof(root));
            Requires.NotNull(modesController, nameof(modesController));
            Requires.NotNull(composer, nameof(composer));

            this.root            = root;
            this.modesController = modesController;
            this.composer        = composer;
            sequence             = new CommandSequence();
            root.Add(sequence);
        }
Ejemplo n.º 9
0
        protected override void GenerateMetal(Element sourceMetal, Element destMetal)
        {
            int diff = PeriodicTable.GetMetalDifference(sourceMetal, destMetal);

            m_maxSize = Math.Max(m_maxSize, diff);

            int numAtoms = 1 << diff;

            for (int i = 1; i < numAtoms; i++)
            {
                CommandSequence.Add(CommandType.Consume, Parent.RequestElement(sourceMetal), this);
            }

            CommandSequence.Add(CommandType.Generate, destMetal, this);
        }
Ejemplo n.º 10
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            foreach (var element in possibleElements)
            {
                var stack = m_stacks.FirstOrDefault(s => s.Elements.Any() && s.Elements.First() == element);
                if (stack != null)
                {
                    CommandSequence.Add(CommandType.Generate, element, this, stack.ID);
                    stack.UsedPop = true;
                    return(stack.Elements.Pop());
                }
            }

            throw new SolverException(Invariant($"Can't find any of {String.Join(", ", possibleElements)} in buffer."));
        }
Ejemplo n.º 11
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            var generated = Parent.RequestElement(new[] { Element.Salt }.Concat(PeriodicTable.Cardinals));

            if (generated != Element.Salt)
            {
                CommandSequence.Add(CommandType.Consume, generated, this);
                CommandSequence.Add(CommandType.Generate, Element.Salt, this);
            }
            else
            {
                PassThrough(generated);
            }

            return(Element.Salt);
        }
Ejemplo n.º 12
0
        protected override void GenerateMetal(Element sourceMetal, Element destMetal)
        {
            int diff = PeriodicTable.GetMetalDifference(sourceMetal, destMetal);

            if (diff < 0)
            {
                throw new SolverException(Invariant($"Cannot use glyph of projection to convert {sourceMetal} to {destMetal}."));
            }

            for (int i = 0; i < diff; i++)
            {
                CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Quicksilver), this);
            }

            CommandSequence.Add(CommandType.Generate, destMetal, this);
        }
Ejemplo n.º 13
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            var element   = possibleElements.First();
            var generated = Parent.RequestElement(PeriodicTable.GetMetalOrLower(element));

            if (generated != element)
            {
                CommandSequence.Add(CommandType.PrepareToGenerate, element, this);
                CommandSequence.Add(CommandType.Consume, generated, this);
                GenerateMetal(generated, element);
            }
            else
            {
                PassThrough(generated);
            }

            return(element);
        }
Ejemplo n.º 14
0
        public void GenerateCommandSequence()
        {
            bool anyRepeats = m_products.Any(product => product.HasRepeats);

            foreach (var product in m_products)
            {
                // If there's a mix of repeating and non-repeating molecules, build extra copies of the
                // non-repeating ones. This is to compensate for the fact that we build all copies of
                // the repeating molecules at the same time. Normally 6 copies would be enough but
                // on some journal puzzles we need 18.
                int numCopies = (anyRepeats && !product.HasRepeats) ? 18 : 1;
                for (int i = 0; i < numCopies; i++)
                {
                    foreach (var element in product.GetAtomsInInputOrder().Select(a => a.Element))
                    {
                        CommandSequence.Add(CommandType.Consume, Parent.RequestElement(element), this, product.ID);
                    }
                }
            }
        }
Ejemplo n.º 15
0
    public void BaseCommand_Execute_Success()
    {
        // Arrange
        Command.Counter = 0;
        var command1 = new Command();
        var command2 = new Command();
        var command3 = new Command();

        // Act
        var sequence = new CommandSequence();

        sequence.Add(command1)
        .Add(command2)
        .Add(command3)
        .Execute();

        //Assert
        Assert.AreEqual(1, command1.Count);
        Assert.AreEqual(2, command2.Count);
        Assert.AreEqual(3, command3.Count);
    }
Ejemplo n.º 16
0
        protected override Element GenerateElement(IEnumerable <Element> possibleElements)
        {
            // We need salt to convert an atom to a cardinal but we'll request everything in possibleElements too.
            // That way, if the input area actually has an atom of the requested cardinal element, it'll give us
            // that one rather than a salt.
            var generated = Parent.RequestElement(possibleElements.Concat(new[] { Element.Salt }));

            if (generated == Element.Salt)
            {
                // If a generator requested more than one possible cardinal, arbitrarily pick the first one
                var element = possibleElements.First();
                CommandSequence.Add(CommandType.Consume, Element.Salt, this);
                CommandSequence.Add(CommandType.Generate, element, this);
                return(element);
            }
            else
            {
                PassThrough(generated);
                return(generated);
            }
        }
Ejemplo n.º 17
0
        protected override void StoreElement(Element element)
        {
            var stack = m_stacks.FirstOrDefault(s => s.Elements.FirstOrDefault() == element);

            if (stack == null)
            {
                stack = m_stacks.FirstOrDefault(s => !s.Elements.Any());
            }
            if (stack == null)
            {
                stack = new ElementStack {
                    ID = m_stacks.Count()
                };
                m_stacks.Add(stack);
            }

            stack.Elements.Push(element);
            stack.MaxCount = Math.Max(stack.MaxCount, stack.Elements.Count);

            CommandSequence.Add(CommandType.Consume, element, this, stack.ID);
        }