23 |
23 |
|
24 |
24 |
import org.distorted.helpers.ObjectShape;
|
25 |
25 |
import org.distorted.helpers.ObjectSticker;
|
|
26 |
import org.distorted.helpers.ScrambleStateGraph;
|
26 |
27 |
import org.distorted.library.main.DistortedEffects;
|
27 |
28 |
import org.distorted.library.main.DistortedTexture;
|
28 |
29 |
import org.distorted.library.mesh.MeshSquare;
|
... | ... | |
128 |
129 |
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke );
|
129 |
130 |
}
|
130 |
131 |
|
|
132 |
private int mCurrState;
|
|
133 |
private int mIndexExcluded;
|
|
134 |
private final ScrambleStateGraph[] mStates;
|
|
135 |
|
131 |
136 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
137 |
|
133 |
138 |
TwistyCube(int size, Static4D quat, DistortedTexture texture,
|
134 |
139 |
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
135 |
140 |
{
|
136 |
141 |
super(size, size, quat, texture, mesh, effects, moves, ObjectList.CUBE, res, scrWidth);
|
|
142 |
|
|
143 |
int[][] m = new int[16][];
|
|
144 |
for(int i=1; i<16; i++) m[i] = createEdges(size,i);
|
|
145 |
|
|
146 |
mStates = new ScrambleStateGraph[] // built so that all 3 axes must be present in every 4 consecutive moves
|
|
147 |
{
|
|
148 |
new ScrambleStateGraph( new int[][] { m[ 1], m[ 2], m[ 3] } ), // 0
|
|
149 |
new ScrambleStateGraph( new int[][] { null, m[ 4], m[ 5] } ), // x
|
|
150 |
new ScrambleStateGraph( new int[][] { m[ 6], null, m[ 7] } ), // y
|
|
151 |
new ScrambleStateGraph( new int[][] { m[ 8], m[ 8], null } ), // z
|
|
152 |
new ScrambleStateGraph( new int[][] { m[10], null, m[ 7] } ), // xy
|
|
153 |
new ScrambleStateGraph( new int[][] { m[11], m[ 9], null } ), // xz
|
|
154 |
new ScrambleStateGraph( new int[][] { null, m[12], m[ 5] } ), // yx
|
|
155 |
new ScrambleStateGraph( new int[][] { m[ 8], m[13], null } ), // yz
|
|
156 |
new ScrambleStateGraph( new int[][] { null, m[ 4], m[14] } ), // zx
|
|
157 |
new ScrambleStateGraph( new int[][] { m[ 6], null, m[15] } ), // zy
|
|
158 |
new ScrambleStateGraph( new int[][] { null, null, m[ 5] } ), // xyx
|
|
159 |
new ScrambleStateGraph( new int[][] { null, m[ 4], null } ), // xzx
|
|
160 |
new ScrambleStateGraph( new int[][] { null, null, m[ 7] } ), // yxy
|
|
161 |
new ScrambleStateGraph( new int[][] { m[ 6], null, null } ), // yzy
|
|
162 |
new ScrambleStateGraph( new int[][] { null, m[ 9], null } ), // zxz
|
|
163 |
new ScrambleStateGraph( new int[][] { m[ 8], null, null } ), // zyz
|
|
164 |
};
|
|
165 |
}
|
|
166 |
|
|
167 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
168 |
|
|
169 |
private int[] createEdges(int size, int vertex)
|
|
170 |
{
|
|
171 |
int[] ret = new int[9*size];
|
|
172 |
|
|
173 |
for(int l=0; l<size; l++)
|
|
174 |
{
|
|
175 |
ret[9*l ] = l;
|
|
176 |
ret[9*l+1] =-1;
|
|
177 |
ret[9*l+2] = vertex;
|
|
178 |
ret[9*l+3] = l;
|
|
179 |
ret[9*l+4] = 1;
|
|
180 |
ret[9*l+5] = vertex;
|
|
181 |
ret[9*l+6] = l;
|
|
182 |
ret[9*l+7] = 2;
|
|
183 |
ret[9*l+8] = vertex;
|
|
184 |
}
|
|
185 |
|
|
186 |
return ret;
|
137 |
187 |
}
|
138 |
188 |
|
139 |
189 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
322 |
372 |
|
323 |
373 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
324 |
374 |
|
325 |
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
|
375 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
326 |
376 |
{
|
327 |
377 |
if( curr==0 )
|
328 |
378 |
{
|
329 |
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
330 |
|
}
|
331 |
|
else
|
332 |
|
{
|
333 |
|
int newVector = rnd.nextInt(NUM_AXIS-1);
|
334 |
|
scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
|
335 |
|
|
336 |
|
// All three axis must be present among every four consecutive rotations.
|
337 |
|
// Otherwise in case of odd-sized cubes we can get four consecutive rotations
|
338 |
|
// that collapse to a NOP
|
339 |
|
// (X,midLayer,180)->(Y,midLayer,180)->(X,midLayer,180)->(Y,midLayer,180) = NOP
|
340 |
|
if( curr>=3 && scramble[curr-1][0]==scramble[curr-3][0] )
|
341 |
|
{
|
342 |
|
for( int ax=0; ax<NUM_AXIS; ax++)
|
343 |
|
{
|
344 |
|
if( scramble[curr-1][0]!=ax && scramble[curr-2][0]!=ax )
|
345 |
|
{
|
346 |
|
scramble[curr][0] = ax;
|
347 |
|
break;
|
348 |
|
}
|
349 |
|
}
|
350 |
|
}
|
|
379 |
mCurrState = 0;
|
|
380 |
mIndexExcluded =-1;
|
351 |
381 |
}
|
352 |
382 |
|
353 |
|
float rowFloat = rnd.nextFloat();
|
354 |
|
int numLayers = getNumLayers();
|
|
383 |
int total = mStates[mCurrState].getTotal(mIndexExcluded);
|
|
384 |
int random= rnd.nextInt(total);
|
|
385 |
int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
|
355 |
386 |
|
356 |
|
for(int row=0; row<numLayers; row++)
|
357 |
|
{
|
358 |
|
if( rowFloat*numLayers <= row+1 )
|
359 |
|
{
|
360 |
|
scramble[curr][1] = row;
|
361 |
|
break;
|
362 |
|
}
|
363 |
|
}
|
|
387 |
scramble[curr][0] = info[0];
|
|
388 |
scramble[curr][1] = info[1];
|
|
389 |
scramble[curr][2] = info[2];
|
364 |
390 |
|
365 |
|
switch( rnd.nextInt(4) )
|
366 |
|
{
|
367 |
|
case 0: scramble[curr][2] = -2; break;
|
368 |
|
case 1: scramble[curr][2] = -1; break;
|
369 |
|
case 2: scramble[curr][2] = 1; break;
|
370 |
|
case 3: scramble[curr][2] = 2; break;
|
371 |
|
}
|
|
391 |
mCurrState = info[3];
|
|
392 |
mIndexExcluded = info[0];
|
372 |
393 |
}
|
373 |
394 |
|
374 |
395 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Convert the Cubes of all sizes to the new, unified scrambling method.