public Quad_Or_Gates() : base(8, 4) { Gate gateA = new ORGate(); int indexA = AddGate(gateA); Gate gateB = new ORGate(); int indexB = AddGate(gateB); Gate gateC = new ORGate(); int indexC = AddGate(gateC); Gate gateD = new ORGate(); int indexD = AddGate(gateD); // Gate A AddWire(ID, new Wire(0, 0, indexA, false)); AddWire(ID, new Wire(1, 1, indexA, false)); AddWire(gateA.ID, new Wire(0, 0, -1, true)); // Gate B AddWire(ID, new Wire(2, 0, indexB, false)); AddWire(ID, new Wire(3, 1, indexB, false)); AddWire(gateB.ID, new Wire(0, 1, -1, true)); // Gate C AddWire(ID, new Wire(4, 0, indexC, false)); AddWire(ID, new Wire(5, 1, indexC, false)); AddWire(gateC.ID, new Wire(0, 2, -1, true)); // Gate D AddWire(ID, new Wire(6, 0, indexD, false)); AddWire(ID, new Wire(7, 1, indexD, false)); AddWire(gateD.ID, new Wire(0, 3, -1, true)); }
// Helper Methods: private static string ToHadesString(this Component component) { return(component switch { ANDGate and => $"hades.models.gatter.And{and.NumberOfInputs} {and.Name} {and.Pos.X * 3}0 {and.Pos.Y * 3}0 @N 1001 1.0E-8", INVGate inv => $"hades.models.gatter.Inv {inv.Name} {inv.Pos.X * 3}0 {inv.Pos.Y * 3}0 @N 1001 5.0E-9", NANDGate nand => $"hades.models.gatter.Nand{nand.NumberOfInputs} {nand.Name} {nand.Pos.X * 3}0 {nand.Pos.Y * 3}0 @N 1001 1.0E-8", NORGate nor => $"hades.models.gatter.Nor{nor.NumberOfInputs} {nor.Name} {nor.Pos.X * 3}0 {nor.Pos.Y * 3}0 @N 1001 1.0E-8", ORGate or => $"hades.models.gatter.Or{or.NumberOfInputs} {or.Name} {or.Pos.X * 3}0 {or.Pos.Y * 3}0 @N 1001 1.0E-8", XNORGate xnor => $"hades.models.gatter.Xnor{xnor.NumberOfInputs} {xnor.Name} {xnor.Pos.X * 3}0 {xnor.Pos.Y * 3}0 @N 1001 1.0E-8", XORGate xor => $"hades.models.gatter.Xor{xor.NumberOfInputs} {xor.Name} {xor.Pos.X * 3}0 {xor.Pos.Y * 3}0 @N 1001 1.0E-8", InputPulse ip => $"hades.models.io.PulseSwitch {ip.Name} {ip.Pos.X * 3}0 {ip.Pos.Y * 3}0 @N 1001 0.1 null", InputClock ic => $"hades.models.io.ClockGen {ic.Name} {ic.Pos.X * 3}0 {ic.Pos.Y * 3}0 @N 1001 {InputClock.MsToSec()} 0.5 0.0", Input i => $"hades.models.io.Ipin {i.Name} {i.Pos.X * 3}0 {i.Pos.Y * 3}0 @N 1001 {i.IsActive}", Output o => $"hades.models.io.Opin {o.Name} {o.Pos.X * 3}0 {o.Pos.Y * 3}0 @N 1001 5.0E-9", _ => throw new ComponentNotFoundException(component.GetType().ToString()) });
public void OR() { PowerSupplier power1 = new PowerSupplier(); PowerSupplier power2 = new PowerSupplier(); ORGate orGate = new ORGate(); IndicatorLight light = new IndicatorLight(); orGate.Output.ConnectTo(light.Input); Assert.IsFalse(light.Lighting); orGate.Input1.ConnectTo(power1.Output); orGate.Input2.ConnectTo(power2.Output); Assert.IsFalse(light.Lighting); power1.On(); power2.Off(); Assert.IsTrue(light.Lighting); power1.Off(); power2.On(); Assert.IsTrue(light.Lighting); power1.On(); power2.On(); Assert.IsTrue(light.Lighting); power1.Off(); power2.Off(); Assert.IsFalse(light.Lighting); }
public NORGate() { _orGate = new ORGate(); _invertor = new Invertor(); _orGate.Output.ConnectTo(_invertor.Input); Input1 = _orGate.Input1; Input2 = _orGate.Input2; Output = _invertor.Output; }
/// <summary> /// Multiplies a sum of products with a gate other than an OR gate. /// </summary> /// <param name="list"></param> /// <param name="b"></param> /// <returns></returns> public static IGate Multiply(IEnumerable <IGate> list, IGate b) { var r = new ORGate(); foreach (var a in list) { r.AddInput(ComposeAND(a, b)); } return(r); }
public AND4Chip() : base(3, 1) { Gate gateA = new ANDGate(); int indexA = AddGate(gateA); Gate gateB = new ORGate(); int indexB = AddGate(gateB); AddWire(ID, new Wire(2, 0, indexA, false)); AddWire(ID, new Wire(1, 1, indexA, false)); AddWire(ID, new Wire(0, 1, indexB, false)); AddWire(gateA.ID, new Wire(0, 0, indexB, false)); AddWire(gateB.ID, new Wire(0, 0, -1, true)); }
public XORGate() { _orGate = new ORGate(); _nandGate = new NANDGate(); _andGate = new ANDGate(); _nexus1 = new TShapedNexus(null, _orGate.Input1, _nandGate.Input1); _nexus2 = new TShapedNexus(null, _orGate.Input2, _nandGate.Input2); _andGate.Input1.ConnectTo(_orGate.Output); _andGate.Input2.ConnectTo(_nandGate.Output); Input1 = _nexus1.GetEndpointAt(0); Input2 = _nexus2.GetEndpointAt(0); Output = _andGate.Output; }
public FullAdder() { _orGate = new ORGate(); _halfAdderOrigin = new HalfAdder(); _halfAdderCarry = new HalfAdder(); _halfAdderCarry.CarryOut.ConnectTo(_orGate.Input1); _halfAdderOrigin.Sum.ConnectTo(_halfAdderCarry.Number2In); _halfAdderOrigin.CarryOut.ConnectTo(_orGate.Input2); CarryIn = _halfAdderCarry.Number1In; Number1In = _halfAdderOrigin.Number1In; Number2In = _halfAdderOrigin.Number2In; Sum = _halfAdderCarry.Sum; CarryOut = _orGate.Output; }
public TestChip3() : base(4, 1) { Gate gateA = new ORGate(); int indexA = AddGate(gateA); Gate gateB = new ORGate(); int indexB = AddGate(gateB); Gate gateC = new ANDGate(); int indexC = AddGate(gateC); AddWire(ID, new Wire(3, 0, indexA, false)); AddWire(ID, new Wire(2, 1, indexA, false)); AddWire(ID, new Wire(1, 0, indexB, false)); AddWire(ID, new Wire(0, 1, indexB, false)); AddWire(gateA.ID, new Wire(0, 0, indexC, false)); AddWire(gateB.ID, new Wire(0, 1, indexC, false)); AddWire(gateC.ID, new Wire(0, 0, -1, true)); }
public Full_Adder() : base(3, 2) { Gate gateA = new XORGate(); int indexA = AddGate(gateA); Gate gateB = new XORGate(); int indexB = AddGate(gateB); Gate gateC = new ANDGate(); int indexC = AddGate(gateC); Gate gateD = new ANDGate(); int indexD = AddGate(gateD); Gate gateE = new ORGate(); int indexE = AddGate(gateE); // Gate A AddWire(ID, new Wire(0, 0, indexA)); AddWire(ID, new Wire(1, 1, indexA)); AddWire(gateA.ID, new Wire(0, 0, indexB)); AddWire(gateA.ID, new Wire(0, 0, indexC)); // Gate B AddWire(ID, new Wire(2, 1, indexB)); AddWire(gateB.ID, new Wire(0, 0, -1, true)); // Gate C AddWire(ID, new Wire(2, 1, indexC)); AddWire(gateC.ID, new Wire(0, 0, indexE)); // Gate D AddWire(ID, new Wire(0, 0, indexD)); AddWire(ID, new Wire(1, 1, indexD)); AddWire(gateD.ID, new Wire(0, 1, indexE)); // Gate E AddWire(gateE.ID, new Wire(0, 1, -1, true)); }
/// <summary> /// Composes two gates with the logical OR operator. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns>The resulting gate.</returns> public static IGate ComposeOR(IGate a, IGate b, ComposeOptions options = ComposeOptions.None) { IGate result; DecomposeExchange(ref a, ref b); if (a.Type == GateType.OR && b.Type == GateType.OR) { var r = new ORGate(); r.AddInputRange(a.GetInputs()); r.AddInputRange(b.GetInputs()); result = r; } else if (a.Type == GateType.OR) { var r = new ORGate(); r.AddInputRange(a.GetInputs()); r.AddInput(b); result = r; } else { var r = new ORGate(); r.AddInput(a); r.AddInput(b); result = r; } if (0 == (options & ComposeOptions.NoSimplify)) { result = Simplify(result); } TraceCompose(a, b, result, "OR"); return(result); }
public Bcd_To_Seg() : base(4, 7) { // Column 1 Gate gateA = new NotGate(); int indexA = AddGate(gateA); Gate gateB = new NotGate(); int indexB = AddGate(gateB); Gate gateC = new NotGate(); int indexC = AddGate(gateC); // Column 2 Gate gateD = new ANDGate(); int indexD = AddGate(gateD); Gate gateE = new ANDGate(); int indexE = AddGate(gateE); Gate gateF = new ANDGate(); int indexF = AddGate(gateF); Gate gateG = new ANDGate(); int indexG = AddGate(gateG); Gate gateH = new ANDGate(); int indexH = AddGate(gateH); Gate gateI = new ANDGate(); int indexI = AddGate(gateI); Gate gateJ = new ANDGate(3); int indexJ = AddGate(gateJ); Gate gateK = new ANDGate(); int indexK = AddGate(gateK); Gate gateL = new ANDGate(); int indexL = AddGate(gateL); // Column 3 Gate gateM = new ORGate(4); int indexM = AddGate(gateM); Gate gateN = new ORGate(4); int indexN = AddGate(gateN); Gate gateO = new ORGate(4); int indexO = AddGate(gateO); Gate gateP = new ORGate(5); int indexP = AddGate(gateP); Gate gateQ = new ORGate(); int indexQ = AddGate(gateQ); Gate gateR = new ORGate(4); int indexR = AddGate(gateR); Gate gateS = new ORGate(4); int indexS = AddGate(gateS); //Input A AddWire(ID, new Wire(0, 0, indexM, false)); AddWire(ID, new Wire(0, 0, indexN, false)); AddWire(ID, new Wire(0, 0, indexO, false)); AddWire(ID, new Wire(0, 0, indexP, false)); AddWire(ID, new Wire(0, 0, indexR, false)); AddWire(ID, new Wire(0, 0, indexS, false)); //Input B AddWire(ID, new Wire(1, 0, indexA, false)); AddWire(ID, new Wire(1, 0, indexE, false)); AddWire(ID, new Wire(1, 0, indexF, false)); AddWire(ID, new Wire(1, 0, indexJ, false)); AddWire(ID, new Wire(1, 0, indexL, false)); AddWire(ID, new Wire(1, 1, indexO, false)); //Input C AddWire(ID, new Wire(2, 0, indexB, false)); AddWire(ID, new Wire(2, 0, indexG, false)); AddWire(ID, new Wire(2, 0, indexI, false)); AddWire(ID, new Wire(2, 1, indexK, false)); AddWire(ID, new Wire(2, 3, indexM, false)); //Input D AddWire(ID, new Wire(3, 0, indexC, false)); AddWire(ID, new Wire(3, 1, indexE, false)); AddWire(ID, new Wire(3, 1, indexG, false)); AddWire(ID, new Wire(3, 2, indexJ, false)); AddWire(ID, new Wire(3, 2, indexO, false)); //Gate A AddWire(gateA.ID, new Wire(0, 0, indexD, false)); AddWire(gateA.ID, new Wire(0, 1, indexN, false)); AddWire(gateA.ID, new Wire(0, 0, indexK, false)); //Gate B AddWire(gateB.ID, new Wire(0, 0, indexH, false)); AddWire(gateB.ID, new Wire(0, 1, indexJ, false)); AddWire(gateB.ID, new Wire(0, 1, indexL, false)); //Gate C AddWire(gateC.ID, new Wire(0, 1, indexD, false)); AddWire(gateC.ID, new Wire(0, 1, indexF, false)); AddWire(gateC.ID, new Wire(0, 1, indexH, false)); AddWire(gateC.ID, new Wire(0, 1, indexI, false)); //Gate D AddWire(gateD.ID, new Wire(0, 1, indexM, false)); AddWire(gateD.ID, new Wire(0, 1, indexP, false)); AddWire(gateD.ID, new Wire(0, 0, indexQ, false)); //Gate E AddWire(gateE.ID, new Wire(0, 2, indexM, false)); //Gate F AddWire(gateF.ID, new Wire(0, 1, indexR, false)); //Gate G AddWire(gateG.ID, new Wire(0, 2, indexN, false)); //Gate H AddWire(gateH.ID, new Wire(0, 3, indexN, false)); AddWire(gateH.ID, new Wire(0, 3, indexO, false)); AddWire(gateH.ID, new Wire(0, 2, indexR, false)); //Gate I AddWire(gateI.ID, new Wire(0, 2, indexP, false)); AddWire(gateI.ID, new Wire(0, 1, indexQ, false)); AddWire(gateI.ID, new Wire(0, 1, indexS, false)); //Gate J AddWire(gateJ.ID, new Wire(0, 3, indexP, false)); //Gate K AddWire(gateK.ID, new Wire(0, 4, indexP, false)); AddWire(gateK.ID, new Wire(0, 2, indexS, false)); //Gate L AddWire(gateL.ID, new Wire(0, 3, indexR, false)); AddWire(gateL.ID, new Wire(0, 3, indexS, false)); //Gate M AddWire(gateM.ID, new Wire(0, 0, -1, true)); //Gate N AddWire(gateN.ID, new Wire(0, 1, -1, true)); //Gate O AddWire(gateO.ID, new Wire(0, 2, -1, true)); //Gate P AddWire(gateP.ID, new Wire(0, 3, -1, true)); //Gate Q AddWire(gateQ.ID, new Wire(0, 4, -1, true)); //Gate R AddWire(gateR.ID, new Wire(0, 5, -1, true)); //Gate S AddWire(gateS.ID, new Wire(0, 6, -1, true)); }
public override void Initialize() { base.Initialize(); par = parent as ORGate; }
public IEnumerator ORTest() { SetupScene(); yield return(new WaitForSecondsRealtime(1)); GameObject ORChip = Resources.Load <GameObject>("Prefabs/Lab/ORChip"); Assert.NotNull(ORChip); GameObject ORGo = GameObject.Instantiate <GameObject>(ORChip); ORGate OrGate = ORGo.GetComponent <ORGate>(); string device_id = ORGate.LOGIC_DEVICE_ID; yield return(new WaitForSecondsRealtime(1)); Dictionary <string, GameObject> nandNodes = OrGate.GetLogicDictionary(); List <GameObject> otherNodes = new List <GameObject>(); for (int i = 0; i < 14; i++) { GameObject newNode = new GameObject("OtherNODE_" + i); otherNodes.Add(newNode); } List <LogicNode> otherLogic = new List <LogicNode>(); for (int i = 0; i < 14; i++) { otherLogic.Add(otherNodes[i].AddComponent <LogicNode>()); } List <GameObject> nandNodeList = new List <GameObject>(); for (int i = 0; i < 14; i++) { GameObject DeviceNode; if (nandNodes.TryGetValue(device_id + i, out DeviceNode)) { nandNodeList.Add(DeviceNode); otherNodes[i].transform.position = nandNodeList[i].transform.position; } else { Assert.Fail(); } } yield return(new WaitForSecondsRealtime(1)); Assert.IsTrue(!OrGate.IsDeviceOn()); otherLogic[6].SetLogicState((int)LOGIC.LOW); otherLogic[13].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.IsTrue(!OrGate.IsDeviceOn()); OrGate.SetSnapped(true); Assert.IsTrue(OrGate.IsDeviceOn()); otherLogic[0].SetLogicState((int)LOGIC.LOW); otherLogic[1].SetLogicState((int)LOGIC.HIGH); otherLogic[3].SetLogicState((int)LOGIC.LOW); otherLogic[4].SetLogicState((int)LOGIC.HIGH); otherLogic[9].SetLogicState((int)LOGIC.LOW); otherLogic[8].SetLogicState((int)LOGIC.HIGH); otherLogic[12].SetLogicState((int)LOGIC.LOW); otherLogic[11].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.HIGH); otherLogic[1].SetLogicState((int)LOGIC.HIGH); otherLogic[3].SetLogicState((int)LOGIC.HIGH); otherLogic[4].SetLogicState((int)LOGIC.HIGH); otherLogic[9].SetLogicState((int)LOGIC.HIGH); otherLogic[8].SetLogicState((int)LOGIC.HIGH); otherLogic[12].SetLogicState((int)LOGIC.HIGH); otherLogic[11].SetLogicState((int)LOGIC.HIGH); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.HIGH); otherLogic[1].SetLogicState((int)LOGIC.LOW); otherLogic[3].SetLogicState((int)LOGIC.HIGH); otherLogic[4].SetLogicState((int)LOGIC.LOW); otherLogic[9].SetLogicState((int)LOGIC.HIGH); otherLogic[8].SetLogicState((int)LOGIC.LOW); otherLogic[12].SetLogicState((int)LOGIC.HIGH); otherLogic[11].SetLogicState((int)LOGIC.LOW); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.HIGH, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); otherLogic[0].SetLogicState((int)LOGIC.LOW); otherLogic[1].SetLogicState((int)LOGIC.LOW); otherLogic[3].SetLogicState((int)LOGIC.LOW); otherLogic[4].SetLogicState((int)LOGIC.LOW); otherLogic[9].SetLogicState((int)LOGIC.LOW); otherLogic[8].SetLogicState((int)LOGIC.LOW); otherLogic[12].SetLogicState((int)LOGIC.LOW); otherLogic[11].SetLogicState((int)LOGIC.LOW); yield return(new WaitForSecondsRealtime(1)); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[2].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[5].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[7].GetComponent <LogicNode>().GetLogicState()); Assert.AreEqual((int)LOGIC.LOW, nandNodeList[10].GetComponent <LogicNode>().GetLogicState()); yield break; }
public Quad_2_To_1_Selector() : base(10, 4) { ANDGate gateA0 = new ANDGate(3); int indexA0 = AddGate(gateA0); ANDGate gateA1 = new ANDGate(3); int indexA1 = AddGate(gateA1); ANDGate gateA2 = new ANDGate(3); int indexA2 = AddGate(gateA2); ANDGate gateA3 = new ANDGate(3); int indexA3 = AddGate(gateA3); ANDGate gateB0 = new ANDGate(3); int indexB0 = AddGate(gateB0); ANDGate gateB1 = new ANDGate(3); int indexB1 = AddGate(gateB1); ANDGate gateB2 = new ANDGate(3); int indexB2 = AddGate(gateB2); ANDGate gateB3 = new ANDGate(3); int indexB3 = AddGate(gateB3); ORGate gate0 = new ORGate(); int index0 = AddGate(gate0); ORGate gate1 = new ORGate(); int index1 = AddGate(gate1); ORGate gate2 = new ORGate(); int index2 = AddGate(gate2); ORGate gate3 = new ORGate(); int index3 = AddGate(gate3); AddWire(ID, new Wire(0, 0, indexA0)); AddWire(ID, new Wire(1, 0, indexA1)); AddWire(ID, new Wire(2, 0, indexA2)); AddWire(ID, new Wire(3, 0, indexA3)); AddWire(ID, new Wire(4, 0, indexB0)); AddWire(ID, new Wire(5, 0, indexB1)); AddWire(ID, new Wire(6, 0, indexB2)); AddWire(ID, new Wire(7, 0, indexB3)); AddWire(ID, new Wire(8, 1, indexA0, false, true)); AddWire(ID, new Wire(8, 1, indexA1, false, true)); AddWire(ID, new Wire(8, 1, indexA2, false, true)); AddWire(ID, new Wire(8, 1, indexA3, false, true)); AddWire(ID, new Wire(8, 1, indexB0)); AddWire(ID, new Wire(8, 1, indexB1)); AddWire(ID, new Wire(8, 1, indexB2)); AddWire(ID, new Wire(8, 1, indexB3)); AddWire(ID, new Wire(9, 2, indexA0, false, true)); AddWire(ID, new Wire(9, 2, indexA1, false, true)); AddWire(ID, new Wire(9, 2, indexA2, false, true)); AddWire(ID, new Wire(9, 2, indexA3, false, true)); AddWire(ID, new Wire(9, 2, indexB0, false, true)); AddWire(ID, new Wire(9, 2, indexB1, false, true)); AddWire(ID, new Wire(9, 2, indexB2, false, true)); AddWire(ID, new Wire(9, 2, indexB3, false, true)); AddWire(gateA0, new Wire(0, 0, index0)); AddWire(gateA1, new Wire(0, 0, index1)); AddWire(gateA2, new Wire(0, 0, index2)); AddWire(gateA3, new Wire(0, 0, index3)); AddWire(gateB0, new Wire(0, 1, index0)); AddWire(gateB1, new Wire(0, 1, index1)); AddWire(gateB2, new Wire(0, 1, index2)); AddWire(gateB3, new Wire(0, 1, index3)); AddWire(gate0, new Wire(0, 0, -1, true)); AddWire(gate1, new Wire(0, 1, -1, true)); AddWire(gate2, new Wire(0, 2, -1, true)); AddWire(gate3, new Wire(0, 3, -1, true)); }
public IEnumerator Lab1IntegrationTesting() { SceneManager.LoadScene("Scenes/Lab1Tester"); yield return(new WaitForSecondsRealtime(1)); GameObject powerSupplyGO = GameObject.Find("PowerSupply"); Assert.IsNotNull(powerSupplyGO); PowerSupplyScript powerSupply = powerSupplyGO.GetComponent <PowerSupplyScript>(); GameObject ProtoboardGO = GameObject.Find("Protoboard"); Assert.IsNotNull(ProtoboardGO); ProtoboardObject protoboardObj = ProtoboardGO.GetComponent <ProtoboardObject>(); Dictionary <string, List <GameObject> > protoboardNodes = protoboardObj.GetNodeDictionary(); GameObject ANDchip = GameObject.Find("ANDChip"); Assert.IsNotNull(ANDchip); ANDGate Andscript = ANDchip.GetComponent <ANDGate>(); GameObject ORchip = GameObject.Find("ORChip"); Assert.IsNotNull(ORchip); ORGate Orscript = ORchip.GetComponent <ORGate>(); GameObject switch1 = GameObject.Find("Switch"); Assert.IsNotNull(switch1); Switch switch1script = switch1.GetComponent <Switch>(); GameObject switch2 = GameObject.Find("Switch (1)"); Assert.IsNotNull(switch2); Switch switch2script = switch2.GetComponent <Switch>(); GameObject switch3 = GameObject.Find("Switch (2)"); Assert.IsNotNull(switch3); Switch switch3script = switch3.GetComponent <Switch>(); GameObject led = GameObject.Find("LEDChip"); Assert.IsNotNull(led); LEDScript ledScript = led.GetComponent <LEDScript>(); GameObject InputA = GameObject.Find("InputA"); Assert.IsNotNull(InputA); CheckerTagScript aScript = InputA.GetComponent <CheckerTagScript>(); GameObject InputB = GameObject.Find("InputB"); Assert.IsNotNull(InputB); CheckerTagScript bScript = InputA.GetComponent <CheckerTagScript>(); GameObject InputC = GameObject.Find("InputC"); Assert.IsNotNull(InputC); CheckerTagScript cScript = InputA.GetComponent <CheckerTagScript>(); GameObject OutputF = GameObject.Find("OutputF"); Assert.IsNotNull(OutputF); CheckerTagScript fScript = InputA.GetComponent <CheckerTagScript>(); yield return(new WaitForSecondsRealtime(.1f)); Andscript.OnMouseUp(); Orscript.OnMouseUp(); switch1script.OnMouseUp(); switch2script.OnMouseUp(); switch3script.OnMouseUp(); aScript.OnMouseUp(); bScript.OnMouseUp(); cScript.OnMouseUp(); fScript.OnMouseUp(); ledScript.OnMouseUp(); yield return(new WaitForSecondsRealtime(.1f)); Assert.IsTrue(Andscript.isSnapped()); Assert.IsTrue(Orscript.isSnapped()); Assert.IsTrue(ledScript.isSnapped()); Assert.IsTrue(switch1script.isSnapped()); Assert.IsTrue(switch2script.isSnapped()); Assert.IsTrue(switch3script.isSnapped()); Assert.IsTrue(aScript.isSnapped()); Assert.IsTrue(bScript.isSnapped()); Assert.IsTrue(cScript.isSnapped()); Assert.IsTrue(fScript.isSnapped()); Wire wire1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1); List <GameObject> leftList; protoboardNodes.TryGetValue("leftlogicnode_LEFT", out leftList); Assert.IsNotNull(leftList); GameObject topLeftNode = leftList[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1.SetNodePositions(powerSupply.GetVccNode().transform.position, topLeftNode.transform.position); Wire wire2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire2); List <GameObject> rightList; protoboardNodes.TryGetValue("leftlogicnode_RIGHT", out rightList); Assert.IsNotNull(rightList); GameObject topRightNode = rightList[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2.SetNodePositions(powerSupply.GetGndNode().transform.position, topRightNode.transform.position); Wire wire1switch1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist; protoboardNodes.TryGetValue("m_farleftnode_0", out farleftnodetoplist); Assert.IsNotNull(rightList); GameObject farleftnodetop = farleftnodetoplist[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch1.SetNodePositions(leftList[1].transform.position, farleftnodetop.transform.position); Wire wire2switch1 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist2; protoboardNodes.TryGetValue("m_farleftnode_2", out farleftnodetoplist2); Assert.IsNotNull(rightList); GameObject farleftnodetop2 = farleftnodetoplist2[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch1.SetNodePositions(rightList[1].transform.position, farleftnodetop2.transform.position); Wire wire1switch2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist4; protoboardNodes.TryGetValue("m_farleftnode_4", out farleftnodetoplist4); Assert.IsNotNull(rightList); GameObject farleftnodetop4 = farleftnodetoplist4[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch2.SetNodePositions(leftList[2].transform.position, farleftnodetop4.transform.position); Wire wire2switch2 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist6; protoboardNodes.TryGetValue("m_farleftnode_6", out farleftnodetoplist6); Assert.IsNotNull(rightList); GameObject farleftnodetop6 = farleftnodetoplist6[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch2.SetNodePositions(rightList[2].transform.position, farleftnodetop6.transform.position); Wire wire1switch3 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist8; protoboardNodes.TryGetValue("m_farleftnode_8", out farleftnodetoplist8); Assert.IsNotNull(rightList); GameObject farleftnodetop8 = farleftnodetoplist8[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire1switch3.SetNodePositions(leftList[2].transform.position, farleftnodetop8.transform.position); Wire wire2switch3 = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farleftnodetoplist10; protoboardNodes.TryGetValue("m_farleftnode_10", out farleftnodetoplist10); Assert.IsNotNull(rightList); GameObject farleftnodetop10 = farleftnodetoplist10[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch3.SetNodePositions(rightList[2].transform.position, farleftnodetop10.transform.position); //ledground Wire wire2ledgnd = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire1switch1); List <GameObject> farfarrightnodelist; protoboardNodes.TryGetValue("rightlogicnode_LEFT", out farfarrightnodelist); Assert.IsNotNull(rightList); GameObject farfarrightnode = farfarrightnodelist[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire2switch3.SetNodePositions(rightList[3].transform.position, farfarrightnode.transform.position); //Setupchips Wire wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node1list, node2list; protoboardNodes.TryGetValue("m_farleftnode_1", out node1list); protoboardNodes.TryGetValue("m_leftnode_0", out node2list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); GameObject node1, node2; node1 = node1list[0]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node3list, node4list; protoboardNodes.TryGetValue("m_farleftnode_9", out node3list); protoboardNodes.TryGetValue("m_leftnode_1", out node4list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node3list[0]; node2 = node4list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node5list, node6list; protoboardNodes.TryGetValue("m_leftnode_2", out node5list); protoboardNodes.TryGetValue("m_leftnode_10", out node6list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node5list[0]; node2 = node6list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node7list, node8list; protoboardNodes.TryGetValue("m_farleftnode_5", out node7list); protoboardNodes.TryGetValue("m_leftnode_11", out node8list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node7list[0]; node2 = node8list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); List <GameObject> node9list, node10list; protoboardNodes.TryGetValue("m_farrightnode_21", out node9list); protoboardNodes.TryGetValue("m_leftnode_12", out node10list); Assert.IsNotNull(node1list); Assert.IsNotNull(node2list); node1 = node9list[0]; node2 = node10list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_leftnode_6", out node2list); Assert.IsNotNull(node2list); node1 = rightList[5]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_leftnode_16", out node2list); Assert.IsNotNull(rightList); node1 = rightList[6]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_rightnode_0", out node2list); Assert.IsNotNull(rightList); node1 = leftList[6]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(.1f)); wire = new GameObject("Wire").AddComponent <Wire>(); Assert.IsNotNull(wire); protoboardNodes.TryGetValue("m_rightnode_10", out node2list); Assert.IsNotNull(rightList); node1 = leftList[7]; node2 = node2list[0]; yield return(null); yield return(null); yield return(null); yield return(null); wire.SetNodePositions(node1.transform.position, node2.transform.position); yield return(new WaitForSecondsRealtime(10)); yield break; }
public static IGate ExtractCommonFactors(IGate gate) { var original = gate; if (gate.Type == GateType.OR) { // TraceOptimize("extract common factors from {0} ...", gate); var sop = gate.GetSOP(); // count how many times each factor appears var inmap = new Dictionary <int, IInput>(); var dict = new SortedList <int, int>(); foreach (var p in sop.GetPrimitiveFactors()) { // a gate representing the factors (may be multiple per state variable) var pg = p.ToGate(); foreach (var i in pg.GetInputs().OfType <IInput>()) { var address = i.Address; // TraceOptimize("check factor {0} @ {1:X6}", i, address); if (!inmap.ContainsKey(i.Address)) { inmap.Add(i.Address, i); } if (!dict.ContainsKey(address)) { dict[address] = 1; } else { dict[address]++; } } } var m = dict.Values.Max(); // TraceOptimize("maximum factor count {0}", m); if (m > 1) { // go for it, take the first input with maximum multiplicity, inputs are ordered. var pivotindex = dict.Where(e => e.Value == m).Select(e => e.Key).First(); var pivot = inmap[pivotindex]; var pivotlist = new List <Product>(); var otherlist = new List <Product>(); TraceOptimize("use pivot {0:X6} ...", pivot); // split sop into two groups: factor or not foreach (var p in sop) { if (p.ContainsFactor(pivot)) { p.RemoveInput(pivot); pivotlist.Add(p); } else { otherlist.Add(p); } } IGate and = new ANDGate(); and.AddInput(pivot); IGate inneror = new ORGate(); foreach (var p in pivotlist) { var z = p.ToGate().Simplify(); // Debug.Assert(z.GetInputs().Count() > 1); Trace("adding pivot {0} [{1}]", z, z.GetType().Name); inneror.AddInput(z); } inneror = ExtractCommonFactors(inneror); and.AddInput(inneror); if (otherlist.Any()) { //var rh = ExtractCommonFactors(otherlist); var or = new ORGate(); or.AddInput(and); foreach (var p in otherlist) { var z = p.ToGate(); or.AddInput(z.Simplify()); } gate = or; } else { gate = and; } } } if (gate != original && TraceFlags.ShowOptimize) { Log.TraceGateOp2(original, gate, "optimize AND"); } return(gate); }