Exemple #1
0
 // Start is called before the first frame update
 void Start()
 {
     _computer    = new Day11.IntcodeComputer(Program.Intcode);
     _caseManager = FindObjectOfType <CaseManager>();
     _controls    = FindObjectOfType <Controls>();
     _dest.y      = transform.position.y;
     _prop        = new MaterialPropertyBlock();
 }
        private static void Part2()
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var             points   = new Dictionary <Point, long>();
            IntcodeComputer computer = new IntcodeComputer(memory);

            computer.InputQueue.Enqueue(1);

            bool  running      = true;
            Point currentPoint = new Point(0, 0);

            points.Add(currentPoint, 1);
            int currentDirection = 0;

            while (running)
            {
                running = computer.RunNext() == long.MinValue;
                if (computer.OutputQueue.Count == 2)
                {
                    points[currentPoint] = computer.OutputQueue.Dequeue();
                    if (computer.OutputQueue.Dequeue() == 0)
                    {
                        currentDirection--;
                    }
                    else
                    {
                        currentDirection++;
                    }
                    if (currentDirection == -1)
                    {
                        currentDirection = 3;
                    }
                    else if (currentDirection == 4)
                    {
                        currentDirection = 0;
                    }
                    switch (currentDirection)
                    {
                    case 0:
                        currentPoint.Y++;
                        break;

                    case 1:
                        currentPoint.X++;
                        break;

                    case 2:
                        currentPoint.Y--;
                        break;

                    case 3:
                        currentPoint.X--;
                        break;
                    }
                    if (!points.ContainsKey(currentPoint))
                    {
                        points.Add(currentPoint, 0);
                    }
                    computer.InputQueue.Enqueue(points[currentPoint]);
                }
            }
            Console.WriteLine("Part 2:");
            for (int y = points.Keys.Max(p => p.Y); y >= points.Keys.Min(p => p.Y); y--)
            {
                for (int x = points.Keys.Min(p => p.X); x <= points.Keys.Max(p => p.X); x++)
                {
                    Point point = new Point(x, y);
                    if (points.ContainsKey(point) && points[point] == 1)
                    {
                        Console.Write("#");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }

            sw.Stop();
            System.Diagnostics.Debug.WriteLine(sw.Elapsed);
        }
        private static void Part1()
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var             points   = new Dictionary <Point, long>();
            IntcodeComputer computer = new IntcodeComputer(memory);

            computer.InputQueue.Enqueue(0);

            bool  running      = true;
            Point currentPoint = new Point(0, 0);

            points.Add(currentPoint, 0);
            int currentDirection = 0;

            while (running)
            {
                running = computer.RunNext() == long.MinValue;
                if (computer.OutputQueue.Count == 2)
                {
                    points[currentPoint] = computer.OutputQueue.Dequeue();
                    if (computer.OutputQueue.Dequeue() == 0)
                    {
                        currentDirection--;
                    }
                    else
                    {
                        currentDirection++;
                    }
                    if (currentDirection == -1)
                    {
                        currentDirection = 3;
                    }
                    else if (currentDirection == 4)
                    {
                        currentDirection = 0;
                    }
                    switch (currentDirection)
                    {
                    case 0:
                        currentPoint.Y++;
                        break;

                    case 1:
                        currentPoint.X++;
                        break;

                    case 2:
                        currentPoint.Y--;
                        break;

                    case 3:
                        currentPoint.X--;
                        break;
                    }
                    if (!points.ContainsKey(currentPoint))
                    {
                        points.Add(currentPoint, 0);
                    }
                    computer.InputQueue.Enqueue(points[currentPoint]);
                }
            }
            Console.WriteLine($"Part 1: {points.Count}");

            sw.Stop();
            System.Diagnostics.Debug.WriteLine(sw.Elapsed);
        }
Exemple #4
0
 /// <summary>
 /// CPY CTOR
 /// </summary>
 /// <param name="ic">IntcodeComputer to copy.</param>
 public IntcodeComputer(IntcodeComputer ic)
 {
     this._baseOpcodes    = ic._baseOpcodes;
     this._baseMemorySize = ic._baseMemorySize;
 }