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/TwistyRex.java
392 392

  
393 393
///////////////////////////////////////////////////////////////////////////////////////////////////
394 394

  
395
  public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow,
396
                                   int numScramble, int remScrambles, int remDoubleScrambles)
395
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
397 396
    {
398
    if( numScramble==1 )
397
    if( num==0 )
399 398
      {
400
      scramble[0] = rnd.nextInt(ROTATION_AXIS.length);
399
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
401 400
      }
402 401
    else
403 402
      {
404 403
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
405
      scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
404
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
406 405
      }
407 406

  
408 407
    float rowFloat = rnd.nextFloat();
......
411 410
      {
412 411
      if( rowFloat<=mRowChances[row] )
413 412
        {
414
        scramble[1] = row;
413
        scramble[num][1] = row;
415 414
        break;
416 415
        }
417 416
      }
418 417

  
419
    int random = rnd.nextInt(remScrambles);
420
    int result = random<remDoubleScrambles ? 2:1;
421
    int sign   = rnd.nextInt(2);
422

  
423
    scramble[2] = sign==0 ? result : -result;
418
    switch( rnd.nextInt(2) )
419
      {
420
      case 0: scramble[num][2] = -1; break;
421
      case 1: scramble[num][2] =  1; break;
422
      }
424 423
    }
425 424

  
426 425
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff