Project

General

Profile

« Previous | Next » 

Revision 0021af58

Added by Leszek Koltunski about 3 years ago

Convert Square-2 to the new generic scrambling algorithm.

In order to do it we need to introduce a third, artificial rotational axis - otherwise the algorithm would make it impossible to rotate the lower layer and immediatelly after - the upper.

View differences:

src/main/java/org/distorted/objects/MovementSquare.java
39 39

  
40 40
  MovementSquare()
41 41
    {
42
    super(TwistySquare1.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
42
    super(TwistySquare.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
43 43
    }
44 44

  
45 45
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistySquare.java
40 40
  static final float SIN15 = (SQ6-SQ2)/4;
41 41
  static final float     X = 3*(2-SQ3)/2;
42 42

  
43
  // The third, artificial axis is for the generic scrambling algorithm.
44
  // Otherwise it wouldn't be possible to rotate the LO and UP layers
45
  // consecutively.
46

  
43 47
  static final Static3D[] ROT_AXIS = new Static3D[]
44 48
    {
45
      new Static3D(0,1,0),
46
      new Static3D(COS15,0,SIN15)
49
      new Static3D(0,+1,0),
50
      new Static3D(COS15,0,SIN15),
51
      new Static3D(0,-1,0),
47 52
    };
48 53

  
49
  static final int[] BASIC_ANGLE = new int[] { 12,2 };
54
  static final int[] BASIC_ANGLE = new int[] { 12,2,12 };
50 55

  
51 56
  static final int[] FACE_COLORS = new int[]
52 57
    {
......
210 215

  
211 216
  float[][] getCuts(int numLayers)
212 217
    {
213
    return new float[][] { {-0.5f,+0.5f}, {0.0f} };
218
    return new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
214 219
    }
215 220

  
216 221
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistySquare2.java
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;
......
173 174
      }
174 175
    }
175 176

  
177
  private int mCurrState;
178
  private int mIndexExcluded;
179
  private final ScrambleState[] mStates;
180
  private int[][] mScrambleTable;
181
  private int[] mNumOccurences;
182

  
176 183
///////////////////////////////////////////////////////////////////////////////////////////////////
177 184

  
178 185
  TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
179 186
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
180 187
    {
181 188
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
189

  
190
    int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
191
    int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
192
    int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
193
    int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
194
    int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
195

  
196
    mStates = new ScrambleState[]
197
      {
198
      new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
199
      new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
200
      new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
201
      new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
202
      new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
203
      };
182 204
    }
183 205

  
184 206
///////////////////////////////////////////////////////////////////////////////////////////////////
......
290 312
    }
291 313

  
292 314
///////////////////////////////////////////////////////////////////////////////////////////////////
293
// PUBLIC API
294 315

  
295
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
316
  private void initializeScrambling()
296 317
    {
297
    int layer, nextAngle;
318
    int numLayers = getNumLayers();
319

  
320
    if( mScrambleTable ==null )
321
      {
322
      mScrambleTable = new int[NUM_AXIS][numLayers];
323
      }
324
    if( mNumOccurences ==null )
325
      {
326
      int max=0;
327

  
328
      for (ScrambleState mState : mStates)
329
        {
330
        int tmp = mState.getTotal(-1);
331
        if (max < tmp) max = tmp;
332
        }
298 333

  
299
    if( curr==0 ) mLastRot = rnd.nextInt(4);
334
      mNumOccurences = new int[max];
335
      }
336

  
337
    for(int i=0; i<NUM_AXIS; i++)
338
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
339
    }
340

  
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
// PUBLIC API
300 343

  
301
    switch(mLastRot)
344
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
345
    {
346
    if( curr==0 )
302 347
      {
303
      case LAST_SL: layer = rnd.nextInt(2);
304
                    nextAngle = rnd.nextInt(12)-6;
305

  
306
                    if( nextAngle==0 )
307
                      {
308
                      layer = 1-layer;
309
                      nextAngle = (2*rnd.nextInt(2)-1)*(rnd.nextInt(5)+1);
310
                      }
311

  
312
                    scramble[curr][0] = 0;
313
                    scramble[curr][1] = 2*layer;
314
                    scramble[curr][2] = nextAngle;
315
                    mLastRot = layer==0 ? LAST_LO : LAST_UP;
316
                    break;
317
      case LAST_LO:
318
      case LAST_UP: layer = mLastRot==LAST_LO ? 1:0;
319
                    nextAngle = rnd.nextInt(12)-6;
320

  
321
                    if( nextAngle!=0 )
322
                      {
323
                      scramble[curr][0] = 0;
324
                      scramble[curr][1] = 2*layer;
325
                      scramble[curr][2] = nextAngle;
326
                      mLastRot = LAST_UL;
327
                      }
328
                    else
329
                      {
330
                      scramble[curr][0] = 1;
331
                      scramble[curr][1] = rnd.nextInt(2);
332
                      scramble[curr][2] = 1;
333
                      mLastRot = LAST_SL;
334
                      }
335
                    break;
336
      case LAST_UL: scramble[curr][0] = 1;
337
                    scramble[curr][1] = rnd.nextInt(2);
338
                    scramble[curr][2] = 1;
339
                    mLastRot = LAST_SL;
340
                    break;
348
      mCurrState     = 0;
349
      mIndexExcluded =-1;
350
      initializeScrambling();
341 351
      }
352

  
353
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
354

  
355
    scramble[curr][0] = info[0];
356
    scramble[curr][1] = info[1];
357
    scramble[curr][2] = info[2];
358

  
359
    mCurrState     = info[3];
360
    mIndexExcluded = info[0];
342 361
    }
343 362

  
344 363
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff