1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.objects;
|
21
|
|
22
|
import android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.library.main.DistortedEffects;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import java.util.Random;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
abstract class TwistyMinx extends TwistyObject
|
35
|
{
|
36
|
private static final int FACES_PER_CUBIT =6;
|
37
|
|
38
|
static final int NUM_CORNERS = 20;
|
39
|
static final int NUM_CENTERS = 12;
|
40
|
static final int NUM_EDGES = 30;
|
41
|
|
42
|
static final float C2 = (SQ5+3)/4;
|
43
|
static final float LEN = (float)(Math.sqrt(1.25f+0.5f*SQ5));
|
44
|
static final float SIN54 = (SQ5+1)/4;
|
45
|
static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4);
|
46
|
static final float SIN18 = (SQ5-1)/4;
|
47
|
static final float COS18 = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
|
48
|
static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
49
|
static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
50
|
|
51
|
// the six rotation axis of a Minx. Must be normalized.
|
52
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
53
|
{
|
54
|
new Static3D( C2/LEN, SIN54/LEN, 0 ),
|
55
|
new Static3D( -C2/LEN, SIN54/LEN, 0 ),
|
56
|
new Static3D( 0 , C2/LEN, SIN54/LEN ),
|
57
|
new Static3D( 0 , -C2/LEN, SIN54/LEN ),
|
58
|
new Static3D( SIN54/LEN, 0 , C2/LEN ),
|
59
|
new Static3D( SIN54/LEN, 0 , -C2/LEN )
|
60
|
};
|
61
|
|
62
|
private static final int[] BASIC_ANGLE = new int[] { 5,5,5,5,5,5 };
|
63
|
|
64
|
static final int MINX_LGREEN = 0xff53aa00;
|
65
|
static final int MINX_PINK = 0xfffd7ab7;
|
66
|
static final int MINX_SANDY = 0xffefd48b;
|
67
|
static final int MINX_LBLUE = 0xff00a2d7;
|
68
|
static final int MINX_ORANGE = 0xffff6200;
|
69
|
static final int MINX_VIOLET = 0xff7d59a4;
|
70
|
static final int MINX_DGREEN = 0xff007a47;
|
71
|
static final int MINX_DRED = 0xffbd0000;
|
72
|
static final int MINX_DBLUE = 0xff1a29b2;
|
73
|
static final int MINX_DYELLOW= 0xffffc400;
|
74
|
static final int MINX_WHITE = 0xffffffff;
|
75
|
static final int MINX_GREY = 0xff727c7b;
|
76
|
|
77
|
static final int[] FACE_COLORS = new int[]
|
78
|
{
|
79
|
MINX_LGREEN, MINX_PINK , MINX_SANDY , MINX_LBLUE,
|
80
|
MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
|
81
|
MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
|
82
|
};
|
83
|
|
84
|
private static final int[] mFaceMap = new int[] {8,10,3,7,1,11,9,2,4,0,5,6};
|
85
|
|
86
|
// All 60 legal rotation quats of a Minx
|
87
|
static final Static4D[] QUATS = new Static4D[]
|
88
|
{
|
89
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), //0
|
90
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
91
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
92
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
93
|
|
94
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ), //4
|
95
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ),
|
96
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
97
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
98
|
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f ),
|
99
|
new Static4D( -0.5f, 0.5f, -0.5f, 0.5f ),
|
100
|
new Static4D( -0.5f, -0.5f, 0.5f, 0.5f ),
|
101
|
new Static4D( -0.5f, -0.5f, -0.5f, 0.5f ),
|
102
|
|
103
|
new Static4D( 0.5f, SIN54, SIN18, 0.0f ), // 12
|
104
|
new Static4D( 0.5f, SIN54,-SIN18, 0.0f ),
|
105
|
new Static4D( 0.5f,-SIN54, SIN18, 0.0f ),
|
106
|
new Static4D( 0.5f,-SIN54,-SIN18, 0.0f ),
|
107
|
new Static4D( SIN18, 0.5f, SIN54, 0.0f ),
|
108
|
new Static4D( SIN18, 0.5f,-SIN54, 0.0f ),
|
109
|
new Static4D(-SIN18, 0.5f, SIN54, 0.0f ),
|
110
|
new Static4D(-SIN18, 0.5f,-SIN54, 0.0f ),
|
111
|
new Static4D( SIN54, SIN18, 0.5f, 0.0f ),
|
112
|
new Static4D( SIN54,-SIN18, 0.5f, 0.0f ),
|
113
|
new Static4D(-SIN54, SIN18, 0.5f, 0.0f ),
|
114
|
new Static4D(-SIN54,-SIN18, 0.5f, 0.0f ),
|
115
|
|
116
|
new Static4D( 0.0f, SIN18, SIN54, 0.5f ), //24
|
117
|
new Static4D( 0.0f, SIN18,-SIN54, 0.5f ),
|
118
|
new Static4D( 0.0f,-SIN18, SIN54, 0.5f ),
|
119
|
new Static4D( 0.0f,-SIN18,-SIN54, 0.5f ),
|
120
|
new Static4D( SIN18, SIN54, 0.0f, 0.5f ),
|
121
|
new Static4D( SIN18,-SIN54, 0.0f, 0.5f ),
|
122
|
new Static4D(-SIN18, SIN54, 0.0f, 0.5f ),
|
123
|
new Static4D(-SIN18,-SIN54, 0.0f, 0.5f ),
|
124
|
new Static4D( SIN54, 0.0f, SIN18, 0.5f ),
|
125
|
new Static4D( SIN54, 0.0f,-SIN18, 0.5f ),
|
126
|
new Static4D(-SIN54, 0.0f, SIN18, 0.5f ),
|
127
|
new Static4D(-SIN54, 0.0f,-SIN18, 0.5f ),
|
128
|
|
129
|
new Static4D( 0.0f, SIN54, 0.5f, SIN18 ), //36
|
130
|
new Static4D( 0.0f, SIN54, -0.5f, SIN18 ),
|
131
|
new Static4D( 0.0f,-SIN54, 0.5f, SIN18 ),
|
132
|
new Static4D( 0.0f,-SIN54, -0.5f, SIN18 ),
|
133
|
new Static4D( 0.5f, 0.0f, SIN54, SIN18 ),
|
134
|
new Static4D( 0.5f, 0.0f,-SIN54, SIN18 ),
|
135
|
new Static4D( -0.5f, 0.0f, SIN54, SIN18 ),
|
136
|
new Static4D( -0.5f, 0.0f,-SIN54, SIN18 ),
|
137
|
new Static4D( SIN54, 0.5f, 0.0f, SIN18 ),
|
138
|
new Static4D( SIN54, -0.5f, 0.0f, SIN18 ),
|
139
|
new Static4D(-SIN54, 0.5f, 0.0f, SIN18 ),
|
140
|
new Static4D(-SIN54, -0.5f, 0.0f, SIN18 ),
|
141
|
|
142
|
new Static4D( 0.0f, 0.5f, SIN18, SIN54 ), //48
|
143
|
new Static4D( 0.0f, 0.5f,-SIN18, SIN54 ),
|
144
|
new Static4D( 0.0f, -0.5f, SIN18, SIN54 ),
|
145
|
new Static4D( 0.0f, -0.5f,-SIN18, SIN54 ),
|
146
|
new Static4D( 0.5f, SIN18, 0.0f, SIN54 ),
|
147
|
new Static4D( 0.5f,-SIN18, 0.0f, SIN54 ),
|
148
|
new Static4D( -0.5f, SIN18, 0.0f, SIN54 ),
|
149
|
new Static4D( -0.5f,-SIN18, 0.0f, SIN54 ),
|
150
|
new Static4D( SIN18, 0.0f, 0.5f, SIN54 ),
|
151
|
new Static4D( SIN18, 0.0f, -0.5f, SIN54 ),
|
152
|
new Static4D(-SIN18, 0.0f, 0.5f, SIN54 ),
|
153
|
new Static4D(-SIN18, 0.0f, -0.5f, SIN54 ),
|
154
|
};
|
155
|
|
156
|
// Coordinates of all 20 corners of a Minx
|
157
|
static final float[][] CORNERS = new float[][]
|
158
|
{
|
159
|
{ 0.0f, 0.5f, C2},
|
160
|
{ 0.0f, 0.5f, -C2},
|
161
|
{ 0.0f, -0.5f, C2},
|
162
|
{ 0.0f, -0.5f, -C2},
|
163
|
{ C2, 0.0f, 0.5f},
|
164
|
{ C2, 0.0f, -0.5f},
|
165
|
{ -C2, 0.0f, 0.5f},
|
166
|
{ -C2, 0.0f, -0.5f},
|
167
|
{ 0.5f, C2, 0.0f},
|
168
|
{ 0.5f, -C2, 0.0f},
|
169
|
{ -0.5f, C2, 0.0f},
|
170
|
{ -0.5f, -C2, 0.0f},
|
171
|
{ SIN54, SIN54, SIN54},
|
172
|
{ SIN54, SIN54,-SIN54},
|
173
|
{ SIN54,-SIN54, SIN54},
|
174
|
{ SIN54,-SIN54,-SIN54},
|
175
|
{-SIN54, SIN54, SIN54},
|
176
|
{-SIN54, SIN54,-SIN54},
|
177
|
{-SIN54,-SIN54, SIN54},
|
178
|
{-SIN54,-SIN54,-SIN54},
|
179
|
};
|
180
|
|
181
|
static final int[][] mCornerFaceMap =
|
182
|
{
|
183
|
{ 0, 1, 8 },
|
184
|
{ 6, 5,10 },
|
185
|
{ 1, 0,11 },
|
186
|
{ 5, 6, 3 },
|
187
|
{ 0, 9, 4 },
|
188
|
{ 5, 4, 9 },
|
189
|
{ 7, 1, 2 },
|
190
|
{ 2, 6, 7 },
|
191
|
{ 10, 9, 8 },
|
192
|
{ 4, 3,11 },
|
193
|
{ 7,10, 8 },
|
194
|
{ 3, 2,11 },
|
195
|
{ 0, 8, 9 },
|
196
|
{ 9,10, 5 },
|
197
|
{ 0, 4,11 },
|
198
|
{ 4, 5, 3 },
|
199
|
{ 1, 7, 8 },
|
200
|
{ 7, 6,10 },
|
201
|
{ 2, 1,11 },
|
202
|
{ 6, 2, 3 },
|
203
|
};
|
204
|
|
205
|
static final int[] QUAT_EDGE_INDICES =
|
206
|
{
|
207
|
56, 40, 43, 59, 0, 19, 9, 54, 58, 49,
|
208
|
48, 24, 52, 4, 16, 32, 20, 11, 21, 35 ,
|
209
|
37, 30, 8, 28, 36, 44, 1, 46, 12, 47
|
210
|
};
|
211
|
|
212
|
|
213
|
static final int[] QUAT_CORNER_INDICES =
|
214
|
{
|
215
|
0, 2, 3, 1, 40, 31, 41, 30, 39, 35,
|
216
|
36, 34, 56, 32, 43, 21, 48, 28, 42, 23
|
217
|
};
|
218
|
|
219
|
static final boolean[][] OPPOSITE_ROWS =
|
220
|
{
|
221
|
{false, true, false, true, false, false},
|
222
|
{ true, false, false, true, true, true},
|
223
|
{false, false, false, true, false, true},
|
224
|
{ true, true, true, false, false, true},
|
225
|
{false, true, false, false, false, true},
|
226
|
{false, true, true, true, true, false}
|
227
|
};
|
228
|
|
229
|
// the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
|
230
|
// In fact the 2 corners already define it, the faces only provide easy
|
231
|
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
|
232
|
// the 'left' or right of vector corner1 --> corner2, according to Quat.
|
233
|
static final int[][] mEdgeMap =
|
234
|
{
|
235
|
{ 0, 12, 0, 8}, //0
|
236
|
{ 12, 4, 0, 9},
|
237
|
{ 4, 14, 0, 4},
|
238
|
{ 14, 2, 0, 11},
|
239
|
{ 2, 0, 0, 1},
|
240
|
{ 14, 9, 11, 4}, //5
|
241
|
{ 9, 11, 11, 3},
|
242
|
{ 11, 18, 11, 2},
|
243
|
{ 18, 2, 11, 1},
|
244
|
{ 18, 6, 1, 2},
|
245
|
{ 6, 16, 1, 7}, //10
|
246
|
{ 16, 0, 1, 8},
|
247
|
{ 16, 10, 8, 7},
|
248
|
{ 10, 8, 8, 10},
|
249
|
{ 8, 12, 8, 9},
|
250
|
{ 8, 13, 9, 10}, //15
|
251
|
{ 13, 5, 9, 5},
|
252
|
{ 5, 4, 9, 4},
|
253
|
{ 5, 15, 4, 5},
|
254
|
{ 15, 9, 4, 3},
|
255
|
{ 11, 19, 2, 3}, //20
|
256
|
{ 19, 7, 2, 6},
|
257
|
{ 7, 6, 2, 7},
|
258
|
{ 7, 17, 7, 6},
|
259
|
{ 17, 10, 7, 10},
|
260
|
{ 17, 1, 10, 6}, //25
|
261
|
{ 1, 3, 5, 6},
|
262
|
{ 3, 19, 3, 6},
|
263
|
{ 1, 13, 10, 5},
|
264
|
{ 3, 15, 5, 3},
|
265
|
};
|
266
|
|
267
|
// the five vertices that form a given face. Order: the same as colors
|
268
|
// of the faces in TwistyMinx.
|
269
|
static final int[][] mCenterMap =
|
270
|
{
|
271
|
{ 0, 12, 4, 14, 2},
|
272
|
{ 0, 2, 18, 6, 16},
|
273
|
{ 6, 18, 11, 19, 7},
|
274
|
{ 3, 15, 9, 11, 19},
|
275
|
{ 4, 5, 15, 9, 14},
|
276
|
{ 1, 13, 5, 15, 3},
|
277
|
{ 1, 3, 19, 7, 17},
|
278
|
{10, 16, 6, 7, 17},
|
279
|
{ 0, 12, 8, 10, 16},
|
280
|
{ 8, 13, 5, 4, 12},
|
281
|
{ 1, 13, 8, 10, 17},
|
282
|
{ 2, 14, 9, 11, 18},
|
283
|
};
|
284
|
|
285
|
static final float[][] mCenterCoords = new float[NUM_CENTERS][3];
|
286
|
|
287
|
static
|
288
|
{
|
289
|
for(int center=0; center<NUM_CENTERS; center++)
|
290
|
{
|
291
|
int[] map = mCenterMap[center];
|
292
|
|
293
|
float x = CORNERS[map[0]][0] +
|
294
|
CORNERS[map[1]][0] +
|
295
|
CORNERS[map[2]][0] +
|
296
|
CORNERS[map[3]][0] +
|
297
|
CORNERS[map[4]][0] ;
|
298
|
|
299
|
float y = CORNERS[map[0]][1] +
|
300
|
CORNERS[map[1]][1] +
|
301
|
CORNERS[map[2]][1] +
|
302
|
CORNERS[map[3]][1] +
|
303
|
CORNERS[map[4]][1] ;
|
304
|
|
305
|
float z = CORNERS[map[0]][2] +
|
306
|
CORNERS[map[1]][2] +
|
307
|
CORNERS[map[2]][2] +
|
308
|
CORNERS[map[3]][2] +
|
309
|
CORNERS[map[4]][2] ;
|
310
|
|
311
|
mCenterCoords[center][0] = x/5;
|
312
|
mCenterCoords[center][1] = y/5;
|
313
|
mCenterCoords[center][2] = z/5;
|
314
|
}
|
315
|
}
|
316
|
|
317
|
static final Static4D[] mBasicCornerV, mCurrCornerV;
|
318
|
|
319
|
static
|
320
|
{
|
321
|
mBasicCornerV = new Static4D[3];
|
322
|
mCurrCornerV = new Static4D[3];
|
323
|
|
324
|
mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
|
325
|
mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
|
326
|
mBasicCornerV[2] = new Static4D( 0, -0.500f, 0.0f, 0.0f );
|
327
|
}
|
328
|
|
329
|
private static int[][] mScrambleTable;
|
330
|
private static int[] mPossibleAxis, mPossibleLayers;
|
331
|
private static int[] mNumOccurences;
|
332
|
|
333
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
334
|
|
335
|
TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
336
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
337
|
{
|
338
|
super(numLayers, realSize, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
339
|
}
|
340
|
|
341
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
342
|
|
343
|
int[] getSolvedQuats(int cubit, int numLayers)
|
344
|
{
|
345
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
346
|
return status<0 ? null : buildSolvedQuats(MovementMinx.FACE_AXIS[mFaceMap[status]],QUATS);
|
347
|
}
|
348
|
|
349
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
350
|
|
351
|
Static4D[] getQuats()
|
352
|
{
|
353
|
return QUATS;
|
354
|
}
|
355
|
|
356
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
357
|
|
358
|
int getNumFaces()
|
359
|
{
|
360
|
return FACE_COLORS.length;
|
361
|
}
|
362
|
|
363
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
364
|
|
365
|
int getSolvedFunctionIndex()
|
366
|
{
|
367
|
return 0;
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
boolean shouldResetTextureMaps()
|
373
|
{
|
374
|
return false;
|
375
|
}
|
376
|
|
377
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
378
|
|
379
|
int getNumCubitFaces()
|
380
|
{
|
381
|
return FACES_PER_CUBIT;
|
382
|
}
|
383
|
|
384
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
385
|
|
386
|
float returnMultiplier()
|
387
|
{
|
388
|
return 2.0f;
|
389
|
}
|
390
|
|
391
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
392
|
|
393
|
private void initializeScrambleTable(int[] first, int numLayers)
|
394
|
{
|
395
|
if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2];
|
396
|
if( mPossibleAxis ==null ) mPossibleAxis = new int[NUM_AXIS-1];
|
397
|
if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1];
|
398
|
if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1];
|
399
|
|
400
|
for(int i=0; i<NUM_AXIS; i++)
|
401
|
for(int j=0; j<2; j++)
|
402
|
{
|
403
|
mScrambleTable[i][j] = 0;
|
404
|
}
|
405
|
|
406
|
int layer = convertRowIntoLayer(first[1],numLayers);
|
407
|
|
408
|
mScrambleTable[first[0]][layer] = 1;
|
409
|
}
|
410
|
|
411
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
412
|
|
413
|
private int convertRowIntoLayer(int row, int numLayers)
|
414
|
{
|
415
|
return row>(numLayers-1)/2 ? 1 : 0;
|
416
|
}
|
417
|
|
418
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
419
|
|
420
|
private int convertLayerIntoRow(Random rnd, int layer, int numLayers)
|
421
|
{
|
422
|
int ran = numLayers>3 ? rnd.nextInt((numLayers-1)/2) : 0;
|
423
|
return layer==0 ? ran : numLayers-1-ran;
|
424
|
}
|
425
|
|
426
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
427
|
|
428
|
private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom)
|
429
|
{
|
430
|
return OPPOSITE_ROWS[oldAxis][newAxis]^(oldRow<nom);
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
private int retNewRotationIndex(Random rnd, int nom, int[] oldRot)
|
436
|
{
|
437
|
int index=0, max=0;
|
438
|
|
439
|
for(int ax=0; ax<NUM_AXIS; ax++)
|
440
|
{
|
441
|
if( ax!=oldRot[0] )
|
442
|
{
|
443
|
mPossibleAxis[index] = ax;
|
444
|
mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1;
|
445
|
int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]];
|
446
|
if( tmp>max ) max=tmp;
|
447
|
index++;
|
448
|
}
|
449
|
}
|
450
|
|
451
|
for(int ax=0; ax<NUM_AXIS-1; ax++)
|
452
|
{
|
453
|
int value = mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]];
|
454
|
mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]);
|
455
|
}
|
456
|
|
457
|
float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2];
|
458
|
|
459
|
for(int ax=0; ax<NUM_AXIS-1; ax++)
|
460
|
{
|
461
|
if( random <= mNumOccurences[ax] )
|
462
|
{
|
463
|
index=ax;
|
464
|
break;
|
465
|
}
|
466
|
}
|
467
|
|
468
|
mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++;
|
469
|
|
470
|
return index;
|
471
|
}
|
472
|
|
473
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
474
|
// PUBLIC API
|
475
|
|
476
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
477
|
{
|
478
|
int numLayers = getNumLayers();
|
479
|
int nom = (numLayers-1)/2;
|
480
|
|
481
|
if( curr==0 )
|
482
|
{
|
483
|
int lf = rnd.nextInt(2);
|
484
|
int row= rnd.nextInt(nom);
|
485
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
486
|
scramble[curr][1] = (lf==0 ? row : numLayers-1-row);
|
487
|
initializeScrambleTable(scramble[curr],numLayers);
|
488
|
}
|
489
|
else
|
490
|
{
|
491
|
int index = retNewRotationIndex(rnd,nom,scramble[curr-1]);
|
492
|
scramble[curr][0] = mPossibleAxis[index];
|
493
|
scramble[curr][1] = convertLayerIntoRow(rnd, mPossibleLayers[index], numLayers);
|
494
|
}
|
495
|
|
496
|
switch( rnd.nextInt(4) )
|
497
|
{
|
498
|
case 0: scramble[curr][2] = -2; break;
|
499
|
case 1: scramble[curr][2] = -1; break;
|
500
|
case 2: scramble[curr][2] = 1; break;
|
501
|
case 3: scramble[curr][2] = 2; break;
|
502
|
}
|
503
|
}
|
504
|
|
505
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506
|
|
507
|
public Static3D[] getRotationAxis()
|
508
|
{
|
509
|
return ROT_AXIS;
|
510
|
}
|
511
|
|
512
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
513
|
|
514
|
public int[] getBasicAngle()
|
515
|
{
|
516
|
return BASIC_ANGLE;
|
517
|
}
|
518
|
}
|