23 |
23 |
|
24 |
24 |
import org.distorted.helpers.ObjectShape;
|
25 |
25 |
import org.distorted.helpers.ObjectSticker;
|
|
26 |
import org.distorted.helpers.ScrambleState;
|
26 |
27 |
import org.distorted.library.main.DistortedEffects;
|
27 |
28 |
import org.distorted.library.main.DistortedTexture;
|
28 |
29 |
import org.distorted.library.mesh.MeshSquare;
|
... | ... | |
185 |
186 |
{ -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
|
186 |
187 |
};
|
187 |
188 |
|
188 |
|
private static int[][] mScrambleTable;
|
189 |
|
private static int[] mPossibleAxis, mPossibleLayers;
|
190 |
|
private static int[] mNumOccurences;
|
191 |
|
|
192 |
189 |
private static final ObjectSticker[] mStickers;
|
193 |
190 |
|
194 |
191 |
static
|
... | ... | |
205 |
202 |
}
|
206 |
203 |
}
|
207 |
204 |
|
|
205 |
private int mCurrState;
|
|
206 |
private int mIndexExcluded;
|
|
207 |
private final ScrambleState[] mStates;
|
|
208 |
private int[][] mScrambleTable;
|
|
209 |
private int[] mNumOccurences;
|
|
210 |
|
208 |
211 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209 |
212 |
|
210 |
213 |
TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
211 |
214 |
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
212 |
215 |
{
|
213 |
216 |
super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
|
|
217 |
|
|
218 |
mStates = new ScrambleState[]
|
|
219 |
{
|
|
220 |
new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
|
|
221 |
new ScrambleState( new int[][] { { },{0,1,3,0,-1,3 },{0,1,5,0,-1,5, },{ 2,1,8,2,-1,8} } ),
|
|
222 |
new ScrambleState( new int[][] { { },{ 2,1,4,2,-1,4},{ 2,1,6,2,-1,6},{0,1,7,0,-1,7 } } ),
|
|
223 |
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ },{ 2,1,6,2,-1,6},{0,1,7,0,-1,7 } } ),
|
|
224 |
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{ },{0,1,5,0,-1,5, },{ 2,1,8,2,-1,8} } ),
|
|
225 |
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ 2,1,4,2,-1,4},{ },{0,1,7,0,-1,7 } } ),
|
|
226 |
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{0,1,3,0,-1,3 },{ },{ 2,1,8,2,-1,8} } ),
|
|
227 |
new ScrambleState( new int[][] { { 2,1,2,2,-1,2},{0,1,3,0,-1,3 },{0,1,5,0,-1,5, },{ } } ),
|
|
228 |
new ScrambleState( new int[][] { {0,1,1,0,-1,1 },{ 2,1,4,2,-1,4},{ 2,1,6,2,-1,6},{ } } ),
|
|
229 |
};
|
214 |
230 |
}
|
215 |
231 |
|
216 |
232 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
388 |
404 |
return 2.0f;
|
389 |
405 |
}
|
390 |
406 |
|
391 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
392 |
|
// PUBLIC API
|
393 |
|
|
394 |
|
public Static3D[] getRotationAxis()
|
395 |
|
{
|
396 |
|
return ROT_AXIS;
|
397 |
|
}
|
398 |
|
|
399 |
407 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
400 |
408 |
|
401 |
|
public int[] getBasicAngle()
|
|
409 |
private void initializeScrambling()
|
402 |
410 |
{
|
403 |
|
return BASIC_ANGLE;
|
404 |
|
}
|
405 |
|
|
406 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
411 |
int numLayers = getNumLayers();
|
407 |
412 |
|
408 |
|
private void initializeScrambleTable(int[] first)
|
409 |
|
{
|
410 |
|
if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2];
|
411 |
|
if( mPossibleAxis ==null ) mPossibleAxis = new int[NUM_AXIS-1];
|
412 |
|
if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1];
|
413 |
|
if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1];
|
|
413 |
if( mScrambleTable ==null )
|
|
414 |
{
|
|
415 |
mScrambleTable = new int[NUM_AXIS][numLayers];
|
|
416 |
}
|
|
417 |
if( mNumOccurences ==null )
|
|
418 |
{
|
|
419 |
int max=0;
|
414 |
420 |
|
415 |
|
for(int i=0; i<NUM_AXIS; i++)
|
416 |
|
for(int j=0; j<2; j++)
|
|
421 |
for (ScrambleState mState : mStates)
|
417 |
422 |
{
|
418 |
|
mScrambleTable[i][j] = 0;
|
|
423 |
int tmp = mState.getTotal(-1);
|
|
424 |
if (max < tmp) max = tmp;
|
419 |
425 |
}
|
420 |
426 |
|
421 |
|
mScrambleTable[first[0]][first[1]/2] = 1;
|
422 |
|
}
|
423 |
|
|
424 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
427 |
mNumOccurences = new int[max];
|
|
428 |
}
|
425 |
429 |
|
426 |
|
private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom)
|
427 |
|
{
|
428 |
|
return (oldAxis+newAxis==3)^(oldRow<nom);
|
|
430 |
for(int i=0; i<NUM_AXIS; i++)
|
|
431 |
for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
|
429 |
432 |
}
|
430 |
433 |
|
431 |
434 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
435 |
// PUBLIC API
|
432 |
436 |
|
433 |
|
private int retNewRotationIndex(Random rnd, int nom, int[] oldRot)
|
|
437 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
434 |
438 |
{
|
435 |
|
int index=0, max=0;
|
436 |
|
|
437 |
|
for(int ax=0; ax<NUM_AXIS; ax++)
|
|
439 |
if( curr==0 )
|
438 |
440 |
{
|
439 |
|
if( ax!=oldRot[0] )
|
440 |
|
{
|
441 |
|
mPossibleAxis[index] = ax;
|
442 |
|
mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1;
|
443 |
|
int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]];
|
444 |
|
if( tmp>max ) max=tmp;
|
445 |
|
index++;
|
446 |
|
}
|
|
441 |
mCurrState = 0;
|
|
442 |
mIndexExcluded =-1;
|
|
443 |
initializeScrambling();
|
447 |
444 |
}
|
448 |
445 |
|
449 |
|
for(int ax=0; ax<NUM_AXIS-1; ax++)
|
450 |
|
{
|
451 |
|
int value = mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]];
|
452 |
|
mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]);
|
453 |
|
}
|
|
446 |
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
|
454 |
447 |
|
455 |
|
float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2];
|
|
448 |
scramble[curr][0] = info[0];
|
|
449 |
scramble[curr][1] = info[1];
|
|
450 |
scramble[curr][2] = info[2];
|
456 |
451 |
|
457 |
|
for(int ax=0; ax<NUM_AXIS-1; ax++)
|
458 |
|
{
|
459 |
|
if( random <= mNumOccurences[ax] )
|
460 |
|
{
|
461 |
|
index=ax;
|
462 |
|
break;
|
463 |
|
}
|
464 |
|
}
|
|
452 |
mCurrState = info[3];
|
|
453 |
mIndexExcluded = info[0];
|
|
454 |
}
|
465 |
455 |
|
466 |
|
mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++;
|
|
456 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
467 |
457 |
|
468 |
|
return index;
|
|
458 |
public Static3D[] getRotationAxis()
|
|
459 |
{
|
|
460 |
return ROT_AXIS;
|
469 |
461 |
}
|
470 |
462 |
|
471 |
463 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
472 |
|
// PUBLIC API
|
473 |
464 |
|
474 |
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
|
465 |
public int[] getBasicAngle()
|
475 |
466 |
{
|
476 |
|
if( curr==0 )
|
477 |
|
{
|
478 |
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
479 |
|
scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0:2;
|
480 |
|
initializeScrambleTable(scramble[curr]);
|
481 |
|
}
|
482 |
|
else
|
483 |
|
{
|
484 |
|
int index = retNewRotationIndex(rnd,1,scramble[curr-1]);
|
485 |
|
scramble[curr][0] = mPossibleAxis[index];
|
486 |
|
scramble[curr][1] = 2*mPossibleLayers[index];
|
487 |
|
}
|
488 |
|
|
489 |
|
switch( rnd.nextInt(2) )
|
490 |
|
{
|
491 |
|
case 0: scramble[curr][2] = -1; break;
|
492 |
|
case 1: scramble[curr][2] = 1; break;
|
493 |
|
}
|
|
467 |
return BASIC_ANGLE;
|
494 |
468 |
}
|
495 |
469 |
|
496 |
470 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Convert the Redi to the new scrambling paradigm.