Project

General

Profile

« Previous | Next » 

Revision e844c116

Added by Leszek Koltunski about 4 years ago

Beginnings of Pyraminx.

View differences:

src/main/java/org/distorted/effect/scramble/ScrambleEffect.java
70 70
  private long mDurationSingleTurn;
71 71
  private Random mRnd;
72 72
  private RubikObject mObject;
73
  private int mNumAxis;
74
  private int mBasicAngle;
73 75

  
74 76
  Effect[] mNodeEffects;
75 77
  int[] mNodeEffectPosition;
......
82 84
  ScrambleEffect()
83 85
    {
84 86
    mRnd = new Random( System.currentTimeMillis() );
85
    mLastVector = 3;
87
    mLastVector = -2;
86 88
    }
87 89

  
88 90
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 95
///////////////////////////////////////////////////////////////////////////////////////////////////
94 96
// first compute how many out of 'numScrambles' are double turns (this will matter when we compute
95 97
// the time a single quarter-turn takes!
98
//
99
// Only works for
100
// basicAngle==4, i.e. something whose rotations are by 90 degrees (RubikCube) or
101
// basicAngle==3, i.e. something whose rotations are by 120 degrees (a Pyramix) or
102
// basicAngle==2, i.e. something whose rotations are by 180 degrees (is there something like that?)
96 103

  
97 104
  private void createBaseEffects(int duration, int numScrambles)
98 105
    {
......
100 107

  
101 108
    mNumDoubleScramblesLeft=0;
102 109

  
103
    for(int i=0; i<numScrambles; i++)
110
    if( mBasicAngle>=4 )
104 111
      {
105
      if( (mRnd.nextInt() % 3) == 0 )
112
      for(int i=0; i<numScrambles; i++)
106 113
        {
107
        mNumDoubleScramblesLeft++;
114
        if( (mRnd.nextInt() % 3) == 0 )
115
          {
116
          mNumDoubleScramblesLeft++;
117
          }
108 118
        }
109 119
      }
110 120

  
......
114 124
    }
115 125

  
116 126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// only works if basicAngle<=4, i.e. wont work for something whose basic rotations are by less
128
// than 90 degrees.
117 129

  
118 130
  private void addNewScramble()
119 131
    {
120 132
    if( mNumScramblesLeft>0 )
121 133
      {
122
      if( mLastVector == 3 )
134
      if( mLastVector == -2 )
123 135
        {
124
        mLastVector = mRnd.nextInt(3);
136
        mLastVector = mRnd.nextInt(mNumAxis);
125 137
        }
126 138
      else
127 139
        {
128
        int newVector = mRnd.nextInt(2);
129

  
130
        switch(mLastVector)
131
          {
132
          case 0: mLastVector = (newVector==0 ? 1:2); break;
133
          case 1: mLastVector = (newVector==0 ? 0:2); break;
134
          case 2: mLastVector = (newVector==0 ? 0:1); break;
135
          }
140
        int newVector = mRnd.nextInt(mNumAxis-1);
141
        mLastVector = (newVector>=mLastVector ? newVector+1 : newVector);
136 142
        }
137 143

  
138 144
      int row  = mRnd.nextInt(mObject.getSize());
......
162 168
    }
163 169

  
164 170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
// only works for basicAngle==4, i.e. RubikCube or basicAngle==3, i.e. a Pyramix.
165 172

  
166 173
  private int randomizeAngle()
167 174
    {
......
301 308

  
302 309
    mObject.solve();
303 310

  
311
    mNumAxis    = mObject.getNumAxis();
312
    mBasicAngle = mObject.getBasicAngle();
313

  
304 314
    int numScrambles = renderer.getNumScrambles();
305 315
    int dura = (int)(duration*Math.pow(numScrambles,0.6f));
306 316
    createBaseEffects(dura,numScrambles);

Also available in: Unified diff