Exemplo n.º 1
0
        private static Maze MakeMaze(IntcodeComputer com)
        {
            long  output = -1;
            long  input  = 1;
            Point pos    = new Point(0, 0);
            Maze  m      = new Maze();
            int   iter   = 0;

            m.AddStartAt(0, 0);
            while (iter < 100000)
            {
                Point left = Move(TurnLeft(input), pos);
                if (!(m.CellAt(left.X, left.Y) is MazeWall))
                {
                    input = TurnLeft(input);
                }
                com.InputQueue.Enqueue(input);
                while (com.OutputQueue.Count == 0)
                {
                    ;
                }
                output = com.OutputQueue.Dequeue();
                switch (output)
                {
                case 0:
                    AddWall(input, pos, m);
                    input = TurnRight(input);
                    break;

                case 1:
                    pos = Move(input, pos);
                    AddCorridor(pos, m);
                    break;

                case 2:
                    pos = Move(input, pos);
                    AddExit(pos, m);
                    break;
                }
                iter++;
            }
            return(m);
        }