Project

General

Profile

« Previous | Next » 

Revision 01b2ef5a

Added by Leszek Koltunski over 2 years ago

Convert Skewbs & Rex Cube to the new, unified scrambling method.

View differences:

src/main/java/org/distorted/objects/TwistyRex.java
23 23

  
24 24
import org.distorted.helpers.ObjectShape;
25 25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleStateGraph;
26 27
import org.distorted.library.main.DistortedEffects;
27 28
import org.distorted.library.main.DistortedTexture;
28 29
import org.distorted.library.mesh.MeshSquare;
......
152 153
      }
153 154
    }
154 155

  
156
  private int mCurrState;
157
  private int mIndexExcluded;
158
  private final ScrambleStateGraph[] mStates;
159

  
155 160
///////////////////////////////////////////////////////////////////////////////////////////////////
156 161

  
157 162
  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
158 163
            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
159 164
    {
160 165
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
166

  
167
    int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
168

  
169
    mStates = new ScrambleStateGraph[]
170
      {
171
      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
172
      };
161 173
    }
162 174

  
163 175
///////////////////////////////////////////////////////////////////////////////////////////////////
......
481 493

  
482 494
///////////////////////////////////////////////////////////////////////////////////////////////////
483 495

  
484
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
496
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
485 497
    {
486 498
    if( curr==0 )
487 499
      {
488
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
489
      }
490
    else
491
      {
492
      int newVector = rnd.nextInt(NUM_AXIS -1);
493
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
500
      mCurrState     = 0;
501
      mIndexExcluded =-1;
494 502
      }
495 503

  
496
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
504
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
505
    int random= rnd.nextInt(total);
506
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
497 507

  
498
    switch( rnd.nextInt(2) )
499
      {
500
      case 0: scramble[curr][2] = -1; break;
501
      case 1: scramble[curr][2] =  1; break;
502
      }
508
    scramble[curr][0] = info[0];
509
    scramble[curr][1] = info[1];
510
    scramble[curr][2] = info[2];
511

  
512
    mCurrState     = info[3];
513
    mIndexExcluded = info[0];
503 514
    }
504 515

  
505 516
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistySkewb.java
23 23

  
24 24
import org.distorted.helpers.ObjectShape;
25 25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleStateGraph;
26 27
import org.distorted.library.main.DistortedEffects;
27 28
import org.distorted.library.main.DistortedTexture;
28 29
import org.distorted.library.mesh.MeshSquare;
......
189 190
      }
190 191
    }
191 192

  
193
  private int mCurrState;
194
  private int mIndexExcluded;
195
  private final ScrambleStateGraph[] mStates;
196

  
192 197
///////////////////////////////////////////////////////////////////////////////////////////////////
193 198

  
194 199
  TwistySkewb(int size, Static4D quat, DistortedTexture texture,
195 200
              MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
196 201
    {
197 202
    super(size, 2*size-2, quat, texture, mesh, effects, moves, ObjectList.SKEW, res, scrWidth);
203

  
204
    int[] tmp = {0,-1,0, 0,1,0, size-1,-1,0, size-1,1,0 };
205

  
206
    mStates = new ScrambleStateGraph[]
207
      {
208
      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
209
      };
198 210
    }
199 211

  
200 212
///////////////////////////////////////////////////////////////////////////////////////////////////
......
599 611

  
600 612
///////////////////////////////////////////////////////////////////////////////////////////////////
601 613

  
602
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
614
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
603 615
    {
604 616
    if( curr==0 )
605 617
      {
606
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
607
      }
608
    else
609
      {
610
      int newVector = rnd.nextInt(NUM_AXIS-1);
611
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
618
      mCurrState     = 0;
619
      mIndexExcluded =-1;
612 620
      }
613 621

  
614
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : getNumLayers()-1;
622
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
623
    int random= rnd.nextInt(total);
624
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
615 625

  
616
    switch( rnd.nextInt(2) )
617
      {
618
      case 0: scramble[curr][2] = -1; break;
619
      case 1: scramble[curr][2] =  1; break;
620
      }
626
    scramble[curr][0] = info[0];
627
    scramble[curr][1] = info[1];
628
    scramble[curr][2] = info[2];
629

  
630
    mCurrState     = info[3];
631
    mIndexExcluded = info[0];
621 632
    }
622 633

  
623 634
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff