Revision 113597af
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandaged3x3.java | ||
---|---|---|
60 | 60 |
graph.add(bsg); |
61 | 61 |
|
62 | 62 |
insertChildren(graph,id); |
63 |
pruneGraph(graph); |
|
63 |
pruneGraph(graph,id);
|
|
64 | 64 |
remapGraph(graph); |
65 | 65 |
|
66 | 66 |
int num = graph.size(); |
... | ... | |
79 | 79 |
{ |
80 | 80 |
ScrambleStateBandaged3x3 bsg = findState(list,id); |
81 | 81 |
|
82 |
android.util.Log.e("D", "inserting children of "+id); |
|
83 |
|
|
82 | 84 |
if( bsg==null ) |
83 | 85 |
{ |
84 | 86 |
android.util.Log.e("D", "error: "+id+" doesn't exist"); |
... | ... | |
99 | 101 |
list.add(tmp); |
100 | 102 |
insertChildren(list,move); |
101 | 103 |
} |
104 |
else if( tmp.mID != move ) |
|
105 |
{ |
|
106 |
android.util.Log.e("D", "id "+id+" move: "+move+" leads to already existing "+tmp.mID); |
|
107 |
bsg.setMove(i,tmp.mID); |
|
108 |
} |
|
102 | 109 |
} |
103 | 110 |
} |
104 | 111 |
} |
105 | 112 |
|
106 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
107 | 114 |
|
108 |
private static void pruneGraph(ArrayList<ScrambleStateBandaged3x3> list) |
|
115 |
private static void pruneGraph(ArrayList<ScrambleStateBandaged3x3> list, long id)
|
|
109 | 116 |
{ |
110 | 117 |
int num = list.size(); |
111 | 118 |
boolean pruned = false; |
... | ... | |
117 | 124 |
|
118 | 125 |
if( bsg.numAxis()<2 ) |
119 | 126 |
{ |
120 |
list.remove(i); |
|
127 |
long prunedID = bsg.getID(); |
|
128 |
|
|
129 |
android.util.Log.e("D", "pruning id "+prunedID+" axis: "+bsg.numAxis() ); |
|
130 |
bsg.printMoves(); |
|
131 |
|
|
132 |
if( id!=prunedID ) list.remove(i); // do not remove the starting point, even if |
|
133 |
// it does have only 1 axis |
|
121 | 134 |
pruned = true; |
122 |
remapID(list,bsg.getID(),INVALID_MOVE);
|
|
135 |
remapID(list,prunedID,INVALID_MOVE);
|
|
123 | 136 |
break; |
124 | 137 |
} |
125 | 138 |
} |
126 | 139 |
|
127 |
if( pruned ) pruneGraph(list); |
|
140 |
if( pruned ) pruneGraph(list,id); |
|
141 |
} |
|
142 |
|
|
143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
144 |
|
|
145 |
private void printMoves() |
|
146 |
{ |
|
147 |
String moves = ""; |
|
148 |
|
|
149 |
for(int i=0; i<NUM_MOVES; i++) |
|
150 |
{ |
|
151 |
moves += (" " + mMoves[i]); |
|
152 |
} |
|
153 |
|
|
154 |
android.util.Log.e("D", moves); |
|
128 | 155 |
} |
129 | 156 |
|
130 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
317 | 344 |
{ |
318 | 345 |
long x1 = turn(id,axis,layer); |
319 | 346 |
|
320 |
if( x1!=id )
|
|
347 |
if( x1!=INVALID_MOVE )
|
|
321 | 348 |
{ |
322 | 349 |
long x2 = turn(x1,axis,layer); |
323 | 350 |
long x3 = turn(x2,axis,layer); |
... | ... | |
368 | 395 |
ret[20] = turnWhole(ret[19],AXIS_X); |
369 | 396 |
ret[21] = turnWhole(ret[ 3],AXIS_Z); |
370 | 397 |
ret[22] = turnWhole(ret[21],AXIS_Z); |
398 |
/* |
|
399 |
String iso = "isometries of "+id+" :"; |
|
371 | 400 |
|
372 |
for(int i=0; i<23; i++) |
|
373 |
for(int j=i+1; j<23; j++) |
|
374 |
{ |
|
375 |
if( ret[i]==ret[j] ) android.util.Log.e("D", "error: isometries "+i+" and "+j+" the same: "+ret[i]+" id="+id); |
|
376 |
} |
|
401 |
for(int i=0; i<NUM_ISOMETRIES-1; i++) |
|
402 |
{ |
|
403 |
iso += (" " + ret[i]); |
|
404 |
} |
|
405 |
|
|
406 |
android.util.Log.e("D", iso); |
|
407 |
*/ |
|
408 |
/* |
|
409 |
long t = turnWhole(1,AXIS_X); |
|
377 | 410 |
|
411 |
android.util.Log.e("D", "1 turned along X: "+t); |
|
412 |
*/ |
|
378 | 413 |
return ret; |
379 | 414 |
} |
380 | 415 |
|
... | ... | |
442 | 477 |
{ |
443 | 478 |
case LAYER_L: if( getBit(id, 1)==1 || getBit(id, 6)==1 || getBit(id,11)==1 || |
444 | 479 |
getBit(id,22)==1 || getBit(id,27)==1 || getBit(id,32)==1 || |
445 |
getBit(id,43)==1 || getBit(id,48)==1 || getBit(id,53)==1 ) return id;
|
|
480 |
getBit(id,43)==1 || getBit(id,48)==1 || getBit(id,53)==1 ) return INVALID_MOVE;
|
|
446 | 481 |
|
447 | 482 |
long x1 = cycle(id,9,14,46,41); |
448 | 483 |
long x2 = cycle(x1,4,35,51,20); |
... | ... | |
453 | 488 |
getBit(id,43)==1 || getBit(id,48)==1 || getBit(id,53)==1 || |
454 | 489 |
getBit(id, 0)==1 || getBit(id, 5)==1 || getBit(id,10)==1 || |
455 | 490 |
getBit(id,21)==1 || getBit(id,26)==1 || getBit(id,31)==1 || |
456 |
getBit(id,42)==1 || getBit(id,47)==1 || getBit(id,52)==1 ) return id;
|
|
491 |
getBit(id,42)==1 || getBit(id,47)==1 || getBit(id,52)==1 ) return INVALID_MOVE;
|
|
457 | 492 |
|
458 | 493 |
long x4 = cycle(id,8,13,45,40); |
459 | 494 |
long x5 = cycle(x4,3,34,50,19); |
... | ... | |
461 | 496 |
|
462 | 497 |
case LAYER_R: if( getBit(id, 0)==1 || getBit(id, 5)==1 || getBit(id,10)==1 || |
463 | 498 |
getBit(id,21)==1 || getBit(id,26)==1 || getBit(id,31)==1 || |
464 |
getBit(id,42)==1 || getBit(id,47)==1 || getBit(id,52)==1 ) return id;
|
|
499 |
getBit(id,42)==1 || getBit(id,47)==1 || getBit(id,52)==1 ) return INVALID_MOVE;
|
|
465 | 500 |
|
466 | 501 |
long x7 = cycle(id,7,12,44,39); |
467 | 502 |
long x8 = cycle(x7,2,33,49,18); |
... | ... | |
472 | 507 |
{ |
473 | 508 |
case LAYER_L: if( getBit(id,12)==1 || getBit(id,13)==1 || getBit(id,14)==1 || |
474 | 509 |
getBit(id,15)==1 || getBit(id,16)==1 || getBit(id,17)==1 || |
475 |
getBit(id,18)==1 || getBit(id,19)==1 || getBit(id,20)==1 ) return id;
|
|
510 |
getBit(id,18)==1 || getBit(id,19)==1 || getBit(id,20)==1 ) return INVALID_MOVE;
|
|
476 | 511 |
|
477 | 512 |
long y1 = cycle(id,1,9,10,2); |
478 | 513 |
long y2 = cycle(y1,0,4,11,7); |
... | ... | |
483 | 518 |
getBit(id,18)==1 || getBit(id,19)==1 || getBit(id,20)==1 || |
484 | 519 |
getBit(id,33)==1 || getBit(id,34)==1 || getBit(id,35)==1 || |
485 | 520 |
getBit(id,36)==1 || getBit(id,37)==1 || getBit(id,38)==1 || |
486 |
getBit(id,39)==1 || getBit(id,40)==1 || getBit(id,41)==1 ) return id;
|
|
521 |
getBit(id,39)==1 || getBit(id,40)==1 || getBit(id,41)==1 ) return INVALID_MOVE;
|
|
487 | 522 |
|
488 | 523 |
long y4 = cycle(id,21,25,32,28); |
489 | 524 |
long y5 = cycle(y4,22,30,31,23); |
... | ... | |
491 | 526 |
|
492 | 527 |
case LAYER_R: if( getBit(id,33)==1 || getBit(id,34)==1 || getBit(id,35)==1 || |
493 | 528 |
getBit(id,36)==1 || getBit(id,37)==1 || getBit(id,38)==1 || |
494 |
getBit(id,39)==1 || getBit(id,40)==1 || getBit(id,41)==1 ) return id;
|
|
529 |
getBit(id,39)==1 || getBit(id,40)==1 || getBit(id,41)==1 ) return INVALID_MOVE;
|
|
495 | 530 |
|
496 | 531 |
long y7 = cycle(id,42,46,53,49); |
497 | 532 |
long y8 = cycle(y7,43,51,52,44); |
... | ... | |
502 | 537 |
{ |
503 | 538 |
case LAYER_L: if( getBit(id, 7)==1 || getBit(id, 8)==1 || getBit(id, 9)==1 || |
504 | 539 |
getBit(id,28)==1 || getBit(id,29)==1 || getBit(id,30)==1 || |
505 |
getBit(id,49)==1 || getBit(id,50)==1 || getBit(id,51)==1 ) return id;
|
|
540 |
getBit(id,49)==1 || getBit(id,50)==1 || getBit(id,51)==1 ) return INVALID_MOVE;
|
|
506 | 541 |
|
507 | 542 |
long z1 = cycle(id,10,20,53,39); |
508 | 543 |
long z2 = cycle(z1,11,41,52,18); |
... | ... | |
513 | 548 |
getBit(id,49)==1 || getBit(id,50)==1 || getBit(id,51)==1 || |
514 | 549 |
getBit(id, 2)==1 || getBit(id, 3)==1 || getBit(id, 4)==1 || |
515 | 550 |
getBit(id,23)==1 || getBit(id,24)==1 || getBit(id,25)==1 || |
516 |
getBit(id,44)==1 || getBit(id,45)==1 || getBit(id,46)==1 ) return id;
|
|
551 |
getBit(id,44)==1 || getBit(id,45)==1 || getBit(id,46)==1 ) return INVALID_MOVE;
|
|
517 | 552 |
|
518 | 553 |
long z4 = cycle(id,5,17,48,36); |
519 | 554 |
long z5 = cycle(z4,6,38,47,15); |
... | ... | |
521 | 556 |
|
522 | 557 |
case LAYER_R: if( getBit(id, 2)==1 || getBit(id, 3)==1 || getBit(id, 4)==1 || |
523 | 558 |
getBit(id,23)==1 || getBit(id,24)==1 || getBit(id,25)==1 || |
524 |
getBit(id,44)==1 || getBit(id,45)==1 || getBit(id,46)==1 ) return id;
|
|
559 |
getBit(id,44)==1 || getBit(id,45)==1 || getBit(id,46)==1 ) return INVALID_MOVE;
|
|
525 | 560 |
|
526 | 561 |
long z7 = cycle(id,0,14,43,33); |
527 | 562 |
long z8 = cycle(z7,1,35,42,12); |
... | ... | |
548 | 583 |
|
549 | 584 |
long x7 = cycle(x6,7,12,44,39); // |
550 | 585 |
long x8 = cycle(x7,2,33,49,18); // right layer |
551 |
return cycle(x8,15,23,36,28);// |
|
586 |
long x9 = cycle(x8,15,23,36,28);// |
|
587 |
|
|
588 |
long x10= cycle(x9,1,43,53,11); // |
|
589 |
long x11= cycle(x10,6,22,48,32);// left lock |
|
590 |
long x12= cycle(x11,0,42,52,10);// |
|
591 |
return cycle(x12,5,21,47,31);// right lock |
|
552 | 592 |
|
553 | 593 |
case AXIS_Y: long y1 = cycle(id,1,9,10,2); // |
554 |
long y2 = cycle(y1,0,4,11,7); // left layer
|
|
594 |
long y2 = cycle(y1,0,4,11,7); // bottom layer
|
|
555 | 595 |
long y3 = cycle(y2,3,6,8,5); // |
556 | 596 |
|
557 | 597 |
long y4 = cycle(y3,21,25,32,28);// |
... | ... | |
559 | 599 |
long y6 = cycle(y5,24,27,29,26);// |
560 | 600 |
|
561 | 601 |
long y7 = cycle(y6,42,46,53,49);// |
562 |
long y8 = cycle(y7,43,51,52,44);// right layer |
|
563 |
return cycle(y8,45,48,50,47);// |
|
602 |
long y8 = cycle(y7,43,51,52,44);// top layer |
|
603 |
long y9 = cycle(y8,45,48,50,47);// |
|
604 |
|
|
605 |
long y10= cycle(y9,12,14,20,18); // |
|
606 |
long y11= cycle(y10,13,17,19,15);// bottom lock |
|
607 |
long y12= cycle(y11,33,35,41,39);// |
|
608 |
return cycle(y12,34,38,40,36);// top lock |
|
564 | 609 |
|
565 | 610 |
case AXIS_Z: long z1 = cycle(id,10,20,53,39);// |
566 |
long z2 = cycle(z1,11,41,52,18);// left layer
|
|
611 |
long z2 = cycle(z1,11,41,52,18);// back layer
|
|
567 | 612 |
long z3 = cycle(z2,19,32,40,31);// |
568 | 613 |
|
569 | 614 |
long z4 = cycle(z3,5,17,48,36); // |
... | ... | |
571 | 616 |
long z6 = cycle(z5,16,27,37,26);// |
572 | 617 |
|
573 | 618 |
long z7 = cycle(z6,0,14,43,33); // |
574 |
long z8 = cycle(z7,1,35,42,12); // right layer |
|
575 |
return cycle(z8,13,22,34,21);// |
|
619 |
long z8 = cycle(z7,1,35,42,12); // front layer |
|
620 |
long z9 = cycle(z8,13,22,34,21);// |
|
621 |
|
|
622 |
long z10= cycle(z9,7,9,51,49); // |
|
623 |
long z11= cycle(z10,8,30,50,28);// back lock |
|
624 |
long z12= cycle(z11,2,4,46,44); // |
|
625 |
return cycle(z12,3,25,45,23);// front lock |
|
576 | 626 |
} |
577 | 627 |
|
578 | 628 |
return 0; |
... | ... | |
594 | 644 |
return setBit(i3,b1,bit4); |
595 | 645 |
} |
596 | 646 |
|
647 |
|
|
648 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
649 |
// bit b1 in place of b2 etc. |
|
650 |
|
|
651 |
private static long cyclePriv(long id, int b1, int b2, int b3, int b4) |
|
652 |
{ |
|
653 |
long bit1 = getBit(id,b1); |
|
654 |
long bit2 = getBit(id,b2); |
|
655 |
long bit3 = getBit(id,b3); |
|
656 |
long bit4 = getBit(id,b4); |
|
657 |
|
|
658 |
android.util.Log.e("D", "bit1="+bit1+" bit2="+bit2+" bit3="+bit3+" bit4="+bit4); |
|
659 |
|
|
660 |
long i1 = setBitPriv(id,b2,bit1); |
|
661 |
long i2 = setBitPriv(i1,b3,bit2); |
|
662 |
long i3 = setBitPriv(i2,b4,bit3); |
|
663 |
long i4 = setBitPriv(i3,b1,bit4); |
|
664 |
|
|
665 |
|
|
666 |
android.util.Log.e("D", "i1="+i1+" i2="+i2+" i3="+i3+" i4="+i4); |
|
667 |
|
|
668 |
return i4; |
|
669 |
} |
|
670 |
|
|
671 |
|
|
672 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
673 |
|
|
674 |
private static long setBitPriv(long id, int bit, long value) |
|
675 |
{ |
|
676 |
long old = getBit(id,bit); |
|
677 |
|
|
678 |
if( old!=value ) |
|
679 |
{ |
|
680 |
long diff = (1L<<bit); |
|
681 |
id += (value==0 ? -diff : diff); |
|
682 |
} |
|
683 |
|
|
684 |
android.util.Log.e("D", "setBit: id: "+id+" bit="+bit+" value="+value+" old="+old+" ret="+id); |
|
685 |
|
|
686 |
return id; |
|
687 |
} |
|
597 | 688 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
598 | 689 |
|
599 | 690 |
private static long getBit(long id, int bit) |
... | ... | |
609 | 700 |
|
610 | 701 |
if( old!=value ) |
611 | 702 |
{ |
612 |
long diff = (1<<bit); |
|
703 |
long diff = (1L<<bit);
|
|
613 | 704 |
id += (value==0 ? -diff : diff); |
614 | 705 |
} |
615 | 706 |
|
Also available in: Unified diff
Generalized ScrambleState generator: bugfixes