-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_wireworld.dps
86 lines (76 loc) · 1.48 KB
/
program_wireworld.dps
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
void main()
{
int side = 16;
int[side][side] array;
int[side][side] copy;
for (int i = 0; i < side; i = i+1)
{
for (int j = 0; j < side; j = j+1)
{
array[i][j] = 0;
}
}
// line of copper
for (int i = 1; i < side-1; i = i+1)
{
array[8][i] = 3;
}
// loop
for (int i = 6; i < side-1; i = i+1)
{
array[6][i] = 3;
}
array[7][6] = 3;
array[7][14] = 3;
// diode
array[7][3] = 3;
array[9][3] = 3;
array[8][4] = 0;
array[7][4] = 3;
array[9][4] = 3;
// spark
array[8][10] = 1;
asm("syscall #42", side, array);
int iterations = 15;
do
{
copy = array;
for (int i = 1; i < side-1; i = i+1)
{
for (int j = 1; j < side-1; j = j+1)
{
int state = copy[i][j];
if (state == 1) // head
state = 2;
else if (state == 2) // tail
state = 3;
else if (state == 3) // conductor
{
int count = 0;
if (copy[i-1][j-1] == 1)
count = count + 1;
if (copy[i-1][j] == 1)
count = count + 1;
if (copy[i-1][j+1] == 1)
count = count + 1;
if (copy[i][j-1] == 1)
count = count + 1;
if (copy[i][j+1] == 1)
count = count + 1;
if (copy[i+1][j-1] == 1)
count = count + 1;
if (copy[i+1][j] == 1)
count = count + 1;
if (copy[i+1][j+1] == 1)
count = count + 1;
if (count == 1)
state = 1;
if (count == 2)
state = 1;
}
array[i][j] = state;
}
}
asm("syscall #42", side, array);
} while (iterations = iterations - 1);
}