-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRule5.pde
128 lines (104 loc) · 2.79 KB
/
Rule5.pde
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class Rule5 extends Rule {
// tmp working registers for coordinates
Coord p1 = new Coord(0, 0, 0);
Coord p2 = new Coord(0, 0, 0);
Coord p3 = new Coord(0, 0, 0);
Coord p4 = new Coord(0, 0, 0);
// busy box rule
/*
Phase 0: apply rule to even field in XY plane
Phase 1: apply rule to odd field in YZ plane
Phase 2: apply rule to even field in XZ plane
Phase 3: apply rule to odd field in XY plane
Phase 4: apply rule to even field in YZ plane
Phase 5: apply rule to odd field in XZ plane
*/
//knights moves XY plane
class Swap {
Coord a;
Coord b;
public Swap(int x1, int y1, int z1, int x2, int y2, int z2) {
a = new Coord(x1, y1, z1);
b = new Coord(x2, y2, z2);
}
}
Swap dxy1 = new Swap(2, 1, 0, 1, 2, 0);
Swap dxy2 = new Swap(2, -1, 0, 1, -2, 0);
//knights moves XZ plane
Swap dxz1 = new Swap(2, 0, 1, 1, 0, 2);
Swap dxz2 = new Swap(2, 0, -1, 1, 0, -2);
//knights moves YZ plane
Swap dyz1 = new Swap(0, 2, 1, 0, 1, 2);
Swap dyz2 = new Swap(0, 2, -1, 0, 1, -2);
void runRule() {
setPhases(6);
int phase = clockPhase();
ArrayList<Cell> cells;
if (phase % 2 == 0) {
cells = evenCells;
} else {
cells = oddCells;
}
switch(phase) {
case 0:
busybox(cells, dxy1, dxy2);
break;
case 1:
busybox(cells, dyz1, dyz2);
break;
case 2:
busybox(cells, dxz1, dxz2);
break;
case 3:
busybox(cells, dxy1, dxy2);
break;
case 4:
busybox(cells, dyz1, dyz2);
break;
case 5:
busybox(cells, dxz1, dxz2);
break;
}
}
void busybox(ArrayList<Cell> cells, Swap s1, Swap s2) {
for (Cell cell : cells) {
addCoords(cell.loc, s1.a, p1); // p1 := cell + delta1
addCoords(cell.loc, s1.b, p2); // p1 := cell + delta1
addCoords(cell.loc, s2.a, p3); // p1 := cell + delta1
addCoords(cell.loc, s2.b, p4); // p1 := cell + delta1
if (cell.state != 0) {
proposeSwap(p1, p2);
proposeSwap(p3, p4);
}
subCoords(cell.loc, s1.a, p1); // p1 := cell + delta1
subCoords(cell.loc, s1.b, p2); // p1 := cell + delta1
subCoords(cell.loc, s2.a, p3); // p1 := cell + delta1
subCoords(cell.loc, s2.b, p4); // p1 := cell + delta1
if (cell.state != 0) {
proposeSwap(p1, p2);
proposeSwap(p3, p4);
}
}
}
void initConfig() {
for (int i = 0; i < 32; i++) {
addCircular("X", -64+i*8, 0, 0, 64);
}
println("WTF");
}
void addCircular(String orientation, int x, int y, int z, int d) {
int k = 0;
int j = 0;
for (int i = 0; i < d; i++) {
addCell(x-j, y-k, z, 1);
if (i % 2 == 0) {
j+=2;
k+=1;
} else {
j+=1;
k+=2;
}
}
addCell(x+1, y, z, 1);
}
}