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/TwistyPyraminx.java
286 286

  
287 287
///////////////////////////////////////////////////////////////////////////////////////////////////
288 288

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

  
302 301
    float rowFloat = rnd.nextFloat();
......
305 304
      {
306 305
      if( rowFloat<=mRowChances[row] )
307 306
        {
308
        scramble[1] = row;
307
        scramble[num][1] = row;
309 308
        break;
310 309
        }
311 310
      }
312 311

  
313
    int random = rnd.nextInt(remScrambles);
314
    int result = random<remDoubleScrambles ? 2:1;
315
    int sign   = rnd.nextInt(2);
316

  
317
    scramble[2] = sign==0 ? result : -result;
312
    switch( rnd.nextInt(2) )
313
      {
314
      case 0: scramble[num][2] = -1; break;
315
      case 1: scramble[num][2] =  1; break;
316
      }
318 317
    }
319 318

  
320 319
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff