Exemple #1
0
        public void ExecuteDNA(Bot bot)
        {
            BoolStack.Clear();
            IntStack.Clear();

            currentFlowState = FlowState.Clear;

            foreach (var basePair in bot.DNA)
            {
                switch (basePair.Type)
                {
                case BasePairType.Number:
                    if (currentFlowState != FlowState.Clear)
                    {
                        IntStack.Push(basePair.Command);
                    }
                    break;

                case BasePairType.StarNumber:
                    if (currentFlowState != FlowState.Clear)
                    {
                        IntStack.Push(bot.Memory[SystemVariables.NormaliseAddress(basePair.Command)]);
                    }
                    break;

                case BasePairType.Basic:
                    if (currentFlowState != FlowState.Clear)
                    {
                        ExecuteBasicCommand(basePair.GetBasicCommand());
                    }
                    break;

                case BasePairType.Store:
                    if (currentFlowState == FlowState.Body)
                    {
                        ExecuteStoreCommand(bot, basePair.GetStoreCommand());
                    }
                    break;

                case BasePairType.Flow:
                    ExecuteFlowCommand(basePair.GetFlowCommand());
                    break;

                case BasePairType.Boolean:
                    if (currentFlowState != FlowState.Clear)
                    {
                        ExecuteBooleanCommand(basePair.GetBooleanCommand());
                    }
                    break;

                case BasePairType.Condition:
                    if (currentFlowState != FlowState.Clear)
                    {
                        ExecuteConditionCommand(basePair.GetConditionCommand());
                    }
                    break;
                }
            }
        }
        public void NormaliseAddressHandlesZero()
        {
            var testAddress = 0;

            var actualAddress = SystemVariables.NormaliseAddress(testAddress);

            Assert.Equal(testAddress, actualAddress);
        }
        public void NormaliseAddressHandlesSecondLargestValue()
        {
            var testAddress = SystemVariables.MemoryLength - 1;

            var actualAddress = SystemVariables.NormaliseAddress(testAddress);

            Assert.Equal(testAddress, actualAddress);
        }
        public void NormaliseAddressHandlesLargeAddress()
        {
            var testAddress = 1;

            var actualAddress = SystemVariables.NormaliseAddress(testAddress + SystemVariables.MemoryLength * 20);

            Assert.Equal(testAddress, actualAddress);
        }
Exemple #5
0
        private void ExecuteStoreCommand(Bot bot, StoreCommand storeCommand)
        {
            int a, b;

            switch (storeCommand)
            {
            case StoreCommand.Store:
                b = SystemVariables.NormaliseAddress(IntStack.Pop());
                a = IntStack.Pop();
                if (SystemVariables.IsAddressWritable(b))
                {
                    bot.Memory[b] = a;
                }
                break;
            }
        }