Example #1
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int x = befungeRunTime.MaxExtent.x == befungeRunTime.CurrentPosition.x ? 0 : befungeRunTime.CurrentPosition.x + 1;

            befungeRunTime.CurrentPosition = new CoOrds(x, befungeRunTime.CurrentPosition.y);
            base.Execute(befungeRunTime);
        }
Example #2
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int y = befungeRunTime.MaxExtent.y == befungeRunTime.CurrentPosition.y ? 0 : befungeRunTime.CurrentPosition.y + 1;

            befungeRunTime.CurrentPosition = new CoOrds(befungeRunTime.CurrentPosition.x, y);
            base.Execute(befungeRunTime);
        }
Example #3
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int a = befungeRunTime.RetrieveLastValue();

            befungeRunTime.Output = a.ToString();

            base.Execute(befungeRunTime);
        }
Example #4
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int val = befungeRunTime.ReviewLastValueOrDefault(0);

            befungeRunTime.StoreValue(val);

            base.Execute(befungeRunTime);
        }
Example #5
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            char val = (char)befungeRunTime.RetrieveLastValue();

            befungeRunTime.Output = val.ToString();

            base.Execute(befungeRunTime);
        }
Example #6
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int val = befungeRunTime.RetrieveLastValue();

            befungeRunTime.StoreValue(val == 0 ? 1 : 0);

            base.Execute(befungeRunTime);
        }
Example #7
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            Direction[] directions  = { MoveDown.Instance, MoveLeft.Instance, MoveRight.Instance, MoveUp.Instance };
            int         randomIndex = (new Random()).Next(directions.Length);

            befungeRunTime.CurrentDirection = directions[randomIndex];

            base.Execute(befungeRunTime);
        }
Example #8
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            IMode numberMode = NumberMode.Instance;
            IMode stringMode = StringMode.Instance;

            befungeRunTime.CurrentMode = (befungeRunTime.CurrentMode.IsNumberMode) ? stringMode : numberMode;

            base.Execute(befungeRunTime);
        }
Example #9
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int a = befungeRunTime.RetrieveLastValue();
            int b = befungeRunTime.RetrieveLastValue();

            befungeRunTime.StoreValue(a + b);

            base.Execute(befungeRunTime);
        }
Example #10
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int y   = befungeRunTime.RetrieveLastValue();
            int x   = befungeRunTime.RetrieveLastValue();
            int val = (int)befungeRunTime.GetValue(new CoOrds(x, y));

            befungeRunTime.StoreValue(val);

            base.Execute(befungeRunTime);
        }
Example #11
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int  y = befungeRunTime.RetrieveLastValue();
            int  x = befungeRunTime.RetrieveLastValue();
            char v = (char)befungeRunTime.RetrieveLastValue();

            befungeRunTime.PutValue(new CoOrds(x, y), v);

            base.Execute(befungeRunTime);
        }
Example #12
0
        /// <summary>
        /// Execute the current instruction
        /// </summary>
        public void ExecuteInstruction(IBefungeRunTime runTime)
        {
            IInstruction currentInstruction = _defaultInstruction;

            if (_instructionsLookup.ContainsKey(runTime.CurrentInstruction))
            {
                _instructionsLookup.TryGetValue(runTime.CurrentInstruction, out currentInstruction);
            }
            currentInstruction.Execute(runTime);
        }
Example #13
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int val = befungeRunTime.RetrieveLastValue();

            Direction moveDown = MoveDown.Instance;
            Direction moveUp   = MoveUp.Instance;

            befungeRunTime.CurrentDirection = val == 0 ? moveDown : moveUp;

            base.Execute(befungeRunTime);
        }
Example #14
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int val = befungeRunTime.RetrieveLastValue();

            Direction moveRight = MoveRight.Instance;
            Direction moveLeft  = MoveLeft.Instance;

            befungeRunTime.CurrentDirection = val == 0 ? moveRight : moveLeft;

            base.Execute(befungeRunTime);
        }
Example #15
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int    value;
            string input = "";

            while (!Int32.TryParse(input, out value))
            {
                input = befungeRunTime.Input("Please supply an Integer:");
            }

            befungeRunTime.StoreValue(value);
            base.Execute(befungeRunTime);
        }
Example #16
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            string input = "";

            while (input.Length == 0)
            {
                input = befungeRunTime.Input("Please supply a Character:");
            }

            // take the first character and get the ASCII value
            int ASCIIvalue = (int)input[0];

            befungeRunTime.StoreValue(ASCIIvalue);
            base.Execute(befungeRunTime);
        }
Example #17
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        /// <exception cref="UnsupportedInstructionException">Thrown when an unknown instruction is encountered</exception>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            int value;

            if (Int32.TryParse(befungeRunTime.CurrentInstruction.ToString(), out value))
            {
                befungeRunTime.StoreValue(value);
            }
            else
            {
                string message = $"Unsupported Instruction: {befungeRunTime.CurrentInstruction.ToString()}.";
                Console.WriteLine(message);
                throw new UnsupportedInstructionException(message);
            }

            base.Execute(befungeRunTime);
        }
Example #18
0
 /// <summary>
 /// Execute the instruction
 /// </summary>
 public override void Execute(IBefungeRunTime befungeRunTime)
 {
     befungeRunTime.EndProgram = true;
     base.Execute(befungeRunTime);
 }
Example #19
0
        /// <summary>
        /// Execute the current instruction
        /// </summary>
        public void ExecuteInstruction(IBefungeRunTime runTime)
        {
            IInstruction currentInstruction = runTime.CurrentInstruction == '"' ? _toggleStringMode : _defaultInstruction;

            currentInstruction.Execute(runTime);
        }
Example #20
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            befungeRunTime.CurrentDirection.Execute(befungeRunTime);

            base.Execute(befungeRunTime);
        }
Example #21
0
 /// <summary>
 /// Execute the instruction
 /// </summary>
 public virtual void Execute(IBefungeRunTime befungeRunTime)
 {
     // Move in the current direction
     befungeRunTime.CurrentDirection.Execute(befungeRunTime);
 }
Example #22
0
        /// <summary>
        /// Execute the instruction
        /// </summary>
        public override void Execute(IBefungeRunTime befungeRunTime)
        {
            befungeRunTime.StoreValue((int)befungeRunTime.CurrentInstruction);

            base.Execute(befungeRunTime);
        }
Example #23
0
 /// <summary>
 /// Execute the instruction
 /// </summary>
 public virtual void Execute(IBefungeRunTime befungeRunTime)
 {
     befungeRunTime.CurrentDirection = this;
     befungeRunTime.ReadInstruction();
 }