예제 #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 value = fungeContext.GetTopStackTopValues(1)[0];

            fungeContext.ModifyCell(fungeContext.CurrentThread.CurrentPosition + fungeContext.CurrentThreadDeltaVector,
                                    value);
            fungeContext.MoveCurrentThread();
            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);
        }