-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirstLayer.go
203 lines (193 loc) · 5.63 KB
/
firstLayer.go
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
func (env *Env) PutYellowCubieontheirface() {
for i := 0; i < 3; i++ {
if i == 1 {
env.exec("R' U R F2")
} else if i == 2 {
env.exec("L U' L' F2")
}
for j := 0; j < 4; j++ {
for k := 0; k < 4; k++ {
if 4 == ((env.currentCube.cube[YELLOW]>>24)&15) || 4 == ((env.currentCube.cube[ORANGE]>>8)&15) {
return
}
env.exec("F")
}
env.exec("U")
}
}
}
func (env *Env) firstCross() {
for i := 0; i < 4; i++ {
env.PutYellowCubieontheirface()
if 4 == ((env.currentCube.cube[ORANGE] >> 8) & 15) {
env.exec("F' R U R' F2") // Algo for reverse cubie
}
env.exec("D'")
}
// next align yellow aretes cubie every with the correct color of their side
var CubiefaceOrange bool
var CubiefaceBlue bool
var CubiefaceRed bool
var CubiefaceGreen bool
for true {
var s []bool
CubiefaceOrange = ((env.currentCube.cube[ORANGE] >> 8) & 15) == 0
CubiefaceBlue = ((env.currentCube.cube[BLUE] >> 8) & 15) == 2
CubiefaceRed = ((env.currentCube.cube[RED] >> 24) & 15) == 5
CubiefaceGreen = ((env.currentCube.cube[GREEN] >> 8) & 15) == 1
if CubiefaceOrange == true {
s = append(s, CubiefaceOrange)
}
if CubiefaceBlue == true {
s = append(s, CubiefaceBlue)
}
if CubiefaceRed == true {
s = append(s, CubiefaceRed)
}
if CubiefaceGreen == true {
s = append(s, CubiefaceGreen)
}
if len(s) >= 2 {
break
}
env.exec("D")
}
if !CubiefaceOrange && !CubiefaceRed {
env.exec("F2 U2 B2 U2 F2") // swap ORANGE-RED
} else if !CubiefaceGreen && !CubiefaceBlue {
env.exec("R2 U2 L2 U2 R2") // swap GREEN-BLUE
} else if !CubiefaceOrange && !CubiefaceGreen {
env.exec("F2 U' R2 U F2") //swap ORANGE-GREEN
} else if !CubiefaceGreen && !CubiefaceRed {
env.exec("R2 U' B2 U R2") //swap GREEN-RED
} else if !CubiefaceRed && !CubiefaceBlue {
env.exec("B2 U' L2 U B2") //swap RED-BLUE
} else if !CubiefaceBlue && !CubiefaceOrange {
env.exec("L2 U' F2 U L2") //swap BLUE-ORANGE
}
}
func (env *Env) firstPossibleCorner(face int32, cube [6]int32) bool {
var onecolor bool
if face == ORANGE {
onecolor = ((cube[ORANGE]>>20)&15) == YELLOW &&
((cube[GREEN]>>28)&15) == GREEN &&
((cube[WHITE]>>12)&15) == ORANGE
} else if face == GREEN {
onecolor = ((cube[GREEN]>>20)&15) == YELLOW &&
((cube[RED]>>12)&15) == RED &&
((cube[WHITE]>>20)&15) == GREEN
} else if face == RED {
onecolor = ((cube[RED]>>4)&15) == YELLOW &&
((cube[BLUE]>>28)&15) == BLUE &&
((cube[WHITE]>>28)&15) == RED
} else if face == BLUE {
onecolor = ((cube[BLUE]>>20)&15) == YELLOW &&
((cube[ORANGE]>>28)&15) == ORANGE &&
((cube[WHITE]>>4)&15) == BLUE
}
return onecolor
}
func (env *Env) secondPossibleCorner(face int32, cube [6]int32) bool {
var twocolor bool
if face == ORANGE {
twocolor = ((cube[ORANGE]>>20)&15) == ORANGE &&
((cube[GREEN]>>28)&15) == YELLOW &&
((cube[WHITE]>>12)&15) == GREEN
} else if face == GREEN {
twocolor = ((cube[GREEN]>>20)&15) == GREEN &&
((cube[RED]>>12)&15) == YELLOW &&
((cube[WHITE]>>20)&15) == RED
} else if face == RED {
twocolor = ((cube[RED]>>4)&15) == RED &&
((cube[BLUE]>>28)&15) == YELLOW &&
((cube[WHITE]>>28)&15) == BLUE
} else if face == BLUE {
twocolor = ((cube[BLUE]>>20)&15) == BLUE &&
((cube[ORANGE]>>28)&15) == YELLOW &&
((cube[WHITE]>>4)&15) == ORANGE
}
return twocolor
}
func (env *Env) thridPossibleCorner(face int32, cube [6]int32) bool {
var threecolor bool
if face == ORANGE {
threecolor = ((cube[ORANGE]>>20)&15) == GREEN &&
((cube[GREEN]>>28)&15) == ORANGE &&
((cube[WHITE]>>12)&15) == YELLOW
} else if face == GREEN {
threecolor = ((cube[GREEN]>>20)&15) == RED &&
((cube[RED]>>12)&15) == GREEN &&
((cube[WHITE]>>20)&15) == YELLOW
} else if face == RED {
threecolor = ((cube[RED]>>4)&15) == BLUE &&
((cube[BLUE]>>28)&15) == RED &&
((cube[WHITE]>>28)&15) == YELLOW
} else if face == BLUE {
threecolor = ((cube[BLUE]>>20)&15) == ORANGE &&
((cube[ORANGE]>>28)&15) == BLUE &&
((cube[WHITE]>>4)&15) == YELLOW
}
return threecolor
}
func (env *Env) isalreadyinplace(face int32, cube [6]int32) bool {
var result bool
if face == ORANGE {
result = ((cube[ORANGE]>>12)&15) == ORANGE &&
((cube[GREEN]>>4)&15) == GREEN &&
((cube[YELLOW]>>20)&15) == YELLOW
} else if face == GREEN {
result = ((cube[GREEN]>>12)&15) == GREEN &&
((cube[RED]>>20)&15) == RED &&
((cube[YELLOW]>>12)&15) == YELLOW
} else if face == RED {
result = ((cube[RED]>>28)&15) == RED &&
((cube[BLUE]>>4)&15) == BLUE &&
((cube[YELLOW]>>4)&15) == YELLOW
} else if face == BLUE {
result = ((cube[BLUE]>>12)&15) == BLUE &&
((cube[ORANGE]>>4)&15) == ORANGE &&
((cube[YELLOW]>>28)&15) == YELLOW
}
return result
}
func (env *Env) faceFirstLayer(face int32) {
var first bool
var second bool
var third bool
if env.isalreadyinplace(face, env.currentCube.cube) {
return
}
// Cas orange face :
for i := 0; i <= 4; i++ {
for j := 0; j < 4; j++ {
first = env.firstPossibleCorner(face, env.currentCube.cube)
second = env.secondPossibleCorner(face, env.currentCube.cube)
third = env.thridPossibleCorner(face, env.currentCube.cube)
if first {
env.execFace("F' U' F", face)
return
} else if second {
env.execFace("R U R'", face)
return
} else if third {
env.execFace("R B U2 B' R'", face)
return
} else {
//sinon change de corner
env.execFace("U", face)
}
}
// If the corner is block, need to deblock it
// Warning, ne pas enlever une piece deja mise
if i == 0 && face == ORANGE {
env.exec("R U R'")
} else if i == 1 && (face == ORANGE || face == GREEN) {
env.exec("R' U R")
} else if i == 2 && face != BLUE {
env.exec("L U L'")
} else if i == 3 {
env.exec("L' U L")
}
}
}