Example #1
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var curDirection = fungeContext.CurrentDirectionVector;

            fungeContext.CurrentDirectionVector = curDirection.Reflect();
            return(null);
        }
        protected override string RealExecute(FungeContext fungeContext)
        {
            var cur = fungeContext.CurrentDirectionVector;

            fungeContext.CurrentDirectionVector = cur.Rotate(_nameToDirection[Name]);
            return(null);
        }
Example #3
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var value = fungeContext.GetTopStackTopValues(1)[0];

            fungeContext.SetDeltaVector(value == 0 ? Direction.SOUTH : Direction.NORTH);
            return(null);
        }
Example #4
0
        public string RealExecute(FungeContext fungeContext)
        {
            var n = fungeContext.GetTopStackTopValues(1)[0];

            if (n < 0)
            {
                return("UB in \")\" : top stack value negative");
            }

            var values = fungeContext.GetTopStackTopValues(n).Reverse().ToArray();

            var accum = values.Aggregate(0, (current, value) => current * 256 + value);

            var fps = fungeContext.SupportedFingerPrints;
            var fp  = fps.Find(f => f.FingerPrintHash == accum);

            if (fp == null)
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
                return(null);
            }
            foreach (var(key, _) in fp.KeyBinding)
            {
                _fpc.Find(c => c.Name == key)?.UnloadTopAlias();
            }

            return(null);
        }
Example #5
0
        public string RealExecute(FungeContext fungeContext)
        {
            if (fungeContext.CurrentThread.Stacks.Count < 2)
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
                return(null);
            }

            //get n values from toss
            var n      = fungeContext.GetTopStackTopValues(1)[0];
            var values = n > 0 ? fungeContext.GetTopStackTopValues(n) : new int[0];

            //remove toss
            fungeContext.CurrentThread.Stacks.Pop();

            // restore offset
            var storageOffset = fungeContext.GetTopStackTopValues(fungeContext.Dimension);

            fungeContext.CurrentThread.StorageOffset = new DeltaVector(storageOffset.Reverse().ToArray());

            //
            if (n < 0)
            {
                fungeContext.GetTopStackTopValues(-n);
            }
            else
            {
                foreach (var value in values.Reverse())
                {
                    fungeContext.CurrentThread.Stacks.Peek().Push(value);
                }
            }

            return(null);
        }
Example #6
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(1);

            _writer.Write((char)values[0]);
            return(null);
        }
Example #7
0
        public string RealExecute(FungeContext fungeContext)
        {
            var n        = fungeContext.GetTopStackTopValues(1)[0];
            var newStack = new Stack <int>();

            if (n > 0)
            {
                var values = fungeContext.GetTopStackTopValues(n).Reverse().ToArray();
                foreach (var value in values)
                {
                    newStack.Push(value);
                }
            }

            if (n < 0)
            {
                foreach (var i in Enumerable.Repeat(0, -n))
                {
                    fungeContext.CurrentThread.Stacks.Peek().Push(i);
                }
            }

            var currentThread = fungeContext.CurrentThread;
            var storageOffset = currentThread.StorageOffset;

            for (int i = 0; i < fungeContext.Dimension; i++)
            {
                fungeContext.CurrentThread.Stacks.Peek().Push(storageOffset.Coords(fungeContext.Dimension)[i]);
            }

            currentThread.StorageOffset = currentThread.CurrentPosition + currentThread.DeltaVector;
            fungeContext.CurrentThread.Stacks.Push(newStack);
            return(null);
        }
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(fungeContext.Dimension);

            fungeContext.CurrentDirectionVector = new DeltaVector(values.Reverse().ToArray());
            return(null);
        }
Example #9
0
        public string RealExecute(FungeContext fungeContext)
        {
            var n = fungeContext.GetTopStackTopValues(1)[0];

            if (n == 0)
            {
                fungeContext.MoveCurrentThread();
                return(null);
            }

            if (n < 0)
            {
                return("k command behavior not specified when n is negative");
            }

            var nextPos = fungeContext.CurrentThread.CurrentPosition;

            while (true)
            {
                nextPos += fungeContext.CurrentThreadDeltaVector;
                var nextCommand = fungeContext.GetCellValue(nextPos);
                if (nextCommand == ';' || nextCommand == ' ')
                {
                    continue;
                }
                var command = _commands.Find(c => c.Name == nextCommand);
                for (int i = 0; i < n; i++)
                {
                    command?.Execute(fungeContext);
                }

                return(null);
            }
        }
Example #10
0
        public string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(1);

            _writer.Write(values[0]);
            return(null);
        }
Example #11
0
        public string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(fungeContext.Dimension);

            fungeContext.CurrentThreadDeltaVector = new DeltaVector(values.Reverse().ToArray());
            return(null);
        }
Example #12
0
        public string RealExecute(FungeContext fungeContext)
        {
            var cur = fungeContext.CurrentThreadDeltaVector;

            fungeContext.CurrentThreadDeltaVector = cur.Rotate(_nameToDirection[Name]);
            return(null);
        }
Example #13
0
        public string RealExecute(FungeContext fungeContext)
        {
            var value = fungeContext.GetTopStackTopValues(1)[0];

            fungeContext.CurrentThread.DeltaVector = value == 0 ? new DeltaVector(1, 0, 0) : new DeltaVector(-1, 0, 0);
            return(null);
        }
