Project

General

Profile

« Previous | Next » 

Revision 91792184

Added by Leszek Koltunski over 2 years ago

Make object scrambling abstract (well, almost - with exception of Square-1 - this theoretically could also be done the generic way, but this would require almost 20000 'ScrambleStates')

View differences:

src/main/java/org/distorted/objects/TwistyRedi.java
31 31
import org.distorted.library.type.Static4D;
32 32
import org.distorted.main.R;
33 33

  
34
import java.util.Random;
35

  
36 34
///////////////////////////////////////////////////////////////////////////////////////////////////
37 35

  
38 36
public class TwistyRedi extends TwistyObject
......
55 53

  
56 54
  private static final int FACES_PER_CUBIT =9;
57 55

  
58
  private int mCurrState;
59
  private int mIndexExcluded;
60
  private final ScrambleState[] mStates;
61
  private int[][] mScrambleTable;
62
  private int[] mNumOccurences;
56
  private ScrambleState[] mStates;
63 57
  private int[] mBasicAngle;
64 58
  private Static4D[] mQuats;
65 59
  private float[][] mCenters;
......
72 66
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
73 67
    {
74 68
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
69
    }
75 70

  
76
    mStates = new ScrambleState[]
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
  ScrambleState[] getScrambleStates()
74
    {
75
    if( mStates==null )
77 76
      {
78
      new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
79
      new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
80
      new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
81
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
82
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
83
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
84
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
85
      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
86
      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
87
      };
77
      mStates = new ScrambleState[]
78
        {
79
        new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
80
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
81
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
82
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
83
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
84
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
85
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
86
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
87
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
88
        };
89
      }
90

  
91
    return mStates;
88 92
    }
89 93

  
90 94
///////////////////////////////////////////////////////////////////////////////////////////////////
......
419 423
    return 2.0f;
420 424
    }
421 425

  
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

  
424
  private void initializeScrambling()
425
    {
426
    int numLayers = getNumLayers();
427

  
428
    if( mScrambleTable ==null )
429
      {
430
      mScrambleTable = new int[NUM_AXIS][numLayers];
431
      }
432
    if( mNumOccurences ==null )
433
      {
434
      int max=0;
435

  
436
      for (ScrambleState mState : mStates)
437
        {
438
        int tmp = mState.getTotal(-1);
439
        if (max < tmp) max = tmp;
440
        }
441

  
442
      mNumOccurences = new int[max];
443
      }
444

  
445
    for(int i=0; i<NUM_AXIS; i++)
446
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
447
    }
448

  
449 426
///////////////////////////////////////////////////////////////////////////////////////////////////
450 427
// PUBLIC API
451 428

  
452
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
453
    {
454
    if( curr==0 )
455
      {
456
      mCurrState     = 0;
457
      mIndexExcluded =-1;
458
      initializeScrambling();
459
      }
460

  
461
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
462

  
463
    scramble[curr][0] = info[0];
464
    scramble[curr][1] = info[1];
465
    scramble[curr][2] = info[2];
466

  
467
    mCurrState     = info[3];
468
    mIndexExcluded = info[0];
469
    }
470

  
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

  
473 429
  public Static3D[] getRotationAxis()
474 430
    {
475 431
    return ROT_AXIS;

Also available in: Unified diff