Revision 4c737817
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
465 | 465 |
return layer==0 ? ran : numLayers-1-ran; |
466 | 466 |
} |
467 | 467 |
|
468 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
469 |
|
|
470 |
private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom) |
|
471 |
{ |
|
472 |
return OPPOSITE_ROWS[oldAxis][newAxis]^(oldRow<nom); |
|
473 |
} |
|
474 |
|
|
468 | 475 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
469 | 476 |
|
470 | 477 |
private int retNewRotationIndex(Random rnd, int nom, int[] oldRot) |
... | ... | |
476 | 483 |
if( ax!=oldRot[0] ) |
477 | 484 |
{ |
478 | 485 |
mPossibleAxis[index] = ax; |
479 |
boolean low = OPPOSITE_ROWS[oldRot[0]][ax]^(oldRot[1]<nom); |
|
480 |
mPossibleLayers[index] = low ? 0:1; |
|
486 |
mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1; |
|
481 | 487 |
int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]; |
482 | 488 |
if( tmp>max ) max=tmp; |
483 | 489 |
index++; |
... | ... | |
490 | 496 |
mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]); |
491 | 497 |
} |
492 | 498 |
|
493 |
float random= rnd.nextFloat(); |
|
494 |
int total = mNumOccurences[NUM_AXIS-2]; |
|
499 |
float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2]; |
|
495 | 500 |
|
496 | 501 |
for(int ax=0; ax<NUM_AXIS-1; ax++) |
497 | 502 |
{ |
498 |
if( random*total <= mNumOccurences[ax] )
|
|
503 |
if( random <= mNumOccurences[ax] ) |
|
499 | 504 |
{ |
500 | 505 |
index=ax; |
501 | 506 |
break; |
... | ... | |
514 | 519 |
{ |
515 | 520 |
int numLayers = getNumLayers(); |
516 | 521 |
int nom = (numLayers-1)/2; |
517 |
int row = rnd.nextInt(nom); |
|
518 | 522 |
|
519 | 523 |
if( curr==0 ) |
520 | 524 |
{ |
521 | 525 |
int lf = rnd.nextInt(2); |
526 |
int row= rnd.nextInt(nom); |
|
522 | 527 |
scramble[curr][0] = rnd.nextInt(NUM_AXIS); |
523 | 528 |
scramble[curr][1] = (lf==0 ? row : numLayers-1-row); |
524 | 529 |
initializeScrambleTable(scramble[curr],numLayers); |
src/main/java/org/distorted/objects/TwistyRedi.java | ||
---|---|---|
205 | 205 |
|
206 | 206 |
private static int[][] mScrambleTable; |
207 | 207 |
private static int[] mPossibleAxis, mPossibleLayers; |
208 |
private static int[] mNumOccurences; |
|
208 | 209 |
|
209 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
210 | 211 |
|
... | ... | |
429 | 430 |
if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2]; |
430 | 431 |
if( mPossibleAxis ==null ) mPossibleAxis = new int[NUM_AXIS-1]; |
431 | 432 |
if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1]; |
433 |
if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1]; |
|
432 | 434 |
|
433 | 435 |
for(int i=0; i<NUM_AXIS; i++) |
434 | 436 |
for(int j=0; j<2; j++) |
... | ... | |
441 | 443 |
|
442 | 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
443 | 445 |
|
444 |
private int retNewRotationIndex(Random rnd, int[] oldRot) |
|
446 |
private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom) |
|
447 |
{ |
|
448 |
return (oldAxis+newAxis==3)^(oldRow<nom); |
|
449 |
} |
|
450 |
|
|
451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
452 |
|
|
453 |
private int retNewRotationIndex(Random rnd, int nom, int[] oldRot) |
|
445 | 454 |
{ |
446 | 455 |
int index=0, max=0; |
447 | 456 |
|
... | ... | |
450 | 459 |
if( ax!=oldRot[0] ) |
451 | 460 |
{ |
452 | 461 |
mPossibleAxis[index] = ax; |
453 |
mPossibleLayers[index] = oldRot[0]+ax==3 ? 1-oldRot[1]/2 : oldRot[1]/2;
|
|
462 |
mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1;
|
|
454 | 463 |
int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]; |
455 | 464 |
if( tmp>max ) max=tmp; |
456 | 465 |
index++; |
457 | 466 |
} |
458 | 467 |
} |
459 | 468 |
|
460 |
int a0 = max-mScrambleTable[mPossibleAxis[0]][mPossibleLayers[0]]; |
|
461 |
int a1 = max-mScrambleTable[mPossibleAxis[1]][mPossibleLayers[1]]; |
|
462 |
int a2 = max-mScrambleTable[mPossibleAxis[2]][mPossibleLayers[2]]; |
|
469 |
for(int ax=0; ax<NUM_AXIS-1; ax++) |
|
470 |
{ |
|
471 |
int value = mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]]; |
|
472 |
mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]); |
|
473 |
} |
|
463 | 474 |
|
464 |
float total = a0+a1+a2; |
|
465 |
float random= rnd.nextFloat(); |
|
475 |
float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2]; |
|
466 | 476 |
|
467 |
if( random*total < a0 ) index=0; |
|
468 |
else if( random*total < a0+a1 ) index=1; |
|
469 |
else index=2; |
|
477 |
for(int ax=0; ax<NUM_AXIS-1; ax++) |
|
478 |
{ |
|
479 |
if( random <= mNumOccurences[ax] ) |
|
480 |
{ |
|
481 |
index=ax; |
|
482 |
break; |
|
483 |
} |
|
484 |
} |
|
470 | 485 |
|
471 | 486 |
mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++; |
472 | 487 |
|
... | ... | |
474 | 489 |
} |
475 | 490 |
|
476 | 491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
492 |
// PUBLIC API |
|
477 | 493 |
|
478 | 494 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total) |
479 | 495 |
{ |
... | ... | |
485 | 501 |
} |
486 | 502 |
else |
487 | 503 |
{ |
488 |
int index = retNewRotationIndex(rnd,scramble[curr-1]); |
|
504 |
int index = retNewRotationIndex(rnd,1,scramble[curr-1]);
|
|
489 | 505 |
scramble[curr][0] = mPossibleAxis[index]; |
490 | 506 |
scramble[curr][1] = 2*mPossibleLayers[index]; |
491 | 507 |
} |
Also available in: Unified diff
Minor.