Revision 7c969a6d
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/RubikCube.java | ||
---|---|---|
36 | 36 |
import org.distorted.library.type.Static3D; |
37 | 37 |
import org.distorted.library.type.Static4D; |
38 | 38 |
|
39 |
import java.util.Random; |
|
40 |
|
|
41 |
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS; |
|
42 |
|
|
39 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 44 |
|
41 | 45 |
class RubikCube extends RubikObject |
... | ... | |
314 | 318 |
return getSize(); |
315 | 319 |
} |
316 | 320 |
|
321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
322 |
|
|
323 |
float[] getRowChances() |
|
324 |
{ |
|
325 |
int size = getSize(); |
|
326 |
float[] chances = new float[size]; |
|
327 |
|
|
328 |
for(int i=0; i<size; i++) |
|
329 |
{ |
|
330 |
chances[i] = (i+1.0f) / size; |
|
331 |
} |
|
332 |
|
|
333 |
return chances; |
|
334 |
} |
|
335 |
|
|
317 | 336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
318 | 337 |
// PUBLIC API |
319 | 338 |
|
... | ... | |
338 | 357 |
|
339 | 358 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
340 | 359 |
|
341 |
public float[] getRowChances()
|
|
360 |
public float returnRotationFactor(float offset)
|
|
342 | 361 |
{ |
343 |
int size = getSize();
|
|
344 |
float[] chances = new float[size];
|
|
362 |
return 1.0f;
|
|
363 |
}
|
|
345 | 364 |
|
346 |
for(int i=0; i<size; i++) |
|
365 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
366 |
|
|
367 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
|
368 |
{ |
|
369 |
int numAxis = ROTATION_AXIS.length; |
|
370 |
|
|
371 |
if( oldRotAxis == START_AXIS ) |
|
347 | 372 |
{ |
348 |
chances[i] = (i+1.0f) / size; |
|
373 |
return rnd.nextInt(numAxis); |
|
374 |
} |
|
375 |
else |
|
376 |
{ |
|
377 |
int newVector = rnd.nextInt(numAxis-1); |
|
378 |
return (newVector>=oldRotAxis ? newVector+1 : newVector); |
|
349 | 379 |
} |
350 |
|
|
351 |
return chances; |
|
352 | 380 |
} |
353 | 381 |
|
354 | 382 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
355 | 383 |
|
356 |
public float returnRotationFactor(float offset)
|
|
384 |
public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
|
|
357 | 385 |
{ |
358 |
return 1.0f; |
|
386 |
float rowFloat = rnd.nextFloat(); |
|
387 |
|
|
388 |
for(int row=0; row<mRowChances.length; row++) |
|
389 |
{ |
|
390 |
if( rowFloat<=mRowChances[row] ) return row; |
|
391 |
} |
|
392 |
|
|
393 |
return 0; |
|
359 | 394 |
} |
360 | 395 |
|
361 | 396 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Adjust randomizing new rotations so that:
1) it works for basicAngle=5 (Megaminx) (so now basicAngle=2,3,4,5 supported)
2) it leaves the decision as to what can be the next rotation to the Object class, as in case of certain Objects (the Dino, or the Helicopter, the Megaminx) the next rotation doesn't have to 'intersect' the old rotation always when oldRotAxis != newRotAxis (that's so simple only in case of the Cube and - only partly - the Pyraminx!)