Пример #1
0
        public InstructionSet ToInstructionSet(IInstructable instructable)
        {
            InstructionSet instructionSet = new InstructionSet();

            instructionSet.Name = this.Target;

            //INameable nameable = null;


            foreach (KeyframeListSave keyframeList in Instructions)
            {
                KeyframeList keyframes = new KeyframeList();
                keyframes.Name = keyframeList.Name;

                instructionSet.Add(keyframes);
                foreach (KeyframeSave keyframe in keyframeList.SceneKeyframes)
                {
                    InstructionList list = new InstructionList();
                    list.Name = keyframe.Name;
                    keyframes.Add(list);

                    foreach (InstructionSave instructionSave in keyframe.InstructionSaves)
                    {
                        list.Add(instructionSave.ToInstruction(instructable));
                    }
                }
            }

            return(instructionSet);
        }
Пример #2
0
        TICKRESULT ITicker.Tick(float delta)
        {
            if (_Current != null)
            {
                var result = _Current.Result();
                if (result == INSTRUCTION.DONE_BY_FAILURE || result == INSTRUCTION.DONE_BY_SUCCESS)
                {
                    _Reset();
                    return(result == INSTRUCTION.DONE_BY_SUCCESS ? TICKRESULT.SUCCESS :  TICKRESULT.FAILURE);
                }
                if (result == INSTRUCTION.NEXT)
                {
                    _Current = _Next();
                    return(TICKRESULT.RUNNING);
                }
                if (result == INSTRUCTION.WAIT)
                {
                    return(TICKRESULT.RUNNING);
                }
            }
            _Current = _Next();
            if (_Current != null)
            {
                return(TICKRESULT.RUNNING);
            }

            _Reset();
            return(TICKRESULT.SUCCESS);
        }
Пример #3
0
        /// <summary>
        /// Attempts to execute instructions held by the argument instruct
        /// able according to the currentTime value.
        /// Executed instructions will either be removed or cycled if the CycleTime is greater than 0.
        /// </summary>
        /// <param name="instructable">The instructable to execute instructions on.</param>
        /// <param name="currentTime">The time to compare to instructions in the instructable instance.</param>
        public static void ExecuteInstructionsOnConsideringTime(IInstructable instructable, double currentTime)
        {
            Instructions.Instruction instruction;

            while (instructable.Instructions.Count > 0 &&
                   instructable.Instructions[0].TimeToExecute <= currentTime)
            {
                instruction = instructable.Instructions[0];

                instruction.Execute();

                // The instruction may have cleared the InstructionList, so we need to test if it did.
                if (instructable.Instructions.Count < 1)
                {
                    continue;
                }

                if (instruction.CycleTime == 0)
                {
                    instructable.Instructions.Remove(instruction);
                }
                else
                {
                    instruction.TimeToExecute += instruction.CycleTime;
                    instructable.Instructions.InsertionSortAscendingTimeToExecute();
                }
            }
        }
Пример #4
0
        public void Execute(IInstructionExecutor valueExecutor,
                            IInstructionExecutor moveChipsExecutor,
                            IInstructable factory,
                            IEnumerable <string> instructions)
        {
            var valueInstructions = instructions.Where(a => valueExecutor.CanExecute(factory, a));

            foreach (var valueInstruction in valueInstructions)
            {
                valueExecutor.Execute(factory, valueInstruction);
            }

            var remaining = instructions.Except(valueInstructions);

            while (remaining.Any())
            {
                //  -Initially, bot 1 starts with a value-3 chip, and bot 2 starts with a value-2 chip and a value-5 chip.
                //- Because bot 2 has two microchips, it gives its lower one(2) to bot 1 and its higher one (5) to bot 0.
                //- Then, bot 1 has two microchips; it puts the value-2 chip in output 1 and gives the value-3 chip to bot 0.
                //- Finally, bot 0 has two microchips; it puts the 3 in output 2 and the 5 in output 0
                var nextToExecute = NextInstruction(remaining,
                                                    i => moveChipsExecutor.CanExecute(factory, i));

                moveChipsExecutor.Execute(factory, nextToExecute);

                remaining = Remove(remaining, nextToExecute);
            }
        }
