Project

General

Profile

« Previous | Next » 

Revision 486b3417

Added by Leszek Koltunski about 3 years ago

Convert the Diamonds & the Helicopter to the new, unified scrambling method.

View differences:

src/main/java/org/distorted/objects/TwistyDiamond.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;
......
135 136
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
136 137
    }
137 138

  
139
  private int mCurrState;
140
  private int mIndexExcluded;
141
  private final ScrambleStateGraph[] mStates;
142

  
138 143
///////////////////////////////////////////////////////////////////////////////////////////////////
139 144

  
140 145
  TwistyDiamond(int size, Static4D quat, DistortedTexture texture,
141 146
                MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
142 147
    {
143 148
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.DIAM, res, scrWidth);
149

  
150
    int[] tmp = new int[3*2*size];
151

  
152
    for(int i=0; i<2*size; i++)
153
      {
154
      tmp[3*i  ] = (i<size) ?  i:i-size;
155
      tmp[3*i+1] = (i%2==0) ? -1:1;
156
      tmp[3*i+2] = 0;
157
      }
158

  
159
    mStates = new ScrambleStateGraph[]
160
      {
161
      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
162
      };
144 163
    }
145 164

  
146 165
///////////////////////////////////////////////////////////////////////////////////////////////////
......
515 534

  
516 535
///////////////////////////////////////////////////////////////////////////////////////////////////
517 536

  
518
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
537
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
519 538
    {
520 539
    if( curr==0 )
521 540
      {
522
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
523
      }
524
    else
525
      {
526
      int newVector = rnd.nextInt(NUM_AXIS -1);
527
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
541
      mCurrState     = 0;
542
      mIndexExcluded =-1;
528 543
      }
529 544

  
530
    float rowFloat = rnd.nextFloat();
531
    int numLayers = getNumLayers();
545
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
546
    int random= rnd.nextInt(total);
547
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
532 548

  
533
    for(int row=0; row<numLayers; row++)
534
      {
535
      if( rowFloat*numLayers <= row+1 )
536
        {
537
        scramble[curr][1] = row;
538
        break;
539
        }
540
      }
549
    scramble[curr][0] = info[0];
550
    scramble[curr][1] = info[1];
551
    scramble[curr][2] = info[2];
541 552

  
542
    switch( rnd.nextInt(2) )
543
      {
544
      case 0: scramble[curr][2] = -1; break;
545
      case 1: scramble[curr][2] =  1; break;
546
      }
553
    mCurrState     = info[3];
554
    mIndexExcluded = info[0];
547 555
    }
548 556

  
549 557
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyHelicopter.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;
......
235 236
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
236 237
    }
237 238

  
239
  private int mCurrState;
240
  private int mIndexExcluded;
241
  private final ScrambleStateGraph[] mStates;
242

  
238 243
///////////////////////////////////////////////////////////////////////////////////////////////////
239 244

  
240 245
  TwistyHelicopter(int size, Static4D quat, DistortedTexture texture,
241 246
                   MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
242 247
    {
243 248
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
249

  
250
    mStates = new ScrambleStateGraph[]
251
      {
252
      new ScrambleStateGraph( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
253
      new ScrambleStateGraph( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
254
      new ScrambleStateGraph( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
255
      new ScrambleStateGraph( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
256
      new ScrambleStateGraph( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
257
      new ScrambleStateGraph( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
258
      new ScrambleStateGraph( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
259
      new ScrambleStateGraph( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
260
      new ScrambleStateGraph( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
261
      new ScrambleStateGraph( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
262
      new ScrambleStateGraph( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
263
      new ScrambleStateGraph( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
264
      new ScrambleStateGraph( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
265
      };
244 266
    }
245 267

  
246 268
///////////////////////////////////////////////////////////////////////////////////////////////////
......
409 431

  
410 432
///////////////////////////////////////////////////////////////////////////////////////////////////
411 433

  
412
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
434
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
413 435
    {
414 436
    if( curr==0 )
415 437
      {
416
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
417
      }
418
    else
419
      {
420
      int newVector = rnd.nextInt(NUM_AXIS -2);
421

  
422
      switch(scramble[curr-1][0])
423
        {
424
        case  0:
425
        case  1: scramble[curr][0] = newVector+2;
426
                 break;
427
        case  2:
428
        case  3: scramble[curr][0] = (newVector==0 || newVector==1) ? newVector:newVector+2;
429
                 break;
430
        default: scramble[curr][0] = newVector;
431
                 break;
432
        }
438
      mCurrState     = 0;
439
      mIndexExcluded =-1;
433 440
      }
434 441

  
435
    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
442
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
443
    int random= rnd.nextInt(total);
444
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
436 445

  
437
    switch( rnd.nextInt(2) )
438
      {
439
      case 0: scramble[curr][2] = -1; break;
440
      case 1: scramble[curr][2] =  1; break;
441
      }
446
    scramble[curr][0] = info[0];
447
    scramble[curr][1] = info[1];
448
    scramble[curr][2] = info[2];
449

  
450
    mCurrState     = info[3];
451
    mIndexExcluded = info[0];
442 452
    }
443 453

  
444 454
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff