Project

General

Profile

« Previous | Next » 

Revision 0812242b

Added by Leszek Koltunski over 3 years ago

Improve scrambling of the Minx'es and the Redi, which in full scramble mode were frequently leaving large corners unscrambled.

View differences:

src/main/java/org/distorted/main/RubikSurfaceView.java
621 621

  
622 622
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
623 623
          crashlytics.setCustomKey("GLSL Version"  , shading );
624
          crashlytics.setCustomKey("GLversion"     , version );
624
          crashlytics.setCustomKey("GL version"    , version );
625 625
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
626
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
626
          crashlytics.setCustomKey("GLSL renderer" , renderer);
627 627
          crashlytics.recordException(ex);
628 628
          }
629 629
        }
src/main/java/org/distorted/objects/TwistyMinx.java
326 326
    mBasicCornerV[2] = new Static4D(              0,        -0.500f,    0.0f, 0.0f );
327 327
    }
328 328

  
329
  private static int[][] mScrambleTable;
330
  private static int[] mPossibleAxis, mPossibleLayers;
331
  private static int[] mNumOccurences;
332

  
329 333
///////////////////////////////////////////////////////////////////////////////////////////////////
330 334

  
331 335
  TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
......
427 431
    }
428 432

  
429 433
///////////////////////////////////////////////////////////////////////////////////////////////////
430
// PUBLIC API
431 434

  
432
  public Static3D[] getRotationAxis()
435
  private void initializeScrambleTable(int[] first, int numLayers)
433 436
    {
434
    return ROT_AXIS;
437
    if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2];
438
    if( mPossibleAxis  ==null ) mPossibleAxis  = new int[NUM_AXIS-1];
439
    if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1];
440
    if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1];
441

  
442
    for(int i=0; i<NUM_AXIS; i++)
443
      for(int j=0; j<2; j++)
444
        {
445
        mScrambleTable[i][j] = 0;
446
        }
447

  
448
    int layer = convertRowIntoLayer(first[1],numLayers);
449

  
450
    mScrambleTable[first[0]][layer] = 1;
435 451
    }
436 452

  
437 453
///////////////////////////////////////////////////////////////////////////////////////////////////
438 454

  
439
  public int[] getBasicAngle()
455
  private int convertRowIntoLayer(int row, int numLayers)
440 456
    {
441
    return BASIC_ANGLE;
457
    return row>(numLayers-1)/2 ? 1 : 0;
458
    }
459

  
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

  
462
  private int convertLayerIntoRow(Random rnd, int layer, int numLayers)
463
    {
464
    int ran = numLayers>3 ? rnd.nextInt((numLayers-1)/2) : 0;
465
    return layer==0 ? ran : numLayers-1-ran;
442 466
    }
443 467

  
444 468
///////////////////////////////////////////////////////////////////////////////////////////////////
445 469

  
470
  private int retNewRotationIndex(Random rnd, int nom, int[] oldRot)
471
    {
472
    int index=0, max=0;
473

  
474
    for(int ax=0; ax<NUM_AXIS; ax++)
475
      {
476
      if( ax!=oldRot[0] )
477
        {
478
        mPossibleAxis[index] = ax;
479
        boolean opposite = OPPOSITE_ROWS[oldRot[0]][ax];
480
        boolean low = opposite^(oldRot[1]<nom);
481
        mPossibleLayers[index] = low ? 0:1;
482
        int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]];
483
        if( tmp>max ) max=tmp;
484
        index++;
485
        }
486
      }
487

  
488
    for(int ax=0; ax<NUM_AXIS-1; ax++)
489
      {
490
      if( ax==0 )
491
        {
492
        mNumOccurences[ax] = max-mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]];
493
        }
494
      else
495
        {
496
        mNumOccurences[ax] = max-mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]] + mNumOccurences[ax-1];
497
        }
498
      }
499

  
500
    float random= rnd.nextFloat();
501
    int total = mNumOccurences[NUM_AXIS-2];
502

  
503
    for(int ax=0; ax<NUM_AXIS-1; ax++)
504
      {
505
      if( random*total <= mNumOccurences[ax] )
506
        {
507
        index=ax;
508
        break;
509
        }
510
      }
511

  
512
    mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++;
513

  
514
    return index;
515
    }
