Project

General

Profile

« Previous | Next » 

Revision 3a5aa558

Added by Leszek Koltunski about 2 years ago

Fix scrambling the Danavi Block IV (and Burr Cube). Still looks a bit buggy, shouldn't have two consecutive moves along the same axis and layer and it seems to have those occasionally.

View differences:

src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java
441 441
    mBandagedStates.add(nextState);
442 442
    }
443 443

  
444

  
444 445
///////////////////////////////////////////////////////////////////////////////////////////////////
445 446
// TYPE 2
446 447

  
447
  private boolean buildMove(int[][] scramble, Random rnd, int curr)
448
  private boolean buildMove2Cons(int[][] scramble, Random rnd, int curr)
448 449
    {
449 450
    ScrambleStateBandagedCuboid currState = mBandagedStates.get(curr);
450
    int indexExcluded = curr>0 ? scramble[curr-1][0] : ScrambleStateBandagedCuboid.AXIS_NONE;
451
    int numMoves = currState.numMoves(indexExcluded);
451
    boolean lock= (curr>=2 && scramble[curr-2][0]==scramble[curr-1][0] );
452
    int axisExcluded = lock ? scramble[curr-1][0] : ScrambleStateBandagedCuboid.AXIS_NONE;
453
    int layerExcluded= !lock && curr>=1 ? scramble[curr-1][1] : -1;
454
    int numMoves = currState.numMoves(axisExcluded,layerExcluded);
452 455

  
453 456
    while( numMoves==0 )
454 457
      {
......
458 461
        ScrambleStateBandagedCuboid prevState = mBandagedStates.get(curr-1);
459 462
        ObjectSignature signature = currState.getSignature();
460 463
        prevState.removeMoves(signature);
461
        boolean result = buildMove(scramble,rnd,curr-1);
464
        boolean result = buildMove2Cons(scramble,rnd,curr-1);
462 465
        if( !result ) return false;
463 466
        currState = mBandagedStates.get(curr);
464
        indexExcluded = scramble[curr-1][0];
465
        numMoves = currState.numMoves(indexExcluded);
467
        lock= (curr>=2 && scramble[curr-2][0]==scramble[curr-1][0] );
468
        axisExcluded = lock ? scramble[curr-1][0] : ScrambleStateBandagedCuboid.AXIS_NONE;
469
        layerExcluded= lock ? -1 : scramble[curr-1][1];
470
        numMoves = currState.numMoves(axisExcluded,layerExcluded);
471
        }
472
      else return false;
473
      }
474

  
475
    int randMove = rnd.nextInt(numMoves);
476
    int moveIndex = currState.getNthMove(randMove,axisExcluded,layerExcluded);
477
    ObjectSignature signature = currState.getMove(moveIndex);
478
    currState.fillOutScramble(scramble[curr],moveIndex);
479

  
480
    ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], signature);
481
    mBandagedStates.add(nextState);
482

  
483
    return true;
484
    }
485

  
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
// TYPE 2
488

  
489
  private boolean buildMove1Cons(int[][] scramble, Random rnd, int curr)
490
    {
491
    ScrambleStateBandagedCuboid currState = mBandagedStates.get(curr);
492
    int axisExcluded = curr>=1 ? scramble[curr-1][0] : ScrambleStateBandagedCuboid.AXIS_NONE;
493
    int numMoves = currState.numMoves(axisExcluded);
494

  
495
    while( numMoves==0 )
496
      {
497
      if( curr>0 )
498
        {
499
        mBandagedStates.remove(curr);
500
        ScrambleStateBandagedCuboid prevState = mBandagedStates.get(curr-1);
501
        ObjectSignature signature = currState.getSignature();
502
        prevState.removeMoves(signature);
503
        boolean result = buildMove1Cons(scramble,rnd,curr-1);
504
        if( !result ) return false;
505
        currState = mBandagedStates.get(curr);
506
        axisExcluded = scramble[curr-1][0];
507
        numMoves = currState.numMoves(axisExcluded);
466 508
        }
467 509
      else
468 510
        {
......
471 513
      }
472 514

  
473 515
    int randMove = rnd.nextInt(numMoves);
474
    int moveIndex = currState.getNthMove(randMove,indexExcluded);
516
    int moveIndex = currState.getNthMove(randMove,axisExcluded);
475 517
    ObjectSignature signature = currState.getMove(moveIndex);
476 518
    currState.fillOutScramble(scramble[curr],moveIndex);
477 519

  
......
495 537

  
496 538
    for(int curr=0; curr<total; curr++)
497 539
      {
498
      boolean result = buildMove(scramble,rnd,curr);
540
      boolean result = buildMove1Cons(scramble,rnd,curr);
499 541
      if( !result )
500 542
        {
501 543
        success = false;
......
503 545
        }
504 546
      }
505 547

  
548
    if( !success )
549
      {
550
      success = true;
551
      mBandagedStates.clear();
552
      state = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], signature);
553
      mBandagedStates.add(state);
554

  
555
      for(int curr=0; curr<total; curr++)
556
        {
557
        boolean result = buildMove2Cons(scramble,rnd,curr);
558
        if( !result )
559
          {
560
          success = false;
561
          break;
562
          }
563
        }
564
      }
565

  
506 566
    if( !success )
507 567
      {
508 568
      mBandagedStates.clear();

Also available in: Unified diff