mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-01-14 01:25:36 -05:00
Day 13 - Part 2
This commit is contained in:
@@ -19,16 +19,20 @@ namespace Advent
|
||||
private long _instructionPointer;
|
||||
private long _output;
|
||||
private long _relativeBase;
|
||||
private InputDelegate _onInput;
|
||||
|
||||
public bool Halted { get; private set; }
|
||||
|
||||
public IntcodeComputer(string memoryString, long phase)
|
||||
public delegate long InputDelegate();
|
||||
|
||||
public IntcodeComputer(string memoryString, long phase, InputDelegate onInput = null)
|
||||
{
|
||||
_memory = new long[5000];
|
||||
|
||||
memoryString.Split(',').Select(long.Parse).ToArray().CopyTo(_memory, 0);
|
||||
|
||||
_phase = phase;
|
||||
_onInput = onInput;
|
||||
}
|
||||
|
||||
private long GetValue(long parameter, ParameterMode mode)
|
||||
@@ -96,6 +100,9 @@ namespace Advent
|
||||
|
||||
_setPhase = true;
|
||||
|
||||
if (_onInput != null)
|
||||
inputValue = _onInput();
|
||||
|
||||
SetValue(inputValue, _memory[_instructionPointer + 1], mode1);
|
||||
|
||||
_instructionPointer += 2;
|
||||
|
||||
Reference in New Issue
Block a user