Пример #1
0
            public Direction GetNextDirection(Direction from)
            {
                Direction opposite = Board2D <Track> .Turn(from, Direction.Down);

                Direction next = Directions.Where(d => d != opposite).First();

                return(next);
            }
Пример #2
0
        private void Burst(Aoc.Framework.Part part)
        {
            Direction turnDirection = GetTurnDirection();

            _direction = Board2D <Cell> .Turn(_direction, turnDirection);

            Infect(part);
            _position = Board2D <Int64> .MoveForward(_position, _direction);
        }
Пример #3
0
        public string Run(Aoc.Framework.Part part)
        {
            if (part == Aoc.Framework.Part.Part1)
            {
                Direction direction = Direction.Up;
                Point     position  = new Point(0, 0);
                foreach (string s in _input)
                {
                    direction = Board2D <Int64> .Turn(direction, (s[0] == 'R')?Direction.Right : Direction.Left);

                    position = Board2D <Int64> .MoveForward(position, direction, Int32.Parse(s[1..]));
Пример #4
0
        private long Paint(long initial)
        {
            long painted = 0;

            _hull       = new Board2D <long>();
            _hull[0, 0] = initial;
            _painted    = new Board2D <bool>();
            _direction  = Direction.Up;
            _position   = new Point(0, 0);
            _cpu.Reset(Aoc.Framework.Input.GetLongVector(this, ","));
            _cpu.Input.Enqueue(_hull[_position.X, _position.Y]);
            while (_cpu.State != IntCpu.RunningState.Halted)
            {
                _cpu.Run();

                if (_cpu.State != IntCpu.RunningState.Halted)
                {
                    if (!_painted[_position.X, _position.Y])
                    {
                        _painted[_position.X, _position.Y] = true;
                        painted++;
                    }

                    _hull[_position.X, _position.Y] = _cpu.Output.Dequeue();
                    long turn = _cpu.Output.Dequeue();
                    if (turn == 0)
                    {
                        _direction = Board2D <long> .Turn(_direction, Direction.Left);
                    }

                    if (turn == 1)
                    {
                        _direction = Board2D <long> .Turn(_direction, Direction.Right);
                    }

                    _position = Board2D <long> .MoveForward(_position, _direction);

                    _cpu.Input.Enqueue(_hull[_position.X, _position.Y]);
                }
            }

            return(painted);
        }
Пример #5
0
            public Point Move(Point from, Board2D <Track> tracks)
            {
                // Move the cart
                Point next = Board2D <Track> .MoveForward(from, Direction, 1, true);

                // Change the direction if needed
                Track cell = tracks[next.X, next.Y];

                if (cell.IsIntersection)
                {
                    Direction = Board2D <Track> .Turn(Direction, DirectionChooser[DirectionIndex]);

                    DirectionIndex = (DirectionIndex + 1) % DirectionChooser.Length;
                }
                else
                {
                    // We need to follow the track
                    Direction = cell.GetNextDirection(Direction);
                }

                return(next);
            }