230 |
230 |
// order: Up --> Right --> Front --> Down --> Left --> Back
|
231 |
231 |
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)
|
232 |
232 |
//
|
233 |
|
// s : size of the cube
|
|
233 |
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"
|
234 |
234 |
//
|
235 |
|
// Left : index --> ((s-1) + index/s) * s + index%s
|
|
235 |
// s : size of the cube; let index = a*s + b (i.e. a,b = row,column)
|
|
236 |
//
|
|
237 |
// Up : index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a
|
236 |
238 |
// Right : index --> 6*s*s - 12*s + 7 - index
|
237 |
|
// Bottom: index --> s|index ? (s-1 - index/s) : (s*s + s-1 + 4*(index%s -1)*(s-1) - index/s)
|
238 |
|
// Top : index -->
|
239 |
|
// Front : index -->
|
240 |
|
// Back : index -->
|
|
239 |
// Front : index --> if b==0 : s*s - 1 - index
|
|
240 |
// if b==s-1: 6*s*s -11*s +6 - index
|
|
241 |
// else
|
|
242 |
// a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s
|
|
243 |
// else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a)
|
|
244 |
// Down : index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a
|
|
245 |
// Left : index --> (s-1-a)*s + b
|
|
246 |
// Back : index --> if b==s-1: s*(s-1-a)
|
|
247 |
// if b==0 : 5*s*s -12*s + 8 + (s-1-a)*s
|
|
248 |
// else
|
|
249 |
// if a==s-1: s*s + 4*(s-2-b)*(s-1)
|
|
250 |
// else : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2
|
241 |
251 |
|
242 |
252 |
public String retObjectString()
|
243 |
253 |
{
|
244 |
|
String ret="UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB";
|
245 |
|
/*
|
246 |
|
int color;
|
247 |
|
int F=retColor(FRONT , 1,1);
|
248 |
|
int B=retColor(BACK , 1,1);
|
249 |
|
int L=retColor(LEFT , 1,1);
|
250 |
|
int R=retColor(RIGHT , 1,1);
|
251 |
|
int U=retColor(TOP , 1,1);
|
252 |
|
int D=retColor(BOTTOM, 1,1);
|
253 |
|
|
254 |
|
for(int face in {TOP,RIGHT,FRONT,BOTTOM,LEFT,BACK} )
|
255 |
|
for(int row=0; row<mSize; row++)
|
256 |
|
for(int col=0; col<mSize; col++)
|
257 |
|
{
|
258 |
|
color = retColor(TOP,col,row);
|
259 |
|
|
260 |
|
if(color==F) ret+="F";
|
261 |
|
if(color==B) ret+="B";
|
262 |
|
if(color==L) ret+="L";
|
263 |
|
if(color==R) ret+="R";
|
264 |
|
if(color==U) ret+="U";
|
265 |
|
if(color==D) ret+="D";
|
266 |
|
}
|
267 |
|
*/
|
268 |
|
return ret;
|
|
254 |
StringBuilder objectString = new StringBuilder();
|
|
255 |
int size = getSize();
|
|
256 |
int len = size*size;
|
|
257 |
int cubitIndex, row, col;
|
|
258 |
int color;
|
|
259 |
|
|
260 |
final int RIGHT= 0;
|
|
261 |
final int LEFT = 1;
|
|
262 |
final int UP = 2;
|
|
263 |
final int DOWN = 3;
|
|
264 |
final int FRONT= 4;
|
|
265 |
final int BACK = 5;
|
|
266 |
|
|
267 |
final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B'};
|
|
268 |
|
|
269 |
for(int i=0; i<len; i++)
|
|
270 |
{
|
|
271 |
row = i/size;
|
|
272 |
col = i%size;
|
|
273 |
|
|
274 |
cubitIndex = col<size-1 ? (size-1)*(size+4*col) + row : 6*size*size - 13*size + 8 + row;
|
|
275 |
color = getCubitFaceColorIndex(cubitIndex,UP);
|
|
276 |
objectString.append(FACE_NAMES[color]);
|
|
277 |
}
|
|
278 |
|
|
279 |
for(int i=0; i<len; i++)
|
|
280 |
{
|
|
281 |
cubitIndex = 6*size*size - 12*size +7 - i;
|
|
282 |
color = getCubitFaceColorIndex(cubitIndex,RIGHT);
|
|
283 |
objectString.append(FACE_NAMES[color]);
|
|
284 |
}
|
|
285 |
|
|
286 |
for(int i=0; i<len; i++)
|
|
287 |
{
|
|
288 |
row = i/size;
|
|
289 |
col = i%size;
|
|
290 |
|
|
291 |
if( col==size-1 ) cubitIndex = 6*size*size - 11*size + 6 -i;
|
|
292 |
else if( col==0 ) cubitIndex = size*size - 1 - i;
|
|
293 |
else
|
|
294 |
{
|
|
295 |
if( row==0 ) cubitIndex = size*size + size-1 + 4*(col-1)*(size-1) + 2*(size-2) + size;
|
|
296 |
else cubitIndex = size*size + size-1 + 4*(col-1)*(size-1) + 2*(size-1-row);
|
|
297 |
}
|
|
298 |
|
|
299 |
color = getCubitFaceColorIndex(cubitIndex,FRONT);
|
|
300 |
objectString.append(FACE_NAMES[color]);
|
|
301 |
}
|
|
302 |
|
|
303 |
for(int i=0; i<len; i++)
|
|
304 |
{
|
|
305 |
row = i/size;
|
|
306 |
col = i%size;
|
|
307 |
|
|
308 |
cubitIndex = col==0 ? size-1-row : size*size + size-1 + 4*(col-1)*(size-1) - row;
|
|
309 |
color = getCubitFaceColorIndex(cubitIndex,DOWN);
|
|
310 |
objectString.append(FACE_NAMES[color]);
|
|
311 |
}
|
|
312 |
|
|
313 |
for(int i=0; i<len; i++)
|
|
314 |
{
|
|
315 |
row = i/size;
|
|
316 |
col = i%size;
|
|
317 |
|
|
318 |
cubitIndex = (size-1-row)*size + col;
|
|
319 |
color = getCubitFaceColorIndex(cubitIndex,LEFT);
|
|
320 |
objectString.append(FACE_NAMES[color]);
|
|
321 |
}
|
|
322 |
|
|
323 |
for(int i=0; i<len; i++)
|
|
324 |
{
|
|
325 |
row = i/size;
|
|
326 |
col = i%size;
|
|
327 |
|
|
328 |
if( col==size-1 ) cubitIndex = size*(size-1-row);
|
|
329 |
else if( col==0 ) cubitIndex = 5*size*size - 12*size + 8 + (size-1-row)*size;
|
|
330 |
else
|
|
331 |
{
|
|
332 |
if( row==size-1 ) cubitIndex = size*size + 4*(size-2-col)*(size-1);
|
|
333 |
else cubitIndex = size*size + 4*(size-2-col)*(size-1) + size + 2*(size-2-row);
|
|
334 |
}
|
|
335 |
|
|
336 |
color = getCubitFaceColorIndex(cubitIndex,BACK);
|
|
337 |
objectString.append(FACE_NAMES[color]);
|
|
338 |
}
|
|
339 |
|
|
340 |
// android.util.Log.e("cube", "string: "+objectString.toString());
|
|
341 |
|
|
342 |
return objectString.toString();
|
269 |
343 |
}
|
270 |
344 |
}
|
Progress with the Solver - RubikCube.retObjectString() finished.
What remains to be done here: ban changing colors of the centers of 3x3x3 faces, this shouldn't be allowed!