public RepairBot(string intCodeMemory) { _map[_position] = Tile.Empty; AddUnknownNeighbors(); _intCode = new IntCode(intCodeMemory); _intCode.Begin(); while (_unknown.Count > 0) { BuildPathToNearestUnknown(); ExecuteMoves(); } if (goalPos == null) { Console.WriteLine("Failed to find oxygen system, no where left to search!"); return; } goalDist = FindPath(Point.zero, goalPos.Value).Count; timeToFill = _map .Where(p => p.Value == Tile.Empty) .Select(p => FindPath(goalPos.Value, p.Key).Count) .OrderBy(c => c) .Last(); DrawMap(); }
public Arcade(string intCodeMemory, bool insertQuarters = false) { Dictionary <int, long> substitutions = new Dictionary <int, long>(); if (insertQuarters) { substitutions[0] = 2; } _intCode = new IntCode(intCodeMemory, substitutions); _intCode.OnOutput += HandleOnOutput; _intCode.Begin(); while (_intCode.state == IntCode.State.Waiting) { int delta = _ballX - _paddleX; delta = delta == 0 ? 0 : delta / Math.Abs(delta); // -1, 0, 1 _intCode.Input(delta); } if (insertQuarters) { Console.WriteLine("Final score: " + score); } else { RunDiagnosticCheck(); } }
private void RunSpringBot(string[] instructions) { Queue <char> input = new Queue <char>(instructions.Aggregate((a, b) => $"{a}\n{b}") + "\n"); _intCode.Reset(); _intCode.Begin(); while (_intCode.state != IntCode.State.Complete && input.Count > 0) { _intCode.Input((long)input.Dequeue()); } }
public void Run(bool firstTileIsWhite) { _whiteTiles.Clear(); _paintedTiles.Clear(); _state = State.Paint; _pos = Point.zero; _dir = Direction.Up; if (firstTileIsWhite) { _whiteTiles.Add(_pos); } _intCode.Reset(); _intCode.Begin(); while (Update()) { ; } }
public NIC(string intCodeMemory) { _intCode = new IntCode(intCodeMemory); _intCode.OnOutput += HandleOutput; _intCode.Begin(); }
// Resets and begins the intCode, passing the phase setting as the first input public void Begin(int phase) { _intCode.Reset(); _intCode.Begin(); _intCode.Input(phase); }
public override (string message, object answer) SolvePart1() { _intCode.Begin(); _intCode.Input(1); return("Final output: ", _lastOutput); }