Example #14
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(2);

            fungeContext.PushToTopStack(values[1] > values[0] ? 1 : 0);
            return(null);
        }
Example #15
0
        public string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(1);

            fungeContext.PushToTopStack(values[0] == 0 ? 1 : 0);
            return(null);
        }
        public string RealExecute(FungeContext fungeContext)
        {
            var curDirection = fungeContext.CurrentThreadDeltaVector;

            fungeContext.CurrentThreadDeltaVector = curDirection.Reflect();
            return(null);
        }
        public string RealExecute(FungeContext fungeContext)
        {
            fungeContext.MoveCurrentThread();
            var fetched = fungeContext.GetCellValue(fungeContext.CurrentThread.CurrentPosition);

            fungeContext.PushToTopStack(fetched);
            return(null);
        }
Example #18
0
        public string RealExecute(FungeContext fungeContext)
        {
            var values     = fungeContext.GetTopStackTopValues(fungeContext.Dimension + 1);
            var targetCell = new DeltaVector(values.Reverse().Skip(1).ToArray()) + fungeContext.CurrentThread.StorageOffset;

            fungeContext.ModifyCell(targetCell, values.Last());
            return(null);
        }
Example #19
0
        private static string AFunc(FungeContext context)
        {
            var complexes = context.GetTopStackTopValues(4);

            context.PushToTopStack(complexes[0] + complexes[2]);
            context.PushToTopStack(complexes[1] + complexes[3]);
            return(null);
        }
Example #20
0
        public string RealExecute(FungeContext fungeContext)
        {
            var b  = fungeContext.GetTopStackTopValues(1)[0];
            var dv = b > 0 ? new DeltaVector(0, 0, -1) : new DeltaVector(0, 0, 1);

            fungeContext.CurrentThreadDeltaVector = dv;
            return(null);
        }
        protected override string RealExecute(FungeContext fungeContext)
        {
            fungeContext.MoveOnce();
            var fetched = fungeContext.GetCurrentCommandName();

            fungeContext.PushToTopStack(fetched);
            return(null);
        }
Example #22
0
        public string RealExecute(FungeContext fungeContext)
        {
            do
            {
                fungeContext.MoveCurrentThread();
            } while (fungeContext.GetCellValue(fungeContext.CurrentThread.CurrentPosition) != Name);

            return(null);
        }
Example #23
0
        public string RealExecute(FungeContext fungeContext)
        {
            var coords = fungeContext.GetTopStackTopValues(fungeContext.Dimension);
            var value  = fungeContext.GetCellValue(new DeltaVector(coords.Reverse().ToArray()) +
                                                   fungeContext.CurrentThread.StorageOffset);

            fungeContext.PushToTopStack(value);
            return(null);
        }
 protected override string RealExecute(FungeContext fungeContext)
 {
     if (!int.TryParse(_reader.ReadLine(), out var value))
     {
         return("Can't parse Integer from user input!");
     }
     fungeContext.PushToTopStack(value);
     return(null);
 }
Example #25
0
        public string RealExecute(FungeContext fungeContext)
        {
            if (fungeContext.CurrentThread.Stacks.Count != 0)
            {
                fungeContext.CurrentThread.Stacks.Peek().Clear();
            }

            return(null);
        }
        public string RealExecute(FungeContext fungeContext)
        {
            var value = fungeContext.GetTopStackTopValues(1)[0];

            fungeContext.ModifyCell(fungeContext.CurrentThread.CurrentPosition + fungeContext.CurrentThreadDeltaVector,
                                    value);
            fungeContext.MoveCurrentThread();
            return(null);
        }
Example #27
0
        public string Execute(FungeContext fungeContext)
        {
            if (!fungeContext.IsSupported(this))
            {
                return($"{fungeContext.Version} not supporting  {Name} command");
            }

            var error = RealExecute(fungeContext);

            fungeContext.MoveOnce();
            return(error);
        }
Example #28
0
        public string RealExecute(FungeContext fungeContext)
        {
            var n     = fungeContext.GetTopStackTopValues(1)[0];
            var delta = n < 0 ? fungeContext.CurrentThreadDeltaVector.Reflect() : fungeContext.CurrentThreadDeltaVector;

            for (int i = 0; i < Math.Abs(n); i++)
            {
                fungeContext.CurrentThread.CurrentPosition += delta;
            }

            return(null);
        }
Example #29
0
        public string RealExecute(FungeContext fungeContext)
        {
            var name    = fungeContext.PopString();
            var process = Process.Start(name);

            if (process == null)
            {
                fungeContext.PushToTopStack(-1);
                return($" Can't start {name}");
            }
            process.WaitForExit();
            fungeContext.PushToTopStack(process.ExitCode);
            return(null);
        }
Example #30
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(2);

            if (values[0] == values[1])
            {
                return(null);
            }

            var currentDelta = fungeContext.CurrentDirectionVector;

            fungeContext.CurrentDirectionVector = currentDelta.Rotate(values[1] > values[0] ? Direction.EAST : Direction.WEST);
            return(null);
        }