516

  
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518
// PUBLIC API
519

  
446 520
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
447 521
    {
448 522
    int numLayers = getNumLayers();
......
451 525

  
452 526
    if( curr==0 )
453 527
      {
454
      int lf  = rnd.nextInt(2);
528
      int lf = rnd.nextInt(2);
455 529
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
456 530
      scramble[curr][1] = (lf==0 ? row : numLayers-1-row);
531
      initializeScrambleTable(scramble[curr],numLayers);
457 532
      }
458 533
    else
459 534
      {
460
      boolean opposite = OPPOSITE_ROWS[scramble[curr-1][0]][scramble[curr][0]];
461
      boolean low = opposite^(scramble[curr-1][1]<nom);
462
      int newVector = rnd.nextInt(NUM_AXIS-1);
463
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
464
      scramble[curr][1] = (low ? row : numLayers-1-row);
535
      int index = retNewRotationIndex(rnd,nom,scramble[curr-1]);
536
      scramble[curr][0] = mPossibleAxis[index];
537
      scramble[curr][1] = convertLayerIntoRow(rnd, mPossibleLayers[index], numLayers);
465 538
      }
466 539

  
467 540
    switch( rnd.nextInt(4) )
......
473 546
      }
474 547
    }
475 548

  
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

  
551
  public Static3D[] getRotationAxis()
552
    {
553
    return ROT_AXIS;
554
    }
555

  
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557

  
558
  public int[] getBasicAngle()
559
    {
560
    return BASIC_ANGLE;
561
    }
562

  
476 563
///////////////////////////////////////////////////////////////////////////////////////////////////
477 564
// only needed for solvers - there are no Minx solvers ATM)
478 565

  
src/main/java/org/distorted/objects/TwistyRedi.java
203 203

  
204 204
  private static MeshBase[] mMeshes;
205 205

  
206
  private static int[][] mScrambleTable;
207
  private static int[] mPossibleAxis, mPossibleLayers;
208

  
206 209
///////////////////////////////////////////////////////////////////////////////////////////////////
207 210

  
208 211
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
......
419 422
    return BASIC_ANGLE;
420 423
    }
421 424

  
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

  
427
  private void initializeScrambleTable(int[] first)
428
    {
429
    if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2];
430
    if( mPossibleAxis  ==null ) mPossibleAxis  = new int[NUM_AXIS-1];
431
    if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1];
432

  
433
    for(int i=0; i<NUM_AXIS; i++)
434
      for(int j=0; j<2; j++)
435
        {
436
        mScrambleTable[i][j] = 0;
437
        }
438

  
439
    mScrambleTable[first[0]][first[1]/2] = 1;
440
    }
441

  
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

  
444
  private int retNewRotationIndex(Random rnd, int[] oldRot)
445
    {
446
    int index=0, max=0;
447

  
448
    for(int ax=0; ax<NUM_AXIS; ax++)
449
      {
450
      if( ax!=oldRot[0] )
451
        {
452
        mPossibleAxis[index] = ax;
453
        mPossibleLayers[index] = oldRot[0]+ax==3 ? 1-oldRot[1]/2 : oldRot[1]/2;
454
        int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]];
455
        if( tmp>max ) max=tmp;
456
        index++;
457
        }
458
      }
459

  
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]];
463

  
464
    float total = a0+a1+a2;
465
    float random= rnd.nextFloat();
466

  
467
         if( random*total < a0    ) index=0;
468
    else if( random*total < a0+a1 ) index=1;
469
    else                            index=2;
470

  
471
    mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++;
472

  
473
    return index;
474
    }
475

  
422 476
///////////////////////////////////////////////////////////////////////////////////////////////////
423 477

  
424 478
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
......
427 481
      {
428 482
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
429 483
      scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0:2;
484
      initializeScrambleTable(scramble[curr]);
430 485
      }
431 486
    else
432 487
      {
433
      int newVector = rnd.nextInt(NUM_AXIS -1);
434
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
435
      scramble[curr][1] = (scramble[curr-1][0]+scramble[curr][0]==3 ? 2-scramble[curr-1][1] : scramble[curr-1][1]);
488
      int index = retNewRotationIndex(rnd,scramble[curr-1]);
489
      scramble[curr][0] = mPossibleAxis[index];
490
      scramble[curr][1] = 2*mPossibleLayers[index];
436 491
      }
437 492

  
438 493
    switch( rnd.nextInt(2) )
......
443 498
    }
444 499

  
445 500
///////////////////////////////////////////////////////////////////////////////////////////////////
446
// The Redi is solved if and only if:
447
//
448
// ??
501
// The Redi is solved if and only if all cubits are rotated with the same quat.
449 502

  
450 503
  public boolean isSolved()
451 504
    {

Also available in: Unified diff