-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLL.cpp
84 lines (74 loc) · 2.58 KB
/
PLL.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
#include "cube.h"
#include "solver.h"
#include <vector>
void Solver::aperm() {
R(); B(); B(); B(); R(); F(); F();
R(); R(); R(); B(); R(); F(); F(); R(); R();
}
void Solver::PLL() {
bool DEBUG = false;
while (true) {
if (DEBUG) state.disp();
int chestplates = 0; // Named after the crafting recipe for the aforementioned object in Minecraft.
for (int i = 0; i < 4; i++) {
if (state.FRONT[0][2] == state.FRONT[2][2]) {
chestplates++;
}
U();
}
if (chestplates == 0) {
aperm();
continue;
}
if (chestplates == 1) {
while (state.FRONT[0][2] != state.FRONT[2][2]) U();
aperm();
continue;
}
// There are either 0 1 or 4 chestplates. The next case handles 4.
if (state.FRONT[1][2] == state.FRONT[2][2] && state.RIGHT[1][2] == state.RIGHT[2][2] && state.BACK[1][2] == state.BACK[2][2] && state.LEFT[1][2] == state.LEFT[2][2]) {
while (state.FRONT[1][2] != state.FRONT[1][1]) U();
return;
}
if (state.FRONT[1][2] == state.BACK[2][2] && state.BACK[1][2] == state.FRONT[2][2] && state.LEFT[1][2] == state.RIGHT[2][2] && state.RIGHT[1][2] == state.LEFT[2][2]) {
R(); R(); L(); L(); X(); X(); U();
R(); R(); L(); L(); X(); X(); U(); U();
R(); R(); L(); L(); X(); X(); U();
R(); R(); L(); L(); X(); X();
while (state.FRONT[1][2] != state.FRONT[1][1]) U();
}
int disparities = 0;
for (int i = 0; i < 4; i++) {
if (state.FRONT[1][2] != state.FRONT[0][2]) disparities++;
U();
}
if (disparities == 3) {
while (state.BACK[1][2] != state.BACK[2][2]) U();
if (state.RIGHT[1][2] == state.LEFT[2][2]) {
R(); U(); U(); U();
R(); U(); R(); U();
R(); U(); U(); U();
R(); R(); R(); U(); U(); U();
R(); R();
}
else {
L(); L(); L(); U();
L(); L(); L(); U(); U(); U();
L(); L(); L(); U(); U(); U();
L(); L(); L(); U();
L(); U(); L(); L();
}
while (state.FRONT[1][2] != state.FRONT[1][1]) U();
}
else {
while (state.FRONT[1][2] != state.RIGHT[0][2]) U();
R(); R(); L(); L(); X(); X(); U();
R(); R(); L(); L(); X(); X(); U();
R(); R(); R(); L(); X(); U(); U();
R(); R(); L(); L(); X(); X(); U(); U();
R(); R(); R(); L(); X();
while (state.FRONT[1][2] != state.FRONT[1][1]) U();
}
return;
}
}