示例#1
0
        private static string ConstructTape(TuringMachine machine)
        {
            var tape = machine.Tape.Aggregate(string.Empty,
                                              (current, indexValuePair) => current + indexValuePair.Value);

            return(tape.Substring(0, tape.Length < Console.WindowWidth ? tape.Length : Console.WindowWidth));
        }
示例#2
0
        private static string Head(TuringMachine machine)
        {
            if (machine.HeadPosition < 0)
            {
                return(string.Empty);
            }
            var leftBuffer = ConstructRepeatingString(' ', machine.HeadPosition);

            return($"{leftBuffer}V");
        }
示例#3
0
        public static string ConstructRepresentation(TuringMachine machine)
        {
            var title     = FillEmpty($"═════ Machine {machine.Id} | {machine.FileName} ═════").TruncateToConsole();
            var state     = FillEmpty($"State: {machine.State}").TruncateToConsole();
            var head      = FillEmpty($"{Head(machine)}").TruncateToConsole();
            var tape      = FillEmpty($"{ConstructTape(machine)}").TruncateToConsole();
            var step      = FillEmpty($"Step: {machine.CurrentStep}").TruncateToConsole();
            var emptyLine = FillEmpty().TruncateToConsole();

            return($"{title}\n{state}\n{emptyLine}\n{head}\n{tape}\n{emptyLine}\n{step}\n");
        }