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/TwistyHelicopter.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 TwistyHelicopter extends TwistyObject
......
57 55

  
58 56
  private static final int FACES_PER_CUBIT =6;
59 57

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

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
78 75

  
79
    mStates = new ScrambleState[]
76
  ScrambleState[] getScrambleStates()
77
    {
78
    if( mStates==null )
80 79
      {
81
      new ScrambleState( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
82
      new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
83
      new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
84
      new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
85
      new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
86
      new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
87
      new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
88
      new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
89
      new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
90
      new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
91
      new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
92
      new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
93
      new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
94
      };
80
      mStates = new ScrambleState[]
81
        {
82
        new ScrambleState( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
83
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
84
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
85
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
86
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
87
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
88
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
89
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
90
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
91
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
92
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
93
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
94
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
95
        };
96
      }
97

  
98
    return mStates;
95 99
    }
96 100

  
97 101
///////////////////////////////////////////////////////////////////////////////////////////////////
......
423 427
    return 2.0f;
424 428
    }
425 429

  
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

  
428
  private void initializeScrambling()
429
    {
430
    int numLayers = getNumLayers();
431

  
432
    if( mScrambleTable ==null )
433
      {
434
      mScrambleTable = new int[NUM_AXIS][numLayers];
435
      }
436
    if( mNumOccurences ==null )
437
      {
438
      int max=0;
439

  
440
      for (ScrambleState mState : mStates)
441
        {
442
        int tmp = mState.getTotal(-1);
443
        if (max < tmp) max = tmp;
444
        }
445

  
446
      mNumOccurences = new int[max];
447
      }
448

  
449
    for(int i=0; i<NUM_AXIS; i++)
450
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
451
    }
452

  
453 430
///////////////////////////////////////////////////////////////////////////////////////////////////
454 431
// PUBLIC API
455 432

  
456
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
457
    {
458
    if( curr==0 )
459
      {
460
      mCurrState     = 0;
461
      mIndexExcluded =-1;
462
      initializeScrambling();
463
      }
464

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

  
467
    scramble[curr][0] = info[0];
468
    scramble[curr][1] = info[1];
469
    scramble[curr][2] = info[2];
470

  
471
    mCurrState     = info[3];
472
    mIndexExcluded = info[0];
473
    }
474

  
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

  
477 433
  public Static3D[] getRotationAxis()
478 434
    {
479 435
    return ROT_AXIS;

Also available in: Unified diff