Revision 1f9772f3
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/solvers/cube3/CoordCube.java | ||
---|---|---|
77 | 77 |
private static byte[] twistMove = new byte[2*N_TWIST*N_MOVE]; |
78 | 78 |
|
79 | 79 |
public static boolean initialize1(Resources res) |
80 |
{/* |
|
81 |
if( init[0]==true ) return; |
|
82 |
|
|
83 |
CubieCube a = new CubieCube(); |
|
84 |
for (short i = 0; i < N_TWIST; i++) { |
|
85 |
a.setTwist(i); |
|
86 |
for (int j = 0; j < 6; j++) { |
|
87 |
for (int k = 0; k < 3; k++) { |
|
88 |
a.cornerMultiply(CubieCube.moveCube[j]); |
|
89 |
twistMove[i][3 * j + k] = a.getTwist(); |
|
90 |
} |
|
91 |
a.cornerMultiply(CubieCube.moveCube[j]);// 4. faceturn restores |
|
92 |
// a |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
init[0]=true; |
|
97 |
*/ |
|
98 |
if( init[0]==false ) |
|
80 |
{ |
|
81 |
if( !init[0] ) |
|
99 | 82 |
{ |
100 | 83 |
try |
101 | 84 |
{ |
102 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table1);
|
|
85 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table1);
|
|
103 | 86 |
is.read( twistMove, 0, 2*N_TWIST*N_MOVE); |
104 | 87 |
} |
105 | 88 |
catch(Exception ioe) |
... | ... | |
132 | 115 |
private static byte[] flipMove = new byte[2*N_FLIP*N_MOVE]; |
133 | 116 |
|
134 | 117 |
public static boolean initialize2(Resources res) |
135 |
{/* |
|
136 |
if( init[1]==true ) return; |
|
137 |
|
|
138 |
CubieCube a = new CubieCube(); |
|
139 |
for (short i = 0; i < N_FLIP; i++) { |
|
140 |
a.setFlip(i); |
|
141 |
for (int j = 0; j < 6; j++) { |
|
142 |
for (int k = 0; k < 3; k++) { |
|
143 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
144 |
flipMove[i][3 * j + k] = a.getFlip(); |
|
145 |
} |
|
146 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
147 |
// a |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
init[1]=true; |
|
152 |
*/ |
|
153 |
if( init[1]==false ) |
|
118 |
{ |
|
119 |
if( !init[1] ) |
|
154 | 120 |
{ |
155 | 121 |
try |
156 | 122 |
{ |
157 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table2);
|
|
123 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table2);
|
|
158 | 124 |
is.read( flipMove, 0, 2*N_FLIP*N_MOVE); |
159 | 125 |
} |
160 | 126 |
catch(Exception ioe) |
... | ... | |
196 | 162 |
private static byte[] FRtoBR_Move = new byte[2*N_FRtoBR*N_MOVE]; |
197 | 163 |
|
198 | 164 |
public static boolean initialize3(Resources res) |
199 |
{/* |
|
200 |
if( init[2]==true ) return; |
|
201 |
|
|
202 |
CubieCube a = new CubieCube(); |
|
203 |
for (short i = 0; i < N_FRtoBR; i++) { |
|
204 |
a.setFRtoBR(i); |
|
205 |
for (int j = 0; j < 6; j++) { |
|
206 |
for (int k = 0; k < 3; k++) { |
|
207 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
208 |
FRtoBR_Move[i][3 * j + k] = a.getFRtoBR(); |
|
209 |
} |
|
210 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
init[2]=true; |
|
215 |
*/ |
|
216 |
|
|
217 |
if( init[2]==false ) |
|
165 |
{ |
|
166 |
if( !init[2] ) |
|
218 | 167 |
{ |
219 | 168 |
try |
220 | 169 |
{ |
221 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table3);
|
|
170 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table3);
|
|
222 | 171 |
is.read( FRtoBR_Move, 0, 2*N_FRtoBR*N_MOVE); |
223 | 172 |
} |
224 | 173 |
catch(Exception ioe) |
... | ... | |
254 | 203 |
private static byte[] URFtoDLF_Move = new byte[2*N_URFtoDLF*N_MOVE]; |
255 | 204 |
|
256 | 205 |
public static boolean initialize4(Resources res) |
257 |
{/* |
|
258 |
if( init[3]==true ) return; |
|
259 |
|
|
260 |
CubieCube a = new CubieCube(); |
|
261 |
for (short i = 0; i < N_URFtoDLF; i++) { |
|
262 |
a.setURFtoDLF(i); |
|
263 |
for (int j = 0; j < 6; j++) { |
|
264 |
for (int k = 0; k < 3; k++) { |
|
265 |
a.cornerMultiply(CubieCube.moveCube[j]); |
|
266 |
URFtoDLF_Move[i][3 * j + k] = a.getURFtoDLF(); |
|
267 |
} |
|
268 |
a.cornerMultiply(CubieCube.moveCube[j]); |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
init[3]=true; |
|
273 |
*/ |
|
274 |
if( init[3]==false ) |
|
206 |
{ |
|
207 |
if( !init[3] ) |
|
275 | 208 |
{ |
276 | 209 |
try |
277 | 210 |
{ |
278 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table4);
|
|
211 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table4);
|
|
279 | 212 |
is.read( URFtoDLF_Move, 0, 2*N_URFtoDLF*N_MOVE); |
280 | 213 |
} |
281 | 214 |
catch(Exception ioe) |
... | ... | |
309 | 242 |
private static byte[] URtoDF_Move = new byte[2*N_URtoDF*N_MOVE]; |
310 | 243 |
|
311 | 244 |
public static boolean initialize5(Resources res) |
312 |
{/* |
|
313 |
if( init[4]==true ) return; |
|
314 |
|
|
315 |
CubieCube a = new CubieCube(); |
|
316 |
for (short i = 0; i < N_URtoDF; i++) { |
|
317 |
a.setURtoDF(i); |
|
318 |
for (int j = 0; j < 6; j++) { |
|
319 |
for (int k = 0; k < 3; k++) { |
|
320 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
321 |
URtoDF_Move[i][3 * j + k] = (short) a.getURtoDF(); |
|
322 |
// Table values are only valid for phase 2 moves! |
|
323 |
// For phase 1 moves, casting to short is not possible. |
|
324 |
} |
|
325 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
init[4]=true; |
|
330 |
*/ |
|
331 |
if( init[4]==false ) |
|
245 |
{ |
|
246 |
if( !init[4] ) |
|
332 | 247 |
{ |
333 | 248 |
try |
334 | 249 |
{ |
335 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table5);
|
|
250 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table5);
|
|
336 | 251 |
is.read( URtoDF_Move, 0, 2*N_URtoDF*N_MOVE); |
337 | 252 |
} |
338 | 253 |
catch(Exception ioe) |
... | ... | |
364 | 279 |
private static byte[] URtoUL_Move = new byte[2*N_URtoUL*N_MOVE]; |
365 | 280 |
|
366 | 281 |
public static boolean initialize6(Resources res) |
367 |
{/* |
|
368 |
if( init[5]==true ) return; |
|
369 |
|
|
370 |
CubieCube a = new CubieCube(); |
|
371 |
for (short i = 0; i < N_URtoUL; i++) { |
|
372 |
a.setURtoUL(i); |
|
373 |
for (int j = 0; j < 6; j++) { |
|
374 |
for (int k = 0; k < 3; k++) { |
|
375 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
376 |
URtoUL_Move[i][3 * j + k] = a.getURtoUL(); |
|
377 |
} |
|
378 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
379 |
} |
|
380 |
} |
|
381 |
|
|
382 |
init[5]=true; |
|
383 |
*/ |
|
384 |
if( init[5]==false ) |
|
282 |
{ |
|
283 |
if( !init[5] ) |
|
385 | 284 |
{ |
386 | 285 |
try |
387 | 286 |
{ |
388 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table6);
|
|
287 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table6);
|
|
389 | 288 |
is.read( URtoUL_Move, 0, 2*N_URtoUL*N_MOVE); |
390 | 289 |
} |
391 | 290 |
catch(Exception ioe) |
... | ... | |
416 | 315 |
private static byte[] UBtoDF_Move = new byte[2*N_UBtoDF*N_MOVE]; |
417 | 316 |
|
418 | 317 |
public static boolean initialize7(Resources res) |
419 |
{/* |
|
420 |
if( init[6]==true ) return; |
|
421 |
|
|
422 |
CubieCube a = new CubieCube(); |
|
423 |
for (short i = 0; i < N_UBtoDF; i++) { |
|
424 |
a.setUBtoDF(i); |
|
425 |
for (int j = 0; j < 6; j++) { |
|
426 |
for (int k = 0; k < 3; k++) { |
|
427 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
428 |
UBtoDF_Move[i][3 * j + k] = a.getUBtoDF(); |
|
429 |
} |
|
430 |
a.edgeMultiply(CubieCube.moveCube[j]); |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
434 |
init[6]=true; |
|
435 |
*/ |
|
436 |
if( init[6]==false ) |
|
318 |
{ |
|
319 |
if( !init[6] ) |
|
437 | 320 |
{ |
438 | 321 |
try |
439 | 322 |
{ |
440 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table7);
|
|
323 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table7);
|
|
441 | 324 |
is.read( UBtoDF_Move, 0, 2*N_UBtoDF*N_MOVE); |
442 | 325 |
} |
443 | 326 |
catch(Exception ioe) |
... | ... | |
468 | 351 |
private static byte[] MergeURtoULandUBtoDF = new byte[2*336*336]; |
469 | 352 |
|
470 | 353 |
public static boolean initialize8(Resources res) |
471 |
{/* |
|
472 |
if( init[7]==true ) return; |
|
473 |
|
|
474 |
// for i, j <336 the six edges UR,UF,UL,UB,DR,DF are not in the |
|
475 |
// UD-slice and the index is <20160 |
|
476 |
for (short uRtoUL = 0; uRtoUL < 336; uRtoUL++) { |
|
477 |
for (short uBtoDF = 0; uBtoDF < 336; uBtoDF++) { |
|
478 |
MergeURtoULandUBtoDF[uRtoUL][uBtoDF] = (short) CubieCube.getURtoDF(uRtoUL, uBtoDF); |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
init[7]=true; |
|
483 |
*/ |
|
484 |
if( init[7]==false ) |
|
354 |
{ |
|
355 |
if( !init[7] ) |
|
485 | 356 |
{ |
486 | 357 |
try |
487 | 358 |
{ |
488 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table8);
|
|
359 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table8);
|
|
489 | 360 |
is.read( MergeURtoULandUBtoDF, 0, 2*336*336); |
490 | 361 |
} |
491 | 362 |
catch(Exception ioe) |
... | ... | |
519 | 390 |
|
520 | 391 |
public static boolean initialize9(Resources res) |
521 | 392 |
{ |
522 |
|
|
523 |
/* |
|
524 |
for (int i = 0; i < N_SLICE2 * N_URFtoDLF * N_PARITY / 2; i++) |
|
525 |
Slice_URFtoDLF_Parity_Prun[i] = -1; |
|
526 |
int depth = 0; |
|
527 |
setPruning(Slice_URFtoDLF_Parity_Prun, 0, (byte) 0); |
|
528 |
int done = 1; |
|
529 |
while (done != N_SLICE2 * N_URFtoDLF * N_PARITY) { |
|
530 |
for (int i = 0; i < N_SLICE2 * N_URFtoDLF * N_PARITY; i++) { |
|
531 |
int parity = i % 2; |
|
532 |
int URFtoDLF = (i / 2) / N_SLICE2; |
|
533 |
int slice = (i / 2) % N_SLICE2; |
|
534 |
if (getPruning(Slice_URFtoDLF_Parity_Prun, i) == depth) { |
|
535 |
for (int j = 0; j < 18; j++) { |
|
536 |
switch (j) { |
|
537 |
case 3: |
|
538 |
case 5: |
|
539 |
case 6: |
|
540 |
case 8: |
|
541 |
case 12: |
|
542 |
case 14: |
|
543 |
case 15: |
|
544 |
case 17: |
|
545 |
continue; |
|
546 |
default: |
|
547 |
int newSlice = FRtoBR_Move[slice][j]; |
|
548 |
int newURFtoDLF = URFtoDLF_Move[URFtoDLF][j]; |
|
549 |
int newParity = parityMove[parity][j]; |
|
550 |
if (getPruning(Slice_URFtoDLF_Parity_Prun, (N_SLICE2 * newURFtoDLF + newSlice) * 2 + newParity) == 0x0f) { |
|
551 |
setPruning(Slice_URFtoDLF_Parity_Prun, (N_SLICE2 * newURFtoDLF + newSlice) * 2 + newParity, |
|
552 |
(byte) (depth + 1)); |
|
553 |
done++; |
|
554 |
} |
|
555 |
} |
|
556 |
} |
|
557 |
} |
|
558 |
} |
|
559 |
depth++; |
|
560 |
} |
|
561 |
*/ |
|
562 |
|
|
563 |
if( init[8]==false ) |
|
393 |
if( !init[8] ) |
|
564 | 394 |
{ |
565 | 395 |
try |
566 | 396 |
{ |
567 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table9);
|
|
397 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table9);
|
|
568 | 398 |
is.read( Slice_URFtoDLF_Parity_Prun, 0, N_SLICE2 * N_URFtoDLF * N_PARITY / 2); |
569 | 399 |
} |
570 | 400 |
catch(Exception ioe) |
... | ... | |
576 | 406 |
init[8]=true; |
577 | 407 |
} |
578 | 408 |
|
579 |
return true;
|
|
409 |
return true; |
|
580 | 410 |
} |
581 | 411 |
|
582 | 412 |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
... | ... | |
585 | 415 |
public static byte[] Slice_URtoDF_Parity_Prun = new byte[N_SLICE2 * N_URtoDF * N_PARITY / 2]; |
586 | 416 |
|
587 | 417 |
public static boolean initialize10(Resources res) |
588 |
{/* |
|
589 |
if( init[9]==true ) return; |
|
590 |
|
|
591 |
for (int i = 0; i < N_SLICE2 * N_URtoDF * N_PARITY / 2; i++) |
|
592 |
Slice_URtoDF_Parity_Prun[i] = -1; |
|
593 |
int depth = 0; |
|
594 |
setPruning(Slice_URtoDF_Parity_Prun, 0, (byte) 0); |
|
595 |
int done = 1; |
|
596 |
while (done != N_SLICE2 * N_URtoDF * N_PARITY) { |
|
597 |
for (int i = 0; i < N_SLICE2 * N_URtoDF * N_PARITY; i++) { |
|
598 |
int parity = i % 2; |
|
599 |
int URtoDF = (i / 2) / N_SLICE2; |
|
600 |
int slice = (i / 2) % N_SLICE2; |
|
601 |
if (getPruning(Slice_URtoDF_Parity_Prun, i) == depth) { |
|
602 |
for (int j = 0; j < 18; j++) { |
|
603 |
switch (j) { |
|
604 |
case 3: |
|
605 |
case 5: |
|
606 |
case 6: |
|
607 |
case 8: |
|
608 |
case 12: |
|
609 |
case 14: |
|
610 |
case 15: |
|
611 |
case 17: |
|
612 |
continue; |
|
613 |
default: |
|
614 |
int newSlice = FRtoBR_Move[slice][j]; |
|
615 |
int newURtoDF = URtoDF_Move[URtoDF][j]; |
|
616 |
int newParity = parityMove[parity][j]; |
|
617 |
if (getPruning(Slice_URtoDF_Parity_Prun, (N_SLICE2 * newURtoDF + newSlice) * 2 + newParity) == 0x0f) { |
|
618 |
setPruning(Slice_URtoDF_Parity_Prun, (N_SLICE2 * newURtoDF + newSlice) * 2 + newParity, |
|
619 |
(byte) (depth + 1)); |
|
620 |
done++; |
|
621 |
} |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
625 |
} |
|
626 |
depth++; |
|
627 |
} |
|
628 |
|
|
629 |
init[9]=true; |
|
630 |
*/ |
|
631 |
|
|
632 |
if( init[9]==false ) |
|
418 |
{ |
|
419 |
if( !init[9] ) |
|
633 | 420 |
{ |
634 | 421 |
try |
635 | 422 |
{ |
636 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table10);
|
|
423 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table10);
|
|
637 | 424 |
is.read( Slice_URtoDF_Parity_Prun, 0, N_SLICE2 * N_URtoDF * N_PARITY / 2); |
638 | 425 |
} |
639 | 426 |
catch(Exception ioe) |
... | ... | |
654 | 441 |
public static byte[] Slice_Twist_Prun = new byte[N_SLICE1 * N_TWIST / 2 + 1]; |
655 | 442 |
|
656 | 443 |
public static boolean initialize11(Resources res) |
657 |
{/* |
|
658 |
if( init[10]==true ) return; |
|
659 |
|
|
660 |
for (int i = 0; i < N_SLICE1 * N_TWIST / 2 + 1; i++) |
|
661 |
Slice_Twist_Prun[i] = -1; |
|
662 |
int depth = 0; |
|
663 |
setPruning(Slice_Twist_Prun, 0, (byte) 0); |
|
664 |
int done = 1; |
|
665 |
while (done != N_SLICE1 * N_TWIST) { |
|
666 |
for (int i = 0; i < N_SLICE1 * N_TWIST; i++) { |
|
667 |
int twist = i / N_SLICE1, slice = i % N_SLICE1; |
|
668 |
if (getPruning(Slice_Twist_Prun, i) == depth) { |
|
669 |
for (int j = 0; j < 18; j++) { |
|
670 |
int newSlice = FRtoBR_Move[slice * 24][j] / 24; |
|
671 |
int newTwist = twistMove[twist][j]; |
|
672 |
if (getPruning(Slice_Twist_Prun, N_SLICE1 * newTwist + newSlice) == 0x0f) { |
|
673 |
setPruning(Slice_Twist_Prun, N_SLICE1 * newTwist + newSlice, (byte) (depth + 1)); |
|
674 |
done++; |
|
675 |
} |
|
676 |
} |
|
677 |
} |
|
678 |
} |
|
679 |
depth++; |
|
680 |
} |
|
681 |
|
|
682 |
init[10]=true; |
|
683 |
*/ |
|
684 |
if( init[10]==false ) |
|
444 |
{ |
|
445 |
if( !init[10] ) |
|
685 | 446 |
{ |
686 | 447 |
try |
687 | 448 |
{ |
688 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table11);
|
|
449 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table11);
|
|
689 | 450 |
is.read( Slice_Twist_Prun, 0, N_SLICE1 * N_TWIST / 2 + 1); |
690 | 451 |
} |
691 | 452 |
catch(Exception ioe) |
... | ... | |
706 | 467 |
public static byte[] Slice_Flip_Prun = new byte[N_SLICE1 * N_FLIP / 2]; |
707 | 468 |
|
708 | 469 |
public static boolean initialize12(Resources res) |
709 |
{/* |
|
710 |
if( init[11]==true ) return; |
|
711 |
|
|
712 |
for (int i = 0; i < N_SLICE1 * N_FLIP / 2; i++) |
|
713 |
Slice_Flip_Prun[i] = -1; |
|
714 |
int depth = 0; |
|
715 |
setPruning(Slice_Flip_Prun, 0, (byte) 0); |
|
716 |
int done = 1; |
|
717 |
while (done != N_SLICE1 * N_FLIP) { |
|
718 |
for (int i = 0; i < N_SLICE1 * N_FLIP; i++) { |
|
719 |
int flip = i / N_SLICE1, slice = i % N_SLICE1; |
|
720 |
if (getPruning(Slice_Flip_Prun, i) == depth) { |
|
721 |
for (int j = 0; j < 18; j++) { |
|
722 |
int newSlice = FRtoBR_Move[slice * 24][j] / 24; |
|
723 |
int newFlip = flipMove[flip][j]; |
|
724 |
if (getPruning(Slice_Flip_Prun, N_SLICE1 * newFlip + newSlice) == 0x0f) { |
|
725 |
setPruning(Slice_Flip_Prun, N_SLICE1 * newFlip + newSlice, (byte) (depth + 1)); |
|
726 |
done++; |
|
727 |
} |
|
728 |
} |
|
729 |
} |
|
730 |
} |
|
731 |
depth++; |
|
732 |
} |
|
733 |
|
|
734 |
init[11]=true; |
|
735 |
*/ |
|
736 |
if( init[11]==false ) |
|
470 |
{ |
|
471 |
if( !init[11] ) |
|
737 | 472 |
{ |
738 | 473 |
try |
739 | 474 |
{ |
740 |
InputStream is = res.openRawResource(com.threedcell.rubik.R.raw.table12);
|
|
475 |
InputStream is = res.openRawResource(org.distorted.main.R.raw.cube3solver_table12);
|
|
741 | 476 |
is.read( Slice_Flip_Prun, 0, N_SLICE1 * N_FLIP / 2); |
742 | 477 |
} |
743 | 478 |
catch(Exception ioe) |
Also available in: Unified diff
More support for the 3x3x3 Solver: more of the actual 3x3x3 solver mechanism.