Пример #5
0
        public bool CanExecute(IInstructable factory, string instruction)
        {
            var isValidInstruction = IsValidInstruction(instruction);

            var haveTwoChips = DoesBotHaveTwoChips(factory, instruction);

            return(isValidInstruction && haveTwoChips);
        }
        public List<InstructionSet> ToInstructionSetList(IInstructable iinstructable)
        {
            List<InstructionSet> instructionSetList = new List<InstructionSet>(InstructionSetSaves.Count);

            foreach (InstructionSetSave instructionSetSave in InstructionSetSaves)
            {
                instructionSetList.Add(instructionSetSave.ToInstructionSet(iinstructable));
            }

            return instructionSetList;
        }
Пример #7
0
        public List <InstructionSet> ToInstructionSetList(IInstructable iinstructable)
        {
            List <InstructionSet> instructionSetList = new List <InstructionSet>(InstructionSetSaves.Count);

            foreach (InstructionSetSave instructionSetSave in InstructionSetSaves)
            {
                instructionSetList.Add(instructionSetSave.ToInstructionSet(iinstructable));
            }

            return(instructionSetList);
        }
Пример #8
0
        public void Execute(IInstructable factory, string instruction)
        {
            if (!CanExecute(factory, instruction))
            {
                throw new InvalidOperationException(string.Format("Executor cannot run - CanExecute returned false for this input: {0}", instruction));
            }

            StartInstructionForBot(instruction);
            SetLowerMoveInstruction(instruction);
            SetHigherMoveInstruction(instruction);
            ExecuteInstruction(factory);
        }
Пример #9
0
        private bool DoesBotHaveTwoChips(IInstructable factory, string instruction)
        {
            var bot = GetBotForInstruction(instruction);

            if (!factory.Bots.Any(a => a == bot))
            {
                return(false);
            }

            var haveTwoChips = factory.BotValues(bot).Count() == 2;

            return(haveTwoChips);
        }
Пример #10
0
        public void Execute(IInstructable factory, string instruction)
        {
            if (!CanExecute(factory, instruction))
            {
                throw new InvalidOperationException(string.Format("Unable to execute instruction as CanExecute returned false: {0}", instruction));
            }

            var parts = this.numberPattern.Matches(instruction)
                        .Cast <Match>()
                        .Select(a => a.Value);

            var value = Int32.Parse(parts.First());
            var bot   = Int32.Parse(parts.Last());

            factory.LoadBot(new LoadBotInstruction(bot, value));
        }
Пример #11
0
 void _Reset()
 {
     _Action  = _Provider.GetEnumerator();
     _Current = null;
 }
Пример #12
0
 /// <summary>
 /// Attempts to execute instructions held by the argument instructable according to the TimeManager.CurrentTime.
 /// Executed instructions will either be removed or cycled if the CycleTime is greater than 0.
 /// </summary>
 /// <param name="instructable">The instructable to execute instructions on.</param>
 public static void ExecuteInstructionsOnConsideringTime(IInstructable instructable)
 {
     ExecuteInstructionsOnConsideringTime(instructable, TimeManager.CurrentTime);
 }
Пример #13
0
        public InstructionSet ToInstructionSet(IInstructable instructable)
        {
            InstructionSet instructionSet = new InstructionSet();
            instructionSet.Name = this.Target;

            //INameable nameable = null;


            foreach (KeyframeListSave keyframeList in Instructions)
            {
                KeyframeList keyframes = new KeyframeList();
                keyframes.Name = keyframeList.Name;

                instructionSet.Add(keyframes);
                foreach (KeyframeSave keyframe in keyframeList.SceneKeyframes)
                {
                    InstructionList list = new InstructionList();
                    list.Name = keyframe.Name;
                    keyframes.Add(list);

                    foreach (InstructionSave instructionSave in keyframe.InstructionSaves)
                    {
                        list.Add(instructionSave.ToInstruction(instructable));
                    }
                }

            }

            return instructionSet;
        }
Пример #14
0
        private void ExecuteInstruction(IInstructable factory)
        {
            var instruction = this.builder.Build();

            factory.MoveChips(instruction);
        }
Пример #15
0
 public bool CanExecute(IInstructable factory, string instruction)
 {
     return(instruction.StartsWith("value"));
 }