Esempio n. 1
0
    public static void ConvertWhileRunning(IntCodeCompiler intCodeCompiler, IntCodeProgram program, string filename, bool useExecutorActionForMain)
    {
        string output   = "";
        int    maxSteps = 100;

        while (!program.IsDone || maxSteps-- > 0)
        {
            var instruction = program.OpCodeAtPointer;
            var opcode      = instruction % 100;
            if (opcode == 99)
            {
                output += "Halt";
                break;
            }
            else if (opcode > intCodeCompiler.Instructions.Length || intCodeCompiler.Instructions[opcode] == null)
            {
                output += $"! Missing Instruction {opcode}!\n";
                break;
            }
            else
            {
                output += InstructionToCode(program, instruction, opcode, program.Pointer);
                program = intCodeCompiler.ComputeStep(program);
            }
        }

        if (useExecutorActionForMain)
        {
            AOCExecutor.ActionForMain.Enqueue(() => AOCInput.WriteToFile(filename, output));
        }
        else
        {
            AOCInput.WriteToFile(filename, output);
        }
    }
Esempio n. 2
0
    public static void Convert(IntCodeProgram program, string filename)
    {
        var    compiler = new IntCodeCompiler();
        string output   = "";
        long   pointer  = 0;

        while (pointer < program.MemoryLength)
        {
            var instruction = program[pointer];
            var opcode      = instruction % 100;
            if (opcode == 99)
            {
                output += "Halt";
                break;
            }
            else if (opcode > compiler.Instructions.Length || compiler.Instructions[opcode] == null)
            {
                output += "! Missing Instruction !\n";
                break;
            }
            else
            {
                output  += InstructionToCode(program, instruction, opcode, pointer);
                pointer += compiler.InstructionsSkips[opcode];
            }
        }
        if (Application.isPlaying)
        {
            AOCExecutor.ActionForMain.Enqueue(() => AOCInput.WriteToFile(filename, output));
        }
        else
        {
            AOCInput.WriteToFile(filename, output);
        }
    }
Esempio n. 3
0
        private void WriteToFilePainting(Dictionary <Vector2Int, List <long> > painting, string fileName)
        {
            var output = $"{painting.Keys.Count} panels painted in {painting.Sum(x => x.Value.Count)} Steps.\n";

            foreach (var item in painting)
            {
                output += $"{item.Key}: {string.Join(", ", item.Value)}\n";
            }
            AOCInput.WriteToFile(fileName, output);
        }