예제 #1
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);
            }
        }
예제 #2
0
        public string RealExecute(FungeContext fungeContext)
        {
            fungeContext.MoveCurrentThread();
            var fetched = fungeContext.GetCellValue(fungeContext.CurrentThread.CurrentPosition);

            fungeContext.PushToTopStack(fetched);
            return(null);
        }
예제 #3
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);
        }
예제 #4
0
        public string RealExecute(FungeContext fungeContext)
        {
            do
            {
                fungeContext.MoveCurrentThread();
            } while (fungeContext.GetCellValue(fungeContext.CurrentThread.CurrentPosition) != Name);

            return(null);
        }
예제 #5
0
        public string NextStep()
        {
            string res = null;

            foreach (var thread in _executionContext.Threads)
            {
                _executionContext.CurrentThread = thread;
                res = ICommand.Notick;
                while (res == ICommand.Notick)
                {
                    var commandName = _executionContext.GetCellValue(_executionContext.CurrentThread.CurrentPosition);
                    var command     = _commandProducer.GetCommand(commandName);
                    res = command.Execute(_executionContext);
                    _executionContext.MoveCurrentThread();
                }
            }
            Ticks++;
            _executionContext.Threads = _executionContext.SpawnedThreads.Concat(_executionContext.Threads.Where(t => t.Alive)).ToList();
            _executionContext.SpawnedThreads.Clear();
            return(res);
        }
예제 #6
0
        public string RealExecute(FungeContext fungeContext)
        {
            var filename = fungeContext.PopString();
            var flag     = fungeContext.GetTopStackTopValues(1)[0];
            var va       = new DeltaVector(fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray()) + fungeContext.CurrentThread.StorageOffset;
            var vb       = fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray();

            try
            {
                using var fw = new StreamWriter(File.OpenWrite(filename));


                for (var y = va.Y; y < vb[1] + va.Y; y++)
                {
                    var line = new List <char>();
                    for (var x = va.X; x < va.X + vb[0]; x++)
                    {
                        var c = fungeContext.GetCellValue(new DeltaVector(x, y, 0));
                        line.Add((char)c);
                    }

                    var resString = new string(line.ToArray());
                    if ((flag & 1) == 1)
                    {
                        resString = resString.Trim();
                    }

                    fw.WriteLine(resString);
                }
            }
            catch
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
            }

            return(null);
        }