public override int[] calculate() { if (!startFirstTime()) { return(null); } int[] inputs = new int[InputPorts.Count]; // Go through each input and check its value. foreach (var rightIndexAndleftPort in InputPorts) { int rightIndex = rightIndexAndleftPort.Key; Tuple <CircuitElement, int> leftPort = rightIndexAndleftPort.Value; CircuitElement leftElement = leftPort.Item1; int leftIndex = leftPort.Item2; int[] childCalc = leftElement.calculate(); if (childCalc == null) { return(null); } inputs[rightIndex] = childCalc[leftIndex]; } outputValues = computeOutput(inputs.ToArray()); if (outputValues.Length != Outputs.Count) { throw new Exception("Gate returned " + outputValues.Length + " outputs; should have returned " + Outputs.Count); } endCalculation(); return(outputValues); }
/// <summary> /// gives an output, using properties of a NOT bubble /// </summary> /// <returns></returns> public override int[] calculate() { PrevOutput = myOutput; CircuitElement child = Inputs.Keys.ElementAt(0); myOutput[0] = (int)Math.Abs(child.calculate()[Inputs[child][0]] - 1); PrevOutput = myOutput; return(myOutput); }
/// <summary> /// gives the output of the connected gate /// </summary> /// <returns></returns> public override int[] calculate() { myOutput[0] = myLinkedGate.calculate()[Inputs[myLinkedGate][0]]; return(myOutput); }