Ejemplo n.º 1
0
        void Compare(IntCodeOperation operation)
        {
            var op1    = GetMemory(operation.ParameterA, _address + 1);
            var op2    = GetMemory(operation.ParameterB, _address + 2);
            var result = Convert.ToInt32(operation.Operator == IntCodeOperator.LessThan ? op1 < op2 : op1 == op2);

            SetMemory(operation.ParameterC, _address + 3, result);
        }
Ejemplo n.º 2
0
        void Calculate(IntCodeOperation operation)
        {
            var op1    = GetMemory(operation.ParameterA, _address + 1);
            var op2    = GetMemory(operation.ParameterB, _address + 2);
            var result = operation.Operator == IntCodeOperator.Multiply ? op1 * op2 : op1 + op2;

            SetMemory(operation.ParameterC, _address + 3, result);
        }
Ejemplo n.º 3
0
        bool GotoCheck(IntCodeOperation operation)
        {
            var op       = GetMemory(operation.ParameterA, _address + 1);
            var nextAddr = GetMemory(operation.ParameterB, _address + 2);
            var canJump  = operation.Operator == IntCodeOperator.JumpIfFalse ? op == 0 : op != 0;

            if (canJump)
            {
                _address = nextAddr;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 void HandleResponse(IntCodeOperation operation)
 {
     if (operation.Operator == IntCodeOperator.Input)
     {
         if (_inputs.Any())
         {
             SetMemory(operation.ParameterA, _address + 1, _inputs.Dequeue());
         }
         else
         {
             IsPaused = true;
             return;
         }
     }
     else
     {
         var output = GetMemory(operation.ParameterA, _address + 1);
         _outputs.Add(output);
     }
 }
Ejemplo n.º 5
0
        void ShiftBase(IntCodeOperation operation)
        {
            var op = GetMemory(operation.ParameterA, _address + 1);

            _base += op;
        }