Revision fbffa02a
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/solvers/SolverMain.java | ||
---|---|---|
106 | 106 |
// (because the first implemented Solver - the two-phase Cube3 one - expects such order) |
107 | 107 |
// |
108 | 108 |
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB" |
109 |
// |
|
110 |
// s : size of the cube; let index = a*s + b (i.e. a,b = row,column) |
|
111 |
// |
|
112 |
// Up : index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a |
|
113 |
// Right : index --> 6*s*s - 12*s + 7 - index |
|
114 |
// Front : index --> if b==0 : s*s - 1 - index |
|
115 |
// if b==s-1: 6*s*s -11*s +6 - index |
|
116 |
// else |
|
117 |
// a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s |
|
118 |
// else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a) |
|
119 |
// Down : index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a |
|
120 |
// Left : index --> (s-1-a)*s + b |
|
121 |
// Back : index --> if b==s-1: s*(s-1-a) |
|
122 |
// if b==0 : 5*s*s -12*s + 8 + (s-1-a)*s |
|
123 |
// else |
|
124 |
// if a==s-1: s*s + 4*(s-2-b)*(s-1) |
|
125 |
// else : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2 |
|
126 | 109 |
|
127 | 110 |
private String prepareCube3position() |
128 | 111 |
{ |
129 | 112 |
StringBuilder objectString = new StringBuilder(); |
130 |
int layers = 3; |
|
131 |
int len = layers*layers; |
|
132 |
int cubitIndex, row, col, color,face; |
|
133 | 113 |
|
134 |
final int RIGHT= 0;
|
|
135 |
final int LEFT = 1;
|
|
136 |
final int UP = 2;
|
|
137 |
final int DOWN = 3;
|
|
138 |
final int FRONT= 4;
|
|
139 |
final int BACK = 5;
|
|
114 |
final int R = 0;
|
|
115 |
final int L = 1; |
|
116 |
final int U = 2; |
|
117 |
final int D = 3; |
|
118 |
final int F = 4;
|
|
119 |
final int B = 5; |
|
140 | 120 |
|
141 | 121 |
// 'I' - interior, theoretically can happen |
142 | 122 |
final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B', 'I'}; |
143 | 123 |
|
144 |
face = UP; |
|
124 |
final int[] U_INDEX = { 2,10, 6,17,22,19, 3,11, 7}; |
|
125 |
final int[] R_INDEX = { 7,19, 6,15,20,14, 5,18, 4}; |
|
126 |
final int[] F_INDEX = { 3,11, 7,13,24,15, 1, 9, 5}; |
|
127 |
final int[] D_INDEX = { 1, 9, 5,16,23,18, 0, 8, 4}; |
|
128 |
final int[] L_INDEX = { 2,17, 3,12,21,13, 0,16, 1}; |
|
129 |
final int[] B_INDEX = { 6,10, 2,14,25,12, 4, 8, 0}; |
|
145 | 130 |
|
146 |
for(int i=0; i<len; i++)
|
|
131 |
for(int i=0; i<9; i++)
|
|
147 | 132 |
{ |
148 |
row = i/layers; |
|
149 |
col = i%layers; |
|
150 |
|
|
151 |
cubitIndex = col<layers-1 ? (layers-1)*(layers+4*col) + row : 6*layers*layers - 13*layers + 8 + row; |
|
152 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
133 |
int color = mObject.getCubitFaceColorIndex(U_INDEX[i], i==4 ? F : U); |
|
153 | 134 |
objectString.append(FACE_NAMES[color]); |
154 | 135 |
} |
155 |
|
|
156 |
face = RIGHT; |
|
157 |
|
|
158 |
for(int i=0; i<len; i++) |
|
136 |
for(int i=0; i<9; i++) |
|
159 | 137 |
{ |
160 |
cubitIndex = 6*layers*layers - 12*layers +7 - i; |
|
161 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
138 |
int color = mObject.getCubitFaceColorIndex(R_INDEX[i], i==4 ? F : R); |
|
162 | 139 |
objectString.append(FACE_NAMES[color]); |
163 | 140 |
} |
164 |
|
|
165 |
face = FRONT; |
|
166 |
|
|
167 |
for(int i=0; i<len; i++) |
|
141 |
for(int i=0; i<9; i++) |
|
168 | 142 |
{ |
169 |
row = i/layers; |
|
170 |
col = i%layers; |
|
171 |
|
|
172 |
if( col==layers-1 ) cubitIndex = 6*layers*layers - 11*layers + 6 -i; |
|
173 |
else if( col==0 ) cubitIndex = layers*layers - 1 - i; |
|
174 |
else |
|
175 |
{ |
|
176 |
if( row==0 ) cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-2) + layers; |
|
177 |
else cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-1-row); |
|
178 |
} |
|
179 |
|
|
180 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
143 |
int color = mObject.getCubitFaceColorIndex(F_INDEX[i], i==4 ? F : F); |
|
181 | 144 |
objectString.append(FACE_NAMES[color]); |
182 | 145 |
} |
183 |
|
|
184 |
face = DOWN; |
|
185 |
|
|
186 |
for(int i=0; i<len; i++) |
|
146 |
for(int i=0; i<9; i++) |
|
187 | 147 |
{ |
188 |
row = i/layers; |
|
189 |
col = i%layers; |
|
190 |
|
|
191 |
cubitIndex = col==0 ? layers-1-row : layers*layers + layers-1 + 4*(col-1)*(layers-1) - row; |
|
192 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
148 |
int color = mObject.getCubitFaceColorIndex(D_INDEX[i], i==4 ? F : D); |
|
193 | 149 |
objectString.append(FACE_NAMES[color]); |
194 | 150 |
} |
195 |
|
|
196 |
face = LEFT; |
|
197 |
|
|
198 |
for(int i=0; i<len; i++) |
|
151 |
for(int i=0; i<9; i++) |
|
199 | 152 |
{ |
200 |
row = i/layers; |
|
201 |
col = i%layers; |
|
202 |
|
|
203 |
cubitIndex = (layers-1-row)*layers + col; |
|
204 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
153 |
int color = mObject.getCubitFaceColorIndex(L_INDEX[i], i==4 ? F : L); |
|
205 | 154 |
objectString.append(FACE_NAMES[color]); |
206 | 155 |
} |
207 |
|
|
208 |
face = BACK; |
|
209 |
|
|
210 |
for(int i=0; i<len; i++) |
|
156 |
for(int i=0; i<9; i++) |
|
211 | 157 |
{ |
212 |
row = i/layers; |
|
213 |
col = i%layers; |
|
214 |
|
|
215 |
if( col==layers-1 ) cubitIndex = layers*(layers-1-row); |
|
216 |
else if( col==0 ) cubitIndex = 5*layers*layers - 12*layers + 8 + (layers-1-row)*layers; |
|
217 |
else |
|
218 |
{ |
|
219 |
if( row==layers-1 ) cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1); |
|
220 |
else cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1) + layers + 2*(layers-2-row); |
|
221 |
} |
|
222 |
|
|
223 |
color = mObject.getCubitFaceColorIndex(cubitIndex,face); |
|
158 |
int color = mObject.getCubitFaceColorIndex(B_INDEX[i], i==4 ? F : B); |
|
224 | 159 |
objectString.append(FACE_NAMES[color]); |
225 | 160 |
} |
226 | 161 |
|
162 |
android.util.Log.e("D", objectString.toString()); |
|
163 |
|
|
227 | 164 |
return objectString.toString(); |
228 | 165 |
} |
229 | 166 |
|
Also available in: Unified diff
Fix the Solver