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/TwistyDiamond.java
291 291

  
292 292
///////////////////////////////////////////////////////////////////////////////////////////////////
293 293

  
294
  public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow,
295
                                   int numScramble, int remScrambles, int remDoubleScrambles)
294
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
296 295
    {
297
    if( numScramble==1 )
296
    if( num==0 )
298 297
      {
299
      scramble[0] = rnd.nextInt(ROTATION_AXIS.length);
298
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
300 299
      }
301 300
    else
302 301
      {
303 302
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
304
      scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
303
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
305 304
      }
306 305

  
307 306
    float rowFloat = rnd.nextFloat();
......
310 309
      {
311 310
      if( rowFloat<=mRowChances[row] )
312 311
        {
313
        scramble[1] = row;
312
        scramble[num][1] = row;
314 313
        break;
315 314
        }
316 315
      }
317 316

  
318
    int random = rnd.nextInt(remScrambles);
319
    int result = random<remDoubleScrambles ? 2:1;
320
    int sign   = rnd.nextInt(2);
321

  
322
    scramble[2] = sign==0 ? result : -result;
317
    switch( rnd.nextInt(2) )
318
      {
319
      case 0: scramble[num][2] = -1; break;
320
      case 1: scramble[num][2] =  1; break;
321
      }
323 322
    }
324 323

  
325 324
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff