Revision aa26ba7f
Added by Leszek Koltunski about 4 years ago
| src/main/java/org/distorted/objects/TwistyMinx.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import android.content.res.Resources; |
| 23 | 23 |
|
| 24 |
import org.distorted.helpers.ScrambleState; |
|
| 24 | 25 |
import org.distorted.library.main.DistortedEffects; |
| 25 | 26 |
import org.distorted.library.main.DistortedTexture; |
| 26 | 27 |
import org.distorted.library.mesh.MeshSquare; |
| ... | ... | |
| 216 | 217 |
36, 34, 56, 32, 43, 21, 48, 28, 42, 23 |
| 217 | 218 |
}; |
| 218 | 219 |
|
| 219 |
static final boolean[][] OPPOSITE_ROWS = |
|
| 220 |
{
|
|
| 221 |
{false, true, false, true, false, false},
|
|
| 222 |
{ true, false, false, true, true, true},
|
|
| 223 |
{false, false, false, true, false, true},
|
|
| 224 |
{ true, true, true, false, false, true},
|
|
| 225 |
{false, true, false, false, false, true},
|
|
| 226 |
{false, true, true, true, true, false}
|
|
| 227 |
}; |
|
| 228 |
|
|
| 229 | 220 |
// the quadruple ( corner1, corner2, face1, face2 ) defining an edge. |
| 230 | 221 |
// In fact the 2 corners already define it, the faces only provide easy |
| 231 | 222 |
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on |
| ... | ... | |
| 326 | 317 |
mBasicCornerV[2] = new Static4D( 0, -0.500f, 0.0f, 0.0f ); |
| 327 | 318 |
} |
| 328 | 319 |
|
| 329 |
private static int[][] mScrambleTable; |
|
| 330 |
private static int[] mPossibleAxis, mPossibleLayers; |
|
| 331 |
private static int[] mNumOccurences; |
|
| 320 |
private int mCurrState; |
|
| 321 |
private int mIndexExcluded; |
|
| 322 |
private ScrambleState[] mStates; |
|
| 323 |
private int[][] mScrambleTable; |
|
| 324 |
private int[] mNumOccurences; |
|
| 332 | 325 |
|
| 333 | 326 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 334 | 327 |
|
| ... | ... | |
| 336 | 329 |
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth) |
| 337 | 330 |
{
|
| 338 | 331 |
super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth); |
| 332 |
|
|
| 333 |
initializeScrambleStates(numLayers); |
|
| 339 | 334 |
} |
| 340 | 335 |
|
| 341 | 336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 342 | 337 |
|
| 343 |
int[] getSolvedQuats(int cubit, int numLayers)
|
|
| 338 |
private int[] generateL(int numLayers, int index)
|
|
| 344 | 339 |
{
|
| 345 |
int status = retCubitSolvedStatus(cubit,numLayers); |
|
| 346 |
return status<0 ? null : buildSolvedQuats(MovementMinx.FACE_AXIS[mFaceMap[status]],QUATS); |
|
| 340 |
int rows = (numLayers-1)/2; |
|
| 341 |
int[] ret = new int[3*4*rows]; |
|
| 342 |
|
|
| 343 |
for(int i=0; i<rows; i++) |
|
| 344 |
{
|
|
| 345 |
ret[12*i ] = i; |
|
| 346 |
ret[12*i+ 1] =-2; |
|
| 347 |
ret[12*i+ 2] = index; |
|
| 348 |
ret[12*i+ 3] = i; |
|
| 349 |
ret[12*i+ 4] =-1; |
|
| 350 |
ret[12*i+ 5] = index; |
|
| 351 |
ret[12*i+ 6] = i; |
|
| 352 |
ret[12*i+ 7] =+1; |
|
| 353 |
ret[12*i+ 8] = index; |
|
| 354 |
ret[12*i+ 9] = i; |
|
| 355 |
ret[12*i+10] =+2; |
|
| 356 |
ret[12*i+11] = index; |
|
| 357 |
} |
|
| 358 |
|
|
| 359 |
return ret; |
|
| 347 | 360 |
} |
| 348 | 361 |
|
| 349 | 362 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 350 | 363 |
|
| 351 |
Static4D[] getQuats()
|
|
| 364 |
private int[] generateR(int numLayers, int index)
|
|
| 352 | 365 |
{
|
| 353 |
return QUATS; |
|
| 366 |
int rows = (numLayers-1)/2; |
|
| 367 |
int[] ret = new int[3*4*rows]; |
|
| 368 |
|
|
| 369 |
for(int i=0; i<rows; i++) |
|
| 370 |
{
|
|
| 371 |
int lay = rows+i+1; |
|
| 372 |
|
|
| 373 |
ret[12*i ] = lay; |
|
| 374 |
ret[12*i+ 1] =-2; |
|
| 375 |
ret[12*i+ 2] = index; |
|
| 376 |
ret[12*i+ 3] = lay; |
|
| 377 |
ret[12*i+ 4] =-1; |
|
| 378 |
ret[12*i+ 5] = index; |
|
| 379 |
ret[12*i+ 6] = lay; |
|
| 380 |
ret[12*i+ 7] =+1; |
|
| 381 |
ret[12*i+ 8] = index; |
|
| 382 |
ret[12*i+ 9] = lay; |
|
| 383 |
ret[12*i+10] =+2; |
|
| 384 |
ret[12*i+11] = index; |
|
| 385 |
} |
|
| 386 |
|
|
| 387 |
return ret; |
|
| 354 | 388 |
} |
| 355 | 389 |
|
| 356 | 390 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 357 | 391 |
|
| 358 |
int getNumFaces()
|
|
| 392 |
private int[] generateB(int numLayers, int index)
|
|
| 359 | 393 |
{
|
| 360 |
return FACE_COLORS.length; |
|
| 394 |
int rows = (numLayers-1); |
|
| 395 |
int half = rows/2; |
|
| 396 |
int[] ret = new int[3*4*rows]; |
|
| 397 |
|
|
| 398 |
for(int i=0; i<rows; i++) |
|
| 399 |
{
|
|
| 400 |
int ind = i<half? index : index+1; |
|
| 401 |
int lay = i<half? i : i+1; |
|
| 402 |
|
|
| 403 |
ret[12*i ] = lay; |
|
| 404 |
ret[12*i+ 1] =-2; |
|
| 405 |
ret[12*i+ 2] = ind; |
|
| 406 |
ret[12*i+ 3] = lay; |
|
| 407 |
ret[12*i+ 4] =-1; |
|
| 408 |
ret[12*i+ 5] = ind; |
|
| 409 |
ret[12*i+ 6] = lay; |
|
| 410 |
ret[12*i+ 7] =+1; |
|
| 411 |
ret[12*i+ 8] = ind; |
|
| 412 |
ret[12*i+ 9] = lay; |
|
| 413 |
ret[12*i+10] =+2; |
|
| 414 |
ret[12*i+11] = ind; |
|
| 415 |
} |
|
| 416 |
|
|
| 417 |
return ret; |
|
| 361 | 418 |
} |
| 362 | 419 |
|
| 363 | 420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 364 | 421 |
|
| 365 |
int getSolvedFunctionIndex()
|
|
| 422 |
private void initializeScrambleStates(int numLayers)
|
|
| 366 | 423 |
{
|
| 367 |
return 0; |
|
| 424 |
int[] LEFT0 = generateL(numLayers,1); |
|
| 425 |
int[] RIGH0 = generateR(numLayers,2); |
|
| 426 |
int[] LEFT1 = generateL(numLayers,3); |
|
| 427 |
int[] RIGH1 = generateR(numLayers,4); |
|
| 428 |
int[] LEFT2 = generateL(numLayers,5); |
|
| 429 |
int[] RIGH2 = generateR(numLayers,6); |
|
| 430 |
int[] LEFT3 = generateL(numLayers,7); |
|
| 431 |
int[] RIGH3 = generateR(numLayers,8); |
|
| 432 |
int[] LEFT4 = generateL(numLayers,9); |
|
| 433 |
int[] RIGH4 = generateR(numLayers,10); |
|
| 434 |
int[] LEFT5 = generateL(numLayers,11); |
|
| 435 |
int[] RIGH5 = generateR(numLayers,12); |
|
| 436 |
|
|
| 437 |
int[] BOTH1 = generateB(numLayers,1); |
|
| 438 |
int[] BOTH3 = generateB(numLayers,3); |
|
| 439 |
int[] BOTH5 = generateB(numLayers,5); |
|
| 440 |
int[] BOTH7 = generateB(numLayers,7); |
|
| 441 |
int[] BOTH9 = generateB(numLayers,9); |
|
| 442 |
int[] BOTH11= generateB(numLayers,11); |
|
| 443 |
|
|
| 444 |
mStates = new ScrambleState[] |
|
| 445 |
{
|
|
| 446 |
new ScrambleState( new int[][] { BOTH1,BOTH3,BOTH5,BOTH7,BOTH9,BOTH11 } ), // beg
|
|
| 447 |
new ScrambleState( new int[][] { {} ,RIGH1,LEFT2,RIGH3,LEFT4,LEFT5 } ), // 0L
|
|
| 448 |
new ScrambleState( new int[][] { {} ,LEFT1,RIGH2,LEFT3,RIGH4,RIGH5 } ), // 0R
|
|
| 449 |
new ScrambleState( new int[][] { RIGH0,{} ,LEFT2,RIGH3,RIGH4,RIGH5 } ), // 1L
|
|
| 450 |
new ScrambleState( new int[][] { LEFT0,{} ,RIGH2,LEFT3,LEFT4,LEFT5 } ), // 1R
|
|
| 451 |
new ScrambleState( new int[][] { LEFT0,LEFT1,{} ,RIGH3,LEFT4,RIGH5 } ), // 2L
|
|
| 452 |
new ScrambleState( new int[][] { RIGH0,RIGH1,{} ,LEFT3,RIGH4,LEFT5 } ), // 2R
|
|
| 453 |
new ScrambleState( new int[][] { RIGH0,RIGH1,RIGH2,{} ,LEFT4,RIGH5 } ), // 3L
|
|
| 454 |
new ScrambleState( new int[][] { LEFT0,LEFT1,LEFT2,{} ,RIGH4,LEFT5 } ), // 3R
|
|
| 455 |
new ScrambleState( new int[][] { LEFT0,RIGH1,LEFT2,LEFT3,{} ,RIGH5 } ), // 4L
|
|
| 456 |
new ScrambleState( new int[][] { RIGH0,LEFT1,RIGH2,RIGH3,{} ,LEFT5 } ), // 4R
|
|
| 457 |
new ScrambleState( new int[][] { LEFT0,RIGH1,RIGH2,RIGH3,RIGH4,{} } ), // 5L
|
|
| 458 |
new ScrambleState( new int[][] { RIGH0,LEFT1,LEFT2,LEFT3,LEFT4,{} } ), // 5R
|
|
| 459 |
}; |
|
| 368 | 460 |
} |
| 369 | 461 |
|
| 370 | 462 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 371 | 463 |
|
| 372 |
boolean shouldResetTextureMaps()
|
|
| 464 |
int[] getSolvedQuats(int cubit, int numLayers)
|
|
| 373 | 465 |
{
|
| 374 |
return false; |
|
| 466 |
int status = retCubitSolvedStatus(cubit,numLayers); |
|
| 467 |
return status<0 ? null : buildSolvedQuats(MovementMinx.FACE_AXIS[mFaceMap[status]],QUATS); |
|
| 375 | 468 |
} |
| 376 | 469 |
|
| 377 | 470 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 378 | 471 |
|
| 379 |
int getNumCubitFaces()
|
|
| 472 |
Static4D[] getQuats()
|
|
| 380 | 473 |
{
|
| 381 |
return FACES_PER_CUBIT;
|
|
| 474 |
return QUATS;
|
|
| 382 | 475 |
} |
| 383 | 476 |
|
| 384 | 477 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 385 | 478 |
|
| 386 |
float returnMultiplier()
|
|
| 479 |
int getNumFaces()
|
|
| 387 | 480 |
{
|
| 388 |
return 2.0f;
|
|
| 481 |
return FACE_COLORS.length;
|
|
| 389 | 482 |
} |
| 390 | 483 |
|
| 391 | 484 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 392 | 485 |
|
| 393 |
private void initializeScrambleTable(int[] first, int numLayers)
|
|
| 486 |
int getSolvedFunctionIndex()
|
|
| 394 | 487 |
{
|
| 395 |
if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2]; |
|
| 396 |
if( mPossibleAxis ==null ) mPossibleAxis = new int[NUM_AXIS-1]; |
|
| 397 |
if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1]; |
|
| 398 |
if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1]; |
|
| 399 |
|
|
| 400 |
for(int i=0; i<NUM_AXIS; i++) |
|
| 401 |
for(int j=0; j<2; j++) |
|
| 402 |
{
|
|
| 403 |
mScrambleTable[i][j] = 0; |
|
| 404 |
} |
|
| 405 |
|
|
| 406 |
int layer = convertRowIntoLayer(first[1],numLayers); |
|
| 407 |
|
|
| 408 |
mScrambleTable[first[0]][layer] = 1; |
|
| 488 |
return 0; |
|
| 409 | 489 |
} |
| 410 | 490 |
|
| 411 | 491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 412 | 492 |
|
| 413 |
private int convertRowIntoLayer(int row, int numLayers)
|
|
| 493 |
boolean shouldResetTextureMaps()
|
|
| 414 | 494 |
{
|
| 415 |
return row>(numLayers-1)/2 ? 1 : 0;
|
|
| 495 |
return false;
|
|
| 416 | 496 |
} |
| 417 | 497 |
|
| 418 | 498 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 419 | 499 |
|
| 420 |
private int convertLayerIntoRow(Random rnd, int layer, int numLayers)
|
|
| 500 |
int getNumCubitFaces()
|
|
| 421 | 501 |
{
|
| 422 |
int ran = numLayers>3 ? rnd.nextInt((numLayers-1)/2) : 0; |
|
| 423 |
return layer==0 ? ran : numLayers-1-ran; |
|
| 502 |
return FACES_PER_CUBIT; |
|
| 424 | 503 |
} |
| 425 | 504 |
|
| 426 | 505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 427 | 506 |
|
| 428 |
private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom)
|
|
| 507 |
float returnMultiplier()
|
|
| 429 | 508 |
{
|
| 430 |
return OPPOSITE_ROWS[oldAxis][newAxis]^(oldRow<nom);
|
|
| 509 |
return 2.0f;
|
|
| 431 | 510 |
} |
| 432 | 511 |
|
| 433 | 512 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 434 | 513 |
|
| 435 |
private int retNewRotationIndex(Random rnd, int nom, int[] oldRot)
|
|
| 514 |
private void initializeScrambling()
|
|
| 436 | 515 |
{
|
| 437 |
int index=0, max=0;
|
|
| 516 |
int numLayers = getNumLayers();
|
|
| 438 | 517 |
|
| 439 |
for(int ax=0; ax<NUM_AXIS; ax++)
|
|
| 518 |
if( mScrambleTable ==null )
|
|
| 440 | 519 |
{
|
| 441 |
if( ax!=oldRot[0] ) |
|
| 442 |
{
|
|
| 443 |
mPossibleAxis[index] = ax; |
|
| 444 |
mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1; |
|
| 445 |
int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]; |
|
| 446 |
if( tmp>max ) max=tmp; |
|
| 447 |
index++; |
|
| 448 |
} |
|
| 520 |
mScrambleTable = new int[NUM_AXIS][numLayers]; |
|
| 449 | 521 |
} |
| 450 |
|
|
| 451 |
for(int ax=0; ax<NUM_AXIS-1; ax++) |
|
| 522 |
if( mNumOccurences ==null ) |
|
| 452 | 523 |
{
|
| 453 |
int value = mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]]; |
|
| 454 |
mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]); |
|
| 455 |
} |
|
| 524 |
int max=0; |
|
| 456 | 525 |
|
| 457 |
float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2]; |
|
| 458 |
|
|
| 459 |
for(int ax=0; ax<NUM_AXIS-1; ax++) |
|
| 460 |
{
|
|
| 461 |
if( random <= mNumOccurences[ax] ) |
|
| 526 |
for (ScrambleState mState : mStates) |
|
| 462 | 527 |
{
|
| 463 |
index=ax;
|
|
| 464 |
break;
|
|
| 528 |
int tmp = mState.getTotal(-1);
|
|
| 529 |
if (max < tmp) max = tmp;
|
|
| 465 | 530 |
} |
| 466 |
} |
|
| 467 | 531 |
|
| 468 |
mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++; |
|
| 532 |
mNumOccurences = new int[max]; |
|
| 533 |
} |
|
| 469 | 534 |
|
| 470 |
return index; |
|
| 535 |
for(int i=0; i<NUM_AXIS; i++) |
|
| 536 |
for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0; |
|
| 471 | 537 |
} |
| 472 | 538 |
|
| 473 | 539 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 474 | 540 |
// PUBLIC API |
| 475 | 541 |
|
| 476 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total) |
|
| 542 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
|
| 477 | 543 |
{
|
| 478 |
int numLayers = getNumLayers(); |
|
| 479 |
int nom = (numLayers-1)/2; |
|
| 480 |
|
|
| 481 | 544 |
if( curr==0 ) |
| 482 | 545 |
{
|
| 483 |
int lf = rnd.nextInt(2); |
|
| 484 |
int row= rnd.nextInt(nom); |
|
| 485 |
scramble[curr][0] = rnd.nextInt(NUM_AXIS); |
|
| 486 |
scramble[curr][1] = (lf==0 ? row : numLayers-1-row); |
|
| 487 |
initializeScrambleTable(scramble[curr],numLayers); |
|
| 488 |
} |
|
| 489 |
else |
|
| 490 |
{
|
|
| 491 |
int index = retNewRotationIndex(rnd,nom,scramble[curr-1]); |
|
| 492 |
scramble[curr][0] = mPossibleAxis[index]; |
|
| 493 |
scramble[curr][1] = convertLayerIntoRow(rnd, mPossibleLayers[index], numLayers); |
|
| 546 |
mCurrState = 0; |
|
| 547 |
mIndexExcluded =-1; |
|
| 548 |
initializeScrambling(); |
|
| 494 | 549 |
} |
| 495 | 550 |
|
| 496 |
switch( rnd.nextInt(4) ) |
|
| 497 |
{
|
|
| 498 |
case 0: scramble[curr][2] = -2; break; |
|
| 499 |
case 1: scramble[curr][2] = -1; break; |
|
| 500 |
case 2: scramble[curr][2] = 1; break; |
|
| 501 |
case 3: scramble[curr][2] = 2; break; |
|
| 502 |
} |
|
| 551 |
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences); |
|
| 552 |
|
|
| 553 |
scramble[curr][0] = info[0]; |
|
| 554 |
scramble[curr][1] = info[1]; |
|
| 555 |
scramble[curr][2] = info[2]; |
|
| 556 |
|
|
| 557 |
mCurrState = info[3]; |
|
| 558 |
mIndexExcluded = info[0]; |
|
| 503 | 559 |
} |
| 504 | 560 |
|
| 505 | 561 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Convert the 4 Minx'es to the new scrambling paradigm.