Ejemplo n.º 1
0
        private static bool Output(long status)
        {
            var previousPosition  = droidPosition;
            var attemptedPosition = Compass.PositionAfterMovement(droidPosition, Attempt);

            if (status == 0)
            {
                // The repair droid hit a wall. Its position has not changed.
                area.Set(attemptedPosition, Day15Cell.Wall);
                Day15Debug.Set(attemptedPosition, Day15Cell.Wall);
                Day15Debug.WriteLine("BLOCKED");
            }
            else
            {
                // The repair droid has moved one step in the requested direction.
                Day15Debug.WriteLine("OK");
                droidPosition = attemptedPosition;
                if (!Backtracking)
                {
                    area.Set(attemptedPosition, Day15Cell.Open);
                    Day15Debug.Set(attemptedPosition, Day15Cell.Open);
                    if (status == 2)
                    {
                        oxygenSystemPosition = attemptedPosition;
                    }
                    EnteredFrom[attemptedPosition] = Attempt;
                    Visited.Add(attemptedPosition);
                    Attempts.Push(Compass.AllDirections);
                }
            }

            return((Attempts.Count() > 1) || (Attempts.Peek().Count > 0));
        }
Ejemplo n.º 2
0
 public static Area <Day15Cell> GenerateMaze()
 {
     area = new Area <Day15Cell>(Day15Cell.Unexplored);
     Attempts.Push(Compass.AllDirections);
     new IntCodeComputer(GetData(), Input, Output).Run();
     return(area);
 }
Ejemplo n.º 3
0
        private static long Input()
        {
            var attempt = Attempts.Pop().Where(dir => !Visited.Contains(Compass.PositionAfterMovement(droidPosition, dir))).ToList();

            if (attempt.Count == 0)
            {
                Backtracking = true;
                Attempt      = Compass.Opposite(EnteredFrom[droidPosition]);
            }
            else
            {
                Backtracking = false;
                Attempt      = attempt[0];
                attempt.RemoveAt(0);
                Attempts.Push(attempt);
            }
            var backTrackingString = Backtracking ? " (BACKTRACKING)" : "";

            Day15Debug.Write($"({droidPosition.x}),{droidPosition.y}) - {Compass.Name(Attempt)}{backTrackingString} : ");
            return(Compass.ToLong(Attempt));
        }