Revision 1d581993
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java | ||
---|---|---|
22 | 22 |
import java.util.ArrayList; |
23 | 23 |
import java.util.Random; |
24 | 24 |
|
25 |
import org.distorted.objectlib.helpers.ObjectSignature; |
|
26 |
|
|
25 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 28 |
|
27 | 29 |
public class ObjectScrambler |
... | ... | |
52 | 54 |
private int[][] mQuatMult; |
53 | 55 |
|
54 | 56 |
// type=2 , i.e. locally created bandaged cuboids |
55 |
private static long mSignature;
|
|
57 |
private static ObjectSignature mSignature;
|
|
56 | 58 |
private ArrayList<ScrambleStateBandagedCuboid> mBandagedStates; |
59 |
private int[] mSize, mTurns; |
|
57 | 60 |
|
58 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 62 |
|
... | ... | |
70 | 73 |
mCornerQuat = new int[8]; |
71 | 74 |
mLastRot = LAST_SL; |
72 | 75 |
} |
76 |
if( mType==2 ) |
|
77 |
{ |
|
78 |
mSize = new int[3]; |
|
79 |
mTurns= new int[3]; |
|
80 |
|
|
81 |
mSize[0] = (mNumLayers[0]>1 ? mNumLayers[0] : 0); |
|
82 |
mSize[1] = (mNumLayers[1]>1 ? mNumLayers[1] : 0); |
|
83 |
mSize[2] = (mNumLayers[2]>1 ? mNumLayers[2] : 0); |
|
84 |
|
|
85 |
mTurns[0] = mNumLayers[1]==mNumLayers[2] ? 3:1; |
|
86 |
mTurns[1] = mNumLayers[0]==mNumLayers[2] ? 3:1; |
|
87 |
mTurns[2] = mNumLayers[0]==mNumLayers[1] ? 3:1; |
|
88 |
} |
|
73 | 89 |
} |
74 | 90 |
|
75 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
405 | 421 |
} |
406 | 422 |
} |
407 | 423 |
|
424 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
425 |
// TYPE 2 |
|
426 |
|
|
427 |
private void fillOutScramble(int[] scramble, int moveIndex) |
|
428 |
{ |
|
429 |
for(int axis=0; axis<3; axis++) |
|
430 |
{ |
|
431 |
int size = mTurns[axis]*mSize[axis]; |
|
432 |
|
|
433 |
if( moveIndex<size ) |
|
434 |
{ |
|
435 |
scramble[0] = axis; |
|
436 |
scramble[1] = moveIndex/mTurns[axis]; |
|
437 |
|
|
438 |
if( mTurns[axis]==3 ) |
|
439 |
{ |
|
440 |
switch(moveIndex%3) |
|
441 |
{ |
|
442 |
case 0: scramble[2] = -1; break; |
|
443 |
case 1: scramble[2] = 2; break; |
|
444 |
case 2: scramble[2] = 1; break; |
|
445 |
} |
|
446 |
} |
|
447 |
else scramble[2] = 1; |
|
448 |
return; |
|
449 |
} |
|
450 |
|
|
451 |
moveIndex -= size; |
|
452 |
} |
|
453 |
|
|
454 |
android.util.Log.e("D", "ERROR in fillOutScramble moveIndex="+moveIndex); |
|
455 |
} |
|
456 |
|
|
408 | 457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
409 | 458 |
// TYPE 2 |
410 | 459 |
|
... | ... | |
431 | 480 |
int randMove = rnd.nextInt(numMoves); |
432 | 481 |
int moveIndex = currState.getNthMove(randMove,indexExcluded); |
433 | 482 |
mSignature = currState.getMove(moveIndex); |
434 |
|
|
435 |
scramble[curr][0] = moveIndex/9; |
|
436 |
scramble[curr][1] = (moveIndex%9)/3; |
|
437 |
|
|
438 |
switch(moveIndex%3) |
|
439 |
{ |
|
440 |
case 0: scramble[curr][2] = -1; break; |
|
441 |
case 1: scramble[curr][2] = 2; break; |
|
442 |
case 2: scramble[curr][2] = 1; break; |
|
443 |
} |
|
483 |
fillOutScramble(scramble[curr],moveIndex); |
|
444 | 484 |
} |
445 | 485 |
|
446 |
ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mSignature); |
|
486 |
ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
|
|
447 | 487 |
mBandagedStates.add(nextState); |
448 | 488 |
} |
449 | 489 |
|
... | ... | |
462 | 502 |
{ |
463 | 503 |
mBandagedStates.remove(curr); |
464 | 504 |
ScrambleStateBandagedCuboid prevState = mBandagedStates.get(curr-1); |
465 |
long signature = currState.getID();
|
|
505 |
ObjectSignature signature = currState.getSignature();
|
|
466 | 506 |
prevState.removeMoves(signature); |
467 | 507 |
boolean result = buildMove(scramble,rnd,curr-1); |
468 | 508 |
if( !result ) return false; |
... | ... | |
479 | 519 |
int randMove = rnd.nextInt(numMoves); |
480 | 520 |
int moveIndex = currState.getNthMove(randMove,indexExcluded); |
481 | 521 |
mSignature = currState.getMove(moveIndex); |
522 |
fillOutScramble(scramble[curr],moveIndex); |
|
482 | 523 |
|
483 |
scramble[curr][0] = moveIndex/9; |
|
484 |
scramble[curr][1] = (moveIndex%9)/3; |
|
485 |
|
|
486 |
switch(moveIndex%3) |
|
487 |
{ |
|
488 |
case 0: scramble[curr][2] = -1; break; |
|
489 |
case 1: scramble[curr][2] = 2; break; |
|
490 |
case 2: scramble[curr][2] = 1; break; |
|
491 |
} |
|
492 |
|
|
493 |
ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mSignature); |
|
524 |
ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature); |
|
494 | 525 |
mBandagedStates.add(nextState); |
495 | 526 |
|
496 | 527 |
return true; |
... | ... | |
504 | 535 |
if( mBandagedStates==null ) mBandagedStates = new ArrayList<>(); |
505 | 536 |
else mBandagedStates.clear(); |
506 | 537 |
|
507 |
ScrambleStateBandagedCuboid state = new ScrambleStateBandagedCuboid(mSignature); |
|
538 |
ScrambleStateBandagedCuboid state = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
|
|
508 | 539 |
mBandagedStates.add(state); |
509 | 540 |
boolean success = true; |
510 | 541 |
|
... | ... | |
521 | 552 |
if( !success ) |
522 | 553 |
{ |
523 | 554 |
mBandagedStates.clear(); |
524 |
state = new ScrambleStateBandagedCuboid(mSignature); |
|
555 |
state = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
|
|
525 | 556 |
mBandagedStates.add(state); |
526 | 557 |
|
527 | 558 |
for(int curr=0; curr<total; curr++) |
... | ... | |
529 | 560 |
buildMoveForced(scramble,rnd,curr); |
530 | 561 |
} |
531 | 562 |
} |
563 |
|
|
564 |
for(int i=0; i<total; i++) |
|
565 |
{ |
|
566 |
android.util.Log.e("D", "scramble "+i+" axis: "+scramble[i][0]+" layer="+scramble[i][1]+" angle="+scramble[i][2]); |
|
567 |
} |
|
532 | 568 |
} |
533 | 569 |
|
534 | 570 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
535 | 571 |
// TYPE 2 |
536 | 572 |
|
537 |
public static void setSignature(long signature)
|
|
573 |
public static void setSignature(ObjectSignature signature)
|
|
538 | 574 |
{ |
539 | 575 |
mSignature = signature; |
540 | 576 |
} |
Also available in: Unified diff
Introduce ObjectSignature that can incorporate 192-bit signatures (for 5x5x5 bandaged cubes).
ObjectScrambler does not fully work yet.