-
Notifications
You must be signed in to change notification settings - Fork 1
/
wire.cpp
90 lines (82 loc) · 1.57 KB
/
wire.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
struct wire{
int name; // 50 and above
int input;
vector<int> outputs;
char state = 'x'; // 0, 1, D, E, X
int fault = 2; // NA = 2, SA0 = 0, SA1 = 1
};
struct gate{
int name; // 0 - 49
int ip1;
int ip2;
int type; // AND, OR, NAND, NOR, NOT
int op;
};
void faultActivate(wire* faultSite, int faultType){
faultSite->fault = faultType;
switch(faultType){
case 0:
faultSite->state = 'D';
faultSite->fault = 0;
break;
case 1:
faultSite->state = 'E';
faultSite->fault = 1;
break;
}
int gateID = faultSite->input;
if(gateID<50){
gate gateToActivate = findGate(gateList, gateID);
wire ip1wire = findWire(wireList, gateToActivate.ip1);
wire ip2wire = findWire(wireList, gateToActivate.ip2);
switch(gateToActivate.type){
case 0:
if(faultType == 0){
ip1wire->state = '1';
ip2wire->state = '1';
}
else{
ip1wire->state = '0'
}
break;
case 1:
if(faultType == 0){
ip1wire->state = '1';
}
else{
ip1wire->state = '0';
ip2wire->state = '0';
}
break;
case 2:
if(faultType == 0){
ip1wire->state = '0'
}
else{
ip1wire->state = '1';
ip2wire->state = '1';
}
break;
case 3:
if(faultType == 0){
ip1wire->state = '0';
ip2wire->state = '0';
}
else{
ip1wire->state = '1';
}
break;
}
}
else if(gateID>= 50){
ipWire = findWire(wireList, gateID);
if(faultType == 0){
ipWire->state = '1';
}
else if(faultType == 1){
ipWire->state = '0';
}
}
}