Revision 5043d5d0
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/effects/scramble/ScrambleEffect.java | ||
---|---|---|
26 | 26 |
import org.distorted.library.message.EffectListener; |
27 | 27 |
import org.distorted.main.RubikPreRender; |
28 | 28 |
import org.distorted.effects.EffectController; |
29 |
import org.distorted.objects.ObjectList; |
|
29 | 30 |
import org.distorted.objects.TwistyObject; |
30 | 31 |
|
31 | 32 |
import java.lang.reflect.Method; |
... | ... | |
64 | 65 |
} |
65 | 66 |
} |
66 | 67 |
|
67 |
private static final int START_AXIS = -2; |
|
68 |
private static final int STOP_AXIS = -1; |
|
69 |
|
|
70 | 68 |
private EffectController mController; |
71 | 69 |
private int mEffectReturned; |
72 | 70 |
private int mNumDoubleScramblesLeft, mNumScramblesLeft; |
73 |
private int mLastRotAxis, mLastRow; |
|
74 | 71 |
private long mDurationSingleTurn; |
75 | 72 |
private final Random mRnd; |
76 | 73 |
private int mBasicAngle; |
... | ... | |
82 | 79 |
int[] mCubeEffectPosition; |
83 | 80 |
int mCubeEffectNumber, mNodeEffectNumber; |
84 | 81 |
int mNumScrambles; |
85 |
int[] mScramble;
|
|
82 |
int[][] mScrambles;
|
|
86 | 83 |
|
87 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
88 | 85 |
|
89 | 86 |
ScrambleEffect() |
90 | 87 |
{ |
91 | 88 |
mRnd = new Random( System.currentTimeMillis() ); |
92 |
mScramble = new int[3]; |
|
93 |
mLastRotAxis = START_AXIS; |
|
89 |
mScrambles = new int[ObjectList.MAX_LEVEL][3]; |
|
94 | 90 |
} |
95 | 91 |
|
96 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 107 |
private void createBaseEffects(int duration, int numScrambles) |
112 | 108 |
{ |
113 | 109 |
mNumScramblesLeft = numScrambles; |
114 |
|
|
115 | 110 |
mNumDoubleScramblesLeft=0; |
116 | 111 |
|
117 |
if( mBasicAngle>=4 )
|
|
112 |
for(int scramble=0; scramble<mNumScramblesLeft; scramble++)
|
|
118 | 113 |
{ |
119 |
int chance = mBasicAngle==4 ? 3:2; |
|
120 |
|
|
121 |
for(int i=0; i<numScrambles; i++) |
|
122 |
{ |
|
123 |
if( (mRnd.nextInt() % chance) == 0 ) |
|
124 |
{ |
|
125 |
mNumDoubleScramblesLeft++; |
|
126 |
} |
|
127 |
} |
|
114 |
mObject.randomizeNewScramble(mScrambles, mRnd, scramble); |
|
115 |
int angle = mScrambles[scramble][2]; |
|
116 |
if( angle==2 || angle==-2 ) mNumDoubleScramblesLeft++; |
|
128 | 117 |
} |
129 | 118 |
|
130 | 119 |
mDurationSingleTurn = duration/(mNumScramblesLeft+mNumDoubleScramblesLeft); |
... | ... | |
140 | 129 |
{ |
141 | 130 |
if( mNumScramblesLeft>0 ) |
142 | 131 |
{ |
143 |
mNumScrambles++; |
|
144 |
|
|
145 |
mObject.randomizeNewScramble(mScramble, mRnd,mLastRotAxis, mLastRow, mNumScrambles, |
|
146 |
mNumScramblesLeft, mNumDoubleScramblesLeft); |
|
147 |
mLastRotAxis = mScramble[0]; |
|
148 |
mLastRow = mScramble[1]; |
|
149 |
int angle = mScramble[2]; |
|
132 |
int axis = mScrambles[mNumScrambles][0]; |
|
133 |
int row = mScrambles[mNumScrambles][1]; |
|
134 |
int angle= mScrambles[mNumScrambles][2]; |
|
150 | 135 |
|
151 |
int rowBitmap = (1<<mLastRow);
|
|
136 |
int rowBitmap = (1<<row);
|
|
152 | 137 |
int absAngle = (angle<0 ? -angle : angle); |
153 | 138 |
long durationMillis = absAngle*mDurationSingleTurn; |
154 | 139 |
|
... | ... | |
160 | 145 |
android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft); |
161 | 146 |
} |
162 | 147 |
|
163 |
mController.addRotation(this, mLastRotAxis, rowBitmap, angle*(360/mBasicAngle), durationMillis); |
|
148 |
mController.addRotation(this, axis, rowBitmap, angle*(360/mBasicAngle), durationMillis); |
|
149 |
|
|
150 |
mNumScrambles++; |
|
164 | 151 |
} |
165 | 152 |
else |
166 | 153 |
{ |
167 |
mLastRotAxis = STOP_AXIS; |
|
168 |
|
|
169 | 154 |
if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber ) |
170 | 155 |
{ |
171 | 156 |
mController.effectFinished(FAKE_EFFECT_ID); |
src/main/java/org/distorted/objects/TwistyBandaged2Bar.java | ||
---|---|---|
101 | 101 |
// PUBLIC API |
102 | 102 |
// TODO |
103 | 103 |
|
104 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
105 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
104 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
106 | 105 |
{ |
107 |
if( numScramble==1 )
|
|
106 |
if( num==0 )
|
|
108 | 107 |
{ |
109 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
108 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
110 | 109 |
} |
111 | 110 |
else |
112 | 111 |
{ |
113 | 112 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
114 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
113 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
115 | 114 |
} |
116 | 115 |
|
117 | 116 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
120 | 119 |
{ |
121 | 120 |
if( rowFloat<=mRowChances[row] ) |
122 | 121 |
{ |
123 |
scramble[1] = row; |
|
122 |
scramble[num][1] = row;
|
|
124 | 123 |
break; |
125 | 124 |
} |
126 | 125 |
} |
127 | 126 |
|
128 |
int random = rnd.nextInt(remScrambles); |
|
129 |
int result = random<remDoubleScrambles ? 2:1; |
|
130 |
int sign = rnd.nextInt(2); |
|
131 |
|
|
132 |
scramble[2] = sign==0 ? result : -result; |
|
127 |
switch( rnd.nextInt(4) ) |
|
128 |
{ |
|
129 |
case 0: scramble[num][2] = -2; break; |
|
130 |
case 1: scramble[num][2] = -1; break; |
|
131 |
case 2: scramble[num][2] = 1; break; |
|
132 |
case 3: scramble[num][2] = 2; break; |
|
133 |
} |
|
133 | 134 |
} |
134 | 135 |
|
135 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyBandaged3Plate.java | ||
---|---|---|
107 | 107 |
// PUBLIC API |
108 | 108 |
// TODO |
109 | 109 |
|
110 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
111 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
110 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
112 | 111 |
{ |
113 |
if( numScramble==1 )
|
|
112 |
if( num==0 )
|
|
114 | 113 |
{ |
115 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
114 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
116 | 115 |
} |
117 | 116 |
else |
118 | 117 |
{ |
119 | 118 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
120 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
119 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
121 | 120 |
} |
122 | 121 |
|
123 | 122 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
126 | 125 |
{ |
127 | 126 |
if( rowFloat<=mRowChances[row] ) |
128 | 127 |
{ |
129 |
scramble[1] = row; |
|
128 |
scramble[num][1] = row;
|
|
130 | 129 |
break; |
131 | 130 |
} |
132 | 131 |
} |
133 | 132 |
|
134 |
int random = rnd.nextInt(remScrambles); |
|
135 |
int result = random<remDoubleScrambles ? 2:1; |
|
136 |
int sign = rnd.nextInt(2); |
|
137 |
|
|
138 |
scramble[2] = sign==0 ? result : -result; |
|
133 |
switch( rnd.nextInt(4) ) |
|
134 |
{ |
|
135 |
case 0: scramble[num][2] = -2; break; |
|
136 |
case 1: scramble[num][2] = -1; break; |
|
137 |
case 2: scramble[num][2] = 1; break; |
|
138 |
case 3: scramble[num][2] = 2; break; |
|
139 |
} |
|
139 | 140 |
} |
140 | 141 |
|
141 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyBandagedEvil.java | ||
---|---|---|
119 | 119 |
// PUBLIC API |
120 | 120 |
// TODO |
121 | 121 |
|
122 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
123 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
122 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
124 | 123 |
{ |
125 |
if( numScramble==1 )
|
|
124 |
if( num==0 )
|
|
126 | 125 |
{ |
127 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
126 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
128 | 127 |
} |
129 | 128 |
else |
130 | 129 |
{ |
131 | 130 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
132 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
131 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
133 | 132 |
} |
134 | 133 |
|
135 | 134 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
138 | 137 |
{ |
139 | 138 |
if( rowFloat<=mRowChances[row] ) |
140 | 139 |
{ |
141 |
scramble[1] = row; |
|
140 |
scramble[num][1] = row;
|
|
142 | 141 |
break; |
143 | 142 |
} |
144 | 143 |
} |
145 | 144 |
|
146 |
int random = rnd.nextInt(remScrambles); |
|
147 |
int result = random<remDoubleScrambles ? 2:1; |
|
148 |
int sign = rnd.nextInt(2); |
|
149 |
|
|
150 |
scramble[2] = sign==0 ? result : -result; |
|
145 |
switch( rnd.nextInt(4) ) |
|
146 |
{ |
|
147 |
case 0: scramble[num][2] = -2; break; |
|
148 |
case 1: scramble[num][2] = -1; break; |
|
149 |
case 2: scramble[num][2] = 1; break; |
|
150 |
case 3: scramble[num][2] = 2; break; |
|
151 |
} |
|
151 | 152 |
} |
152 | 153 |
|
153 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyBandagedFused.java | ||
---|---|---|
100 | 100 |
|
101 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 102 |
|
103 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
104 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
103 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
105 | 104 |
{ |
106 |
if( numScramble==1 )
|
|
105 |
if( num==0 )
|
|
107 | 106 |
{ |
108 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
107 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
109 | 108 |
} |
110 | 109 |
else |
111 | 110 |
{ |
112 | 111 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
113 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
112 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
114 | 113 |
} |
115 | 114 |
|
116 | 115 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
119 | 118 |
{ |
120 | 119 |
if( rowFloat<=mRowChances[row] ) |
121 | 120 |
{ |
122 |
scramble[1] = row; |
|
121 |
scramble[num][1] = row;
|
|
123 | 122 |
break; |
124 | 123 |
} |
125 | 124 |
} |
126 | 125 |
|
127 |
int random = rnd.nextInt(remScrambles); |
|
128 |
int result = random<remDoubleScrambles ? 2:1; |
|
129 |
int sign = rnd.nextInt(2); |
|
130 |
|
|
131 |
scramble[2] = sign==0 ? result : -result; |
|
126 |
switch( rnd.nextInt(4) ) |
|
127 |
{ |
|
128 |
case 0: scramble[num][2] = -2; break; |
|
129 |
case 1: scramble[num][2] = -1; break; |
|
130 |
case 2: scramble[num][2] = 1; break; |
|
131 |
case 3: scramble[num][2] = 2; break; |
|
132 |
} |
|
132 | 133 |
} |
133 | 134 |
|
134 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyCube.java | ||
---|---|---|
254 | 254 |
|
255 | 255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
256 | 256 |
|
257 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
258 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
257 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
259 | 258 |
{ |
260 |
if( numScramble==1 )
|
|
259 |
if( num==0 )
|
|
261 | 260 |
{ |
262 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
261 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
263 | 262 |
} |
264 | 263 |
else |
265 | 264 |
{ |
266 | 265 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
267 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
266 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
268 | 267 |
} |
269 | 268 |
|
270 | 269 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
273 | 272 |
{ |
274 | 273 |
if( rowFloat<=mRowChances[row] ) |
275 | 274 |
{ |
276 |
scramble[1] = row; |
|
275 |
scramble[num][1] = row;
|
|
277 | 276 |
break; |
278 | 277 |
} |
279 | 278 |
} |
280 | 279 |
|
281 |
int random = rnd.nextInt(remScrambles); |
|
282 |
int result = random<remDoubleScrambles ? 2:1; |
|
283 |
int sign = rnd.nextInt(2); |
|
284 |
|
|
285 |
scramble[2] = sign==0 ? result : -result; |
|
280 |
switch( rnd.nextInt(4) ) |
|
281 |
{ |
|
282 |
case 0: scramble[num][2] = -2; break; |
|
283 |
case 1: scramble[num][2] = -1; break; |
|
284 |
case 2: scramble[num][2] = 1; break; |
|
285 |
case 3: scramble[num][2] = 2; break; |
|
286 |
} |
|
286 | 287 |
} |
287 | 288 |
|
288 | 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
291 | 291 |
|
292 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
293 | 293 |
|
294 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
295 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
294 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
296 | 295 |
{ |
297 |
if( numScramble==1 )
|
|
296 |
if( num==0 )
|
|
298 | 297 |
{ |
299 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
298 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
300 | 299 |
} |
301 | 300 |
else |
302 | 301 |
{ |
303 | 302 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
304 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
303 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
305 | 304 |
} |
306 | 305 |
|
307 | 306 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
310 | 309 |
{ |
311 | 310 |
if( rowFloat<=mRowChances[row] ) |
312 | 311 |
{ |
313 |
scramble[1] = row; |
|
312 |
scramble[num][1] = row;
|
|
314 | 313 |
break; |
315 | 314 |
} |
316 | 315 |
} |
317 | 316 |
|
318 |
int random = rnd.nextInt(remScrambles);
|
|
319 |
int result = random<remDoubleScrambles ? 2:1;
|
|
320 |
int sign = rnd.nextInt(2);
|
|
321 |
|
|
322 |
scramble[2] = sign==0 ? result : -result;
|
|
317 |
switch( rnd.nextInt(2) )
|
|
318 |
{
|
|
319 |
case 0: scramble[num][2] = -1; break;
|
|
320 |
case 1: scramble[num][2] = 1; break; |
|
321 |
}
|
|
323 | 322 |
} |
324 | 323 |
|
325 | 324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyDino4.java | ||
---|---|---|
66 | 66 |
|
67 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 68 |
|
69 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
70 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
69 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
71 | 70 |
{ |
72 |
if( numScramble==1 )
|
|
71 |
if( num==0 )
|
|
73 | 72 |
{ |
74 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
73 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length); |
|
74 |
scramble[num][1] = (scramble[num][0]==1 || scramble[num][0]==2) ? 0:2; |
|
75 | 75 |
} |
76 | 76 |
else |
77 | 77 |
{ |
78 | 78 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
79 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
79 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector); |
|
80 |
scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1]; |
|
80 | 81 |
} |
81 | 82 |
|
82 |
scramble[1] = (numScramble==1) ? ((scramble[0]==1 || scramble[0]==2) ? 0:2) : (oldRotAxis+scramble[0]==3 ? 2-oldRow : oldRow); |
|
83 |
|
|
84 |
int random = rnd.nextInt(remScrambles); |
|
85 |
int result = random<remDoubleScrambles ? 2:1; |
|
86 |
int sign = rnd.nextInt(2); |
|
87 |
|
|
88 |
scramble[2] = sign==0 ? result : -result; |
|
83 |
switch( rnd.nextInt(2) ) |
|
84 |
{ |
|
85 |
case 0: scramble[num][2] = -1; break; |
|
86 |
case 1: scramble[num][2] = 1; break; |
|
87 |
} |
|
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyDino6.java | ||
---|---|---|
66 | 66 |
|
67 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 68 |
|
69 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
70 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
69 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
71 | 70 |
{ |
72 |
if( numScramble==1 )
|
|
71 |
if( num==0 )
|
|
73 | 72 |
{ |
74 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
73 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length); |
|
74 |
scramble[num][1] = rnd.nextFloat()<=0.5f ? 0:2; |
|
75 | 75 |
} |
76 | 76 |
else |
77 | 77 |
{ |
78 | 78 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
79 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
79 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector); |
|
80 |
scramble[num][1] = scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1]; |
|
80 | 81 |
} |
81 | 82 |
|
82 |
scramble[1] = (numScramble==1) ? (rnd.nextFloat()<=0.5f ? 0:2) : (oldRotAxis+scramble[0]==3 ? 2-oldRow : oldRow); |
|
83 |
|
|
84 |
int random = rnd.nextInt(remScrambles); |
|
85 |
int result = random<remDoubleScrambles ? 2:1; |
|
86 |
int sign = rnd.nextInt(2); |
|
87 |
|
|
88 |
scramble[2] = sign==0 ? result : -result; |
|
83 |
switch( rnd.nextInt(2) ) |
|
84 |
{ |
|
85 |
case 0: scramble[num][2] = -1; break; |
|
86 |
case 1: scramble[num][2] = 1; break; |
|
87 |
} |
|
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyHelicopter.java | ||
---|---|---|
335 | 335 |
|
336 | 336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
337 | 337 |
|
338 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
339 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
338 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
340 | 339 |
{ |
341 |
if( numScramble==1 )
|
|
340 |
if( num==0 )
|
|
342 | 341 |
{ |
343 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
342 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
344 | 343 |
} |
345 | 344 |
else |
346 | 345 |
{ |
347 | 346 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-2); |
348 | 347 |
|
349 |
switch(oldRotAxis)
|
|
348 |
switch(scramble[num-1][0])
|
|
350 | 349 |
{ |
351 | 350 |
case 0: |
352 |
case 1: scramble[0] = newVector+2; |
|
351 |
case 1: scramble[num][0] = newVector+2;
|
|
353 | 352 |
break; |
354 | 353 |
case 2: |
355 |
case 3: scramble[0] = (newVector==0 || newVector==1) ? newVector:newVector+2; |
|
354 |
case 3: scramble[num][0] = (newVector==0 || newVector==1) ? newVector:newVector+2;
|
|
356 | 355 |
break; |
357 |
default: scramble[0] = newVector; |
|
356 |
default: scramble[num][0] = newVector;
|
|
358 | 357 |
break; |
359 | 358 |
} |
360 | 359 |
} |
... | ... | |
365 | 364 |
{ |
366 | 365 |
if( rowFloat<=mRowChances[row] ) |
367 | 366 |
{ |
368 |
scramble[1] = row; |
|
367 |
scramble[num][1] = row;
|
|
369 | 368 |
break; |
370 | 369 |
} |
371 | 370 |
} |
372 | 371 |
|
373 |
int random = rnd.nextInt(remScrambles);
|
|
374 |
int result = random<remDoubleScrambles ? 2:1;
|
|
375 |
int sign = rnd.nextInt(2);
|
|
376 |
|
|
377 |
scramble[2] = sign==0 ? result : -result;
|
|
372 |
switch( rnd.nextInt(2) )
|
|
373 |
{
|
|
374 |
case 0: scramble[num][2] = -1; break;
|
|
375 |
case 1: scramble[num][2] = 1; break; |
|
376 |
}
|
|
378 | 377 |
} |
379 | 378 |
|
380 | 379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyIvy.java | ||
---|---|---|
281 | 281 |
|
282 | 282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
283 | 283 |
|
284 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
285 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
284 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
286 | 285 |
{ |
287 |
if( numScramble==1 )
|
|
286 |
if( num==0 )
|
|
288 | 287 |
{ |
289 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
288 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
290 | 289 |
} |
291 | 290 |
else |
292 | 291 |
{ |
293 | 292 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
294 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
293 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
295 | 294 |
} |
296 | 295 |
|
297 | 296 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
300 | 299 |
{ |
301 | 300 |
if( rowFloat<=mRowChances[row] ) |
302 | 301 |
{ |
303 |
scramble[1] = row; |
|
302 |
scramble[num][1] = row;
|
|
304 | 303 |
break; |
305 | 304 |
} |
306 | 305 |
} |
307 | 306 |
|
308 |
int random = rnd.nextInt(remScrambles);
|
|
309 |
int result = random<remDoubleScrambles ? 2:1;
|
|
310 |
int sign = rnd.nextInt(2);
|
|
311 |
|
|
312 |
scramble[2] = sign==0 ? result : -result;
|
|
307 |
switch( rnd.nextInt(2) )
|
|
308 |
{
|
|
309 |
case 0: scramble[num][2] = -1; break;
|
|
310 |
case 1: scramble[num][2] = 1; break; |
|
311 |
}
|
|
313 | 312 |
} |
314 | 313 |
|
315 | 314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
280 | 280 |
|
281 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
282 | 282 |
|
283 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
284 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
283 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
285 | 284 |
{ |
286 |
if( numScramble==1 )
|
|
285 |
if( num==0 )
|
|
287 | 286 |
{ |
288 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
287 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
289 | 288 |
} |
290 | 289 |
else |
291 | 290 |
{ |
292 | 291 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
293 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
292 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
294 | 293 |
} |
295 | 294 |
|
296 |
if( numScramble==1 )
|
|
295 |
if( num==0 )
|
|
297 | 296 |
{ |
298 | 297 |
float rowFloat = rnd.nextFloat(); |
299 | 298 |
|
... | ... | |
301 | 300 |
{ |
302 | 301 |
if( rowFloat<=mRowChances[row] ) |
303 | 302 |
{ |
304 |
scramble[1] = row; |
|
303 |
scramble[num][1] = row;
|
|
305 | 304 |
break; |
306 | 305 |
} |
307 | 306 |
} |
... | ... | |
309 | 308 |
else |
310 | 309 |
{ |
311 | 310 |
int size = mRowChances.length; |
312 |
int num = (size-1)/2;
|
|
313 |
int row = rnd.nextInt(num);
|
|
314 |
boolean opposite = OPPOSITE_ROWS[oldRotAxis][scramble[0]];
|
|
315 |
boolean low = opposite^(oldRow<num);
|
|
316 |
scramble[1] = low ? row : size-1-row; |
|
311 |
int nom = (size-1)/2;
|
|
312 |
int row = rnd.nextInt(nom);
|
|
313 |
boolean opposite = OPPOSITE_ROWS[scramble[num-1][0]][scramble[num][0]];
|
|
314 |
boolean low = opposite^(scramble[num-1][1]<nom);
|
|
315 |
scramble[num][1] = low ? row : size-1-row;
|
|
317 | 316 |
} |
318 | 317 |
|
319 |
int random = rnd.nextInt(remScrambles); |
|
320 |
int result = random<remDoubleScrambles ? 2:1; |
|
321 |
int sign = rnd.nextInt(2); |
|
322 |
|
|
323 |
scramble[2] = sign==0 ? result : -result; |
|
318 |
switch( rnd.nextInt(4) ) |
|
319 |
{ |
|
320 |
case 0: scramble[num][2] = -2; break; |
|
321 |
case 1: scramble[num][2] = -1; break; |
|
322 |
case 2: scramble[num][2] = 1; break; |
|
323 |
case 3: scramble[num][2] = 2; break; |
|
324 |
} |
|
324 | 325 |
} |
325 | 326 |
|
326 | 327 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
913 | 913 |
public abstract Static3D[] getRotationAxis(); |
914 | 914 |
public abstract int getBasicAngle(); |
915 | 915 |
public abstract String retObjectString(); |
916 |
public abstract void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, int numScramble, int remScrambles, int remDoubleScrambles);
|
|
916 |
public abstract void randomizeNewScramble(int[][] scramble, Random rnd, int numScramble);
|
|
917 | 917 |
public abstract int getObjectName(int numLayers); |
918 | 918 |
public abstract int getInventor(int numLayers); |
919 | 919 |
public abstract int getComplexity(int numLayers); |
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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyRedi.java | ||
---|---|---|
328 | 328 |
|
329 | 329 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
330 | 330 |
|
331 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
332 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
331 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
333 | 332 |
{ |
334 |
if( numScramble==1 )
|
|
333 |
if( num==0 )
|
|
335 | 334 |
{ |
336 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
335 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length); |
|
336 |
scramble[num][1] = rnd.nextFloat()<=0.5f ? 0:2; |
|
337 | 337 |
} |
338 | 338 |
else |
339 | 339 |
{ |
340 | 340 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
341 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
341 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector); |
|
342 |
scramble[num][1] = (scramble[num-1][0]+scramble[num][0]==3 ? 2-scramble[num-1][1] : scramble[num-1][1]); |
|
342 | 343 |
} |
343 | 344 |
|
344 |
scramble[1] = (numScramble==1) ? (rnd.nextFloat()<=0.5f ? 0:2) : (oldRotAxis+scramble[0]==3 ? 2-oldRow : oldRow); |
|
345 |
|
|
346 |
int random = rnd.nextInt(remScrambles); |
|
347 |
int result = random<remDoubleScrambles ? 2:1; |
|
348 |
int sign = rnd.nextInt(2); |
|
349 |
|
|
350 |
scramble[2] = sign==0 ? result : -result; |
|
345 |
switch( rnd.nextInt(2) ) |
|
346 |
{ |
|
347 |
case 0: scramble[num][2] = -1; break; |
|
348 |
case 1: scramble[num][2] = 1; break; |
|
349 |
} |
|
351 | 350 |
} |
352 | 351 |
|
353 | 352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyRex.java | ||
---|---|---|
392 | 392 |
|
393 | 393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
394 | 394 |
|
395 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
396 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
395 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
397 | 396 |
{ |
398 |
if( numScramble==1 )
|
|
397 |
if( num==0 )
|
|
399 | 398 |
{ |
400 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
399 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
401 | 400 |
} |
402 | 401 |
else |
403 | 402 |
{ |
404 | 403 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
405 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
404 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
406 | 405 |
} |
407 | 406 |
|
408 | 407 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
411 | 410 |
{ |
412 | 411 |
if( rowFloat<=mRowChances[row] ) |
413 | 412 |
{ |
414 |
scramble[1] = row; |
|
413 |
scramble[num][1] = row;
|
|
415 | 414 |
break; |
416 | 415 |
} |
417 | 416 |
} |
418 | 417 |
|
419 |
int random = rnd.nextInt(remScrambles);
|
|
420 |
int result = random<remDoubleScrambles ? 2:1;
|
|
421 |
int sign = rnd.nextInt(2);
|
|
422 |
|
|
423 |
scramble[2] = sign==0 ? result : -result;
|
|
418 |
switch( rnd.nextInt(2) )
|
|
419 |
{
|
|
420 |
case 0: scramble[num][2] = -1; break;
|
|
421 |
case 1: scramble[num][2] = 1; break; |
|
422 |
}
|
|
424 | 423 |
} |
425 | 424 |
|
426 | 425 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistySkewb.java | ||
---|---|---|
539 | 539 |
|
540 | 540 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
541 | 541 |
|
542 |
public void randomizeNewScramble(int[] scramble, Random rnd, int oldRotAxis, int oldRow, |
|
543 |
int numScramble, int remScrambles, int remDoubleScrambles) |
|
542 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
|
544 | 543 |
{ |
545 |
if( numScramble==1 )
|
|
544 |
if( num==0 )
|
|
546 | 545 |
{ |
547 |
scramble[0] = rnd.nextInt(ROTATION_AXIS.length); |
|
546 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
|
|
548 | 547 |
} |
549 | 548 |
else |
550 | 549 |
{ |
551 | 550 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
552 |
scramble[0] = (newVector>=oldRotAxis ? newVector+1 : newVector);
|
|
551 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
|
|
553 | 552 |
} |
554 | 553 |
|
555 | 554 |
float rowFloat = rnd.nextFloat(); |
... | ... | |
558 | 557 |
{ |
559 | 558 |
if( rowFloat<=mRowChances[row] ) |
560 | 559 |
{ |
561 |
scramble[1] = row; |
|
560 |
scramble[num][1] = row;
|
|
562 | 561 |
break; |
563 | 562 |
} |
564 | 563 |
} |
565 | 564 |
|
566 |
int random = rnd.nextInt(remScrambles);
|
|
567 |
int result = random<remDoubleScrambles ? 2:1;
|
|
568 |
int sign = rnd.nextInt(2);
|
|
569 |
|
|
570 |
scramble[2] = sign==0 ? result : -result;
|
|
565 |
switch( rnd.nextInt(2) )
|
|
566 |
{
|
|
567 |
case 0: scramble[num][2] = -1; break;
|
|
568 |
case 1: scramble[num][2] = 1; break; |
|
569 |
}
|
|
571 | 570 |
} |
572 | 571 |
|
573 | 572 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Refactor the automatic scrambling. From now on, it is not needed to care about single and double turns when randomizing a new turn.