-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondLayer.go
166 lines (155 loc) · 4.82 KB
/
secondLayer.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
package main
const RIGHT = 1
const LEFT = 2
//https://ruwix.com/the-rubiks-cube/how-to-solve-the-rubiks-cube-beginners-method/
func (env *Env) arreteintop(face int32, cube [6]int32) int32 {
if face == ORANGE {
if (((cube[ORANGE]>>24)&15) == ORANGE &&
(((cube[WHITE]>>8)&15) == GREEN || ((cube[WHITE]>>8)&15) == BLUE)) ||
(((cube[WHITE]>>8)&15) == ORANGE &&
(((cube[ORANGE]>>24)&15) == GREEN || ((cube[ORANGE]>>24)&15) == BLUE)) {
if (((cube[WHITE] >> 8) & 15) == GREEN) || (((cube[ORANGE] >> 24) & 15) == GREEN) {
return RIGHT
}
return LEFT
}
return 0
} else if face == GREEN {
if (((cube[GREEN]>>24)&15) == GREEN &&
(((cube[WHITE]>>16)&15) == RED || ((cube[WHITE]>>16)&15) == ORANGE)) ||
(((cube[WHITE]>>16)&15) == GREEN &&
(((cube[GREEN]>>24)&15) == RED || ((cube[GREEN]>>24)&15) == ORANGE)) {
if (((cube[WHITE] >> 16) & 15) == RED) || (((cube[GREEN] >> 24) & 15) == RED) {
return RIGHT
}
return LEFT
}
return 0
} else if face == RED {
if (((cube[RED]>>8)&15) == RED &&
(((cube[WHITE]>>24)&15) == BLUE || ((cube[WHITE]>>24)&15) == GREEN)) ||
(((cube[WHITE]>>24)&15) == RED &&
(((cube[RED]>>8)&15) == BLUE || ((cube[RED]>>8)&15) == GREEN)) {
if (((cube[WHITE] >> 24) & 15) == BLUE) || (((cube[RED] >> 8) & 15) == BLUE) {
return RIGHT
}
return LEFT
}
return 0
} else if face == BLUE {
if (((cube[BLUE]>>24)&15) == BLUE &&
(((cube[WHITE]>>0)&15) == RED || ((cube[WHITE]>>0)&15) == ORANGE)) ||
(((cube[WHITE]>>0)&15) == BLUE &&
(((cube[BLUE]>>24)&15) == RED || ((cube[BLUE]>>24)&15) == ORANGE)) {
if (((cube[WHITE] >> 0) & 15) == ORANGE) || (((cube[BLUE] >> 24) & 15) == ORANGE) {
return RIGHT
}
return LEFT
}
return 0
}
return 0
}
func (env *Env) secondlayerisbarelyFinnished(cube [6]int32) bool {
var orangeface bool
var greenface bool
var redface bool
var blueface bool
orangeface = (((cube[ORANGE]>>0)&15) == ORANGE || ((cube[ORANGE]>>0)&15) == BLUE) &&
(((cube[ORANGE]>>16)&15) == ORANGE || ((cube[ORANGE]>>16)&15) == GREEN)
greenface = (((cube[GREEN]>>0)&15) == GREEN || ((cube[GREEN]>>0)&15) == ORANGE) &&
(((cube[GREEN]>>16)&15) == GREEN || ((cube[GREEN]>>16)&15) == RED)
redface = (((cube[RED]>>0)&15) == RED || ((cube[RED]>>0)&15) == BLUE) &&
(((cube[RED]>>16)&15) == RED || ((cube[RED]>>16)&15) == GREEN)
blueface = (((cube[BLUE]>>0)&15) == BLUE || ((cube[BLUE]>>0)&15) == RED) &&
(((cube[BLUE]>>16)&15) == BLUE || ((cube[BLUE]>>16)&15) == ORANGE)
if orangeface && greenface && redface && blueface {
return true
}
return false
}
func (env *Env) dealwithwrongorientation() {
if ((env.currentCube.cube[ORANGE] >> 16) & 15) == GREEN {
env.execFace("U R U' R' U' F' U F U2 U R U' R' U' F' U F", ORANGE)
}
if ((env.currentCube.cube[GREEN] >> 16) & 15) == RED {
env.execFace("U R U' R' U' F' U F U2 U R U' R' U' F' U F", GREEN)
}
if ((env.currentCube.cube[RED] >> 0) & 15) == BLUE {
env.execFace("U R U' R' U' F' U F U2 U R U' R' U' F' U F", RED)
}
if ((env.currentCube.cube[BLUE] >> 16) & 15) == ORANGE {
env.execFace("U R U' R' U' F' U F U2 U R U' R' U' F' U F", BLUE)
}
}
func (env *Env) inwrongplace(face int32, cube [6]int32) bool {
if face == ORANGE {
if (((cube[ORANGE]>>16)&15) == ORANGE ||
((cube[ORANGE]>>16)&15) == GREEN) &&
(((cube[GREEN]>>0)&15) == GREEN ||
((cube[GREEN]>>0)&15) == ORANGE) {
return false
}
return true
} else if face == GREEN {
if (((cube[GREEN]>>16)&15) == GREEN ||
((cube[GREEN]>>16)&15) == RED) &&
(((cube[RED]>>16)&15) == RED ||
((cube[RED]>>16)&15) == GREEN) {
return false
}
return true
} else if face == RED {
if (((cube[RED]>>0)&15) == RED ||
((cube[RED]>>0)&15) == BLUE) &&
(((cube[BLUE]>>0)&15) == BLUE ||
((cube[BLUE]>>0)&15) == RED) {
return false
}
return true
} else if face == BLUE {
if (((cube[BLUE]>>16)&15) == BLUE ||
((cube[BLUE]>>16)&15) == ORANGE) &&
(((cube[ORANGE]>>0)&15) == ORANGE ||
((cube[ORANGE]>>0)&15) == BLUE) {
return false
}
return true
}
return false
}
func (env *Env) secondLayer() {
faceSecondLayer := [4]int32{ORANGE, GREEN, RED, BLUE}
var o bool
o = false
for true {
o = false
for i := 0; i < 4; i++ {
for _, slayer := range faceSecondLayer {
value := env.arreteintop(slayer, env.currentCube.cube)
if value == RIGHT {
o = true
env.execFace("U R U' R' U' F' U F", slayer)
} else if value == LEFT {
o = true
env.execFace("U' L' U L U F U' F'", slayer)
}
}
if env.secondlayerisbarelyFinnished(env.currentCube.cube) {
env.dealwithwrongorientation()
return
}
env.exec("U")
}
if o == false {
//the border are in the wrong place, need to deloge them
for _, slayer := range faceSecondLayer {
value := env.inwrongplace(slayer, env.currentCube.cube)
if value {
env.execFace("U R U' R' U' F' U F", slayer)
break
}
}
}
}
}