Project

General

Profile

« Previous | Next » 

Revision 5043d5d0

Added by Leszek Koltunski about 3 years ago

Refactor the automatic scrambling. From now on, it is not needed to care about single and double turns when randomizing a new turn.

View differences:

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

  
329 329
///////////////////////////////////////////////////////////////////////////////////////////////////
330 330

  
331
  public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow,
332
                                   int numScramble, int remScrambles, int remDoubleScrambles)
331
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
333 332
    {
334
    if( numScramble==1 )
333
    if( num==0 )
335 334
      {
336
      scramble[0] = rnd.nextInt(ROTATION_AXIS.length);
335
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
336
      scramble[num][1] = rnd.nextFloat()<=0.5f ? 0:2;
337 337
      }
338 338
    else
339 339
      {
340 340
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
341
      scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
341
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
342
      scramble[num][1] = (scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1]);
342 343
      }
343 344

  
344
    scramble[1] = (numScramble==1) ? (rnd.nextFloat()<=0.5f ? 0:2) : (oldRotAxis+scramble[0]==3 ? 2-oldRow : oldRow);
345

  
346
    int random = rnd.nextInt(remScrambles);
347
    int result = random<remDoubleScrambles ? 2:1;
348
    int sign   = rnd.nextInt(2);
349

  
350
    scramble[2] = sign==0 ? result : -result;
345
    switch( rnd.nextInt(2) )
346
      {
347
      case 0: scramble[num][2] = -1; break;
348
      case 1: scramble[num][2] =  1; break;
349
      }
351 350
    }
352 351

  
353 352
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff