Project

General

Profile

Download (19.3 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyDiamond.java @ ad7907b0

1 ece1b58d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 ece1b58d Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
34 ece1b58d Leszek Koltunski
35
import java.util.Random;
36
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 9c2f0c91 Leszek Koltunski
public class TwistyDiamond extends TwistyObject
40 ece1b58d Leszek Koltunski
{
41
  private static final int FACES_PER_CUBIT =8;
42
43
  // the four rotation axis of a Diamond. Must be normalized.
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
46
           new Static3D(+SQ6/3,+SQ3/3,     0),
47
           new Static3D(-SQ6/3,+SQ3/3,     0),
48 cc99cf91 Leszek Koltunski
           new Static3D(     0,-SQ3/3,-SQ6/3),
49
           new Static3D(     0,-SQ3/3,+SQ6/3)
50 ece1b58d Leszek Koltunski
         };
51
52 925ed78f Leszek Koltunski
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
53
54 ece1b58d Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
55
         {
56 2ef489e2 Leszek Koltunski
           COLOR_ORANGE, COLOR_VIOLET,
57
           COLOR_WHITE , COLOR_BLUE  ,
58
           COLOR_YELLOW, COLOR_RED   ,
59
           COLOR_GREEN , COLOR_GREY
60 ece1b58d Leszek Koltunski
         };
61
62 ab0c28f0 Leszek Koltunski
  // All legal rotation quats of a Diamond: unit + three 180 deg turns + 8 generators
63 ece1b58d Leszek Koltunski
  private static final Static4D[] QUATS = new Static4D[]
64
         {
65
           new Static4D(  0.0f,  0.0f,   0.0f,  1.0f ),
66
           new Static4D(  0.0f,  1.0f,   0.0f,  0.0f ),
67 ab0c28f0 Leszek Koltunski
           new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
68
           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f ),
69
70 ece1b58d Leszek Koltunski
           new Static4D(+SQ2/2,  0.5f,   0.0f,  0.5f ),
71
           new Static4D(-SQ2/2,  0.5f,   0.0f,  0.5f ),
72
           new Static4D(  0.0f,  0.5f, +SQ2/2,  0.5f ),
73
           new Static4D(  0.0f,  0.5f, -SQ2/2,  0.5f ),
74
           new Static4D(+SQ2/2,  0.5f,   0.0f, -0.5f ),
75
           new Static4D(-SQ2/2,  0.5f,   0.0f, -0.5f ),
76
           new Static4D(  0.0f,  0.5f, +SQ2/2, -0.5f ),
77 ab0c28f0 Leszek Koltunski
           new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f )
78 ece1b58d Leszek Koltunski
         };
79
80
  private static final float DIST = 0.50f;
81
82 2ef489e2 Leszek Koltunski
  private static final int[][] mFaceNeutralQuatIndex = new int[][]
83 ece1b58d Leszek Koltunski
         {
84 2ef489e2 Leszek Koltunski
             {6,10},
85
             {4, 8},
86
             {7,11},
87
             {5, 9},
88
             {7,11},
89
             {5, 9},
90
             {6,10},
91
             {4, 8}
92 ece1b58d Leszek Koltunski
         };
93
94 68b5f9c5 Leszek Koltunski
  private static final int[] mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4};
95
96 31cd7256 Leszek Koltunski
  private static final double[][] VERTICES_TETRA = new double[][]
97 b1f2ccf5 Leszek Koltunski
          {
98
             {-0.5, SQ2/4, 0.0},
99
             { 0.5, SQ2/4, 0.0},
100
             { 0.0,-SQ2/4, 0.5},
101
             { 0.0,-SQ2/4,-0.5}
102
          };
103
104 31cd7256 Leszek Koltunski
  private static final int[][] VERT_INDEXES_TETRA = new int[][]
105 b1f2ccf5 Leszek Koltunski
          {
106
             {2,1,0},   // counterclockwise!
107
             {2,3,1},
108
             {3,2,0},
109
             {3,0,1}
110
          };
111
112 31cd7256 Leszek Koltunski
  private static final double[][] VERTICES_OCTA = new double[][]
113 b1f2ccf5 Leszek Koltunski
          {
114
             { 0.5,   0.0, 0.5},
115
             { 0.5,   0.0,-0.5},
116
             {-0.5,   0.0,-0.5},
117
             {-0.5,   0.0, 0.5},
118
             { 0.0, SQ2/2, 0.0},
119
             { 0.0,-SQ2/2, 0.0}
120
          };
121
122 31cd7256 Leszek Koltunski
  private static final int[][] VERT_INDEXES_OCTA = new int[][]
123 b1f2ccf5 Leszek Koltunski
          {
124
             {3,0,4},   // counterclockwise!
125
             {0,1,4},
126
             {1,2,4},
127
             {2,3,4},
128
             {5,0,3},
129
             {5,1,0},
130
             {5,2,1},
131
             {5,3,2}
132
          };
133
134 31cd7256 Leszek Koltunski
  private static final float[][] STICKERS = new float[][]
135
          {
136
             { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
137
          };
138
139 9c06394a Leszek Koltunski
  private static final ObjectSticker[] mStickers;
140
141
  static
142
    {
143
    float radius = 0.06f;
144
    float stroke = 0.07f;
145
    float[] radii = new float[] {radius,radius,radius};
146
    mStickers = new ObjectSticker[STICKERS.length];
147
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
148
    }
149
150 ece1b58d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152 9c2f0c91 Leszek Koltunski
  TwistyDiamond(int size, Static4D quat, DistortedTexture texture,
153
                MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
154 ece1b58d Leszek Koltunski
    {
155 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.DIAM, res, scrWidth);
156 ece1b58d Leszek Koltunski
    }
157
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160
  float getScreenRatio()
161
    {
162 ab0c28f0 Leszek Koltunski
    return 0.65f;
163 ece1b58d Leszek Koltunski
    }
164
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
167
  Static4D[] getQuats()
168
    {
169
    return QUATS;
170
    }
171
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174
  int getNumFaces()
175
    {
176
    return FACE_COLORS.length;
177
    }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
181
  boolean shouldResetTextureMaps()
182
    {
183
    return false;
184
    }
185
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
188 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
189 ece1b58d Leszek Koltunski
    {
190 31cd7256 Leszek Koltunski
    return STICKERS.length;
191 ece1b58d Leszek Koltunski
    }
192
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
195 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
196 ece1b58d Leszek Koltunski
    {
197 680f921e Leszek Koltunski
    if( numLayers<2 )
198
      {
199
      return null;
200
      }
201
    else
202
      {
203 e6734aa9 Leszek Koltunski
      float[][] cuts = new float[4][numLayers-1];
204 68b5f9c5 Leszek Koltunski
      float dist = SQ6*0.666f*DIST;
205 680f921e Leszek Koltunski
      float cut  = 0.5f*dist*(2-numLayers);
206
207
      for(int i=0; i<numLayers-1; i++)
208
        {
209 e6734aa9 Leszek Koltunski
        cuts[0][i] = cut;
210
        cuts[1][i] = cut;
211
        cuts[2][i] = cut;
212
        cuts[3][i] = cut;
213 680f921e Leszek Koltunski
        cut += dist;
214
        }
215
216
      return cuts;
217
      }
218 ece1b58d Leszek Koltunski
    }
219
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222
  int getNumCubitFaces()
223
    {
224
    return FACES_PER_CUBIT;
225
    }
226
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
229 680f921e Leszek Koltunski
  private int getNumOctahedrons(int layers)
230
    {
231
    return layers==1 ? 1 : 4*(layers-1)*(layers-1) + 2;
232
    }
233
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235
236
  private int getNumTetrahedrons(int layers)
237
    {
238
    return 4*layers*(layers-1);
239
    }
240
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
243 31cd7256 Leszek Koltunski
  private int createOctaPositions(float[][] centers, int index, int layers, float height)
244 680f921e Leszek Koltunski
    {
245
    float x = DIST*(layers-1);
246
    float z = DIST*(layers+1);
247
248
    for(int i=0; i<layers; i++, index++)
249
      {
250
      z -= 2*DIST;
251
      centers[index][0] = x;
252
      centers[index][1] = height;
253
      centers[index][2] = z;
254
      }
255
256
    for(int i=0; i<layers-1; i++, index++)
257
      {
258
      x -= 2*DIST;
259
      centers[index][0] = x;
260
      centers[index][1] = height;
261
      centers[index][2] = z;
262
      }
263
264
    for(int i=0; i<layers-1; i++, index++)
265
      {
266
      z += 2*DIST;
267
      centers[index][0] = x;
268
      centers[index][1] = height;
269
      centers[index][2] = z;
270
      }
271
272
    for(int i=0; i<layers-2; i++, index++)
273
      {
274
      x += 2*DIST;
275
      centers[index][0] = x;
276
      centers[index][1] = height;
277
      centers[index][2] = z;
278
      }
279
280
    return index;
281
    }
282
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285 31cd7256 Leszek Koltunski
  private int createTetraPositions(float[][] centers, int index, int layers, float height)
286 ece1b58d Leszek Koltunski
    {
287 680f921e Leszek Koltunski
    float x = DIST*(layers-1);
288
    float z = DIST*layers;
289
290
    for(int i=0; i<layers-1; i++, index++)
291
      {
292
      z -= 2*DIST;
293
      centers[index][0] = x;
294
      centers[index][1] = height;
295
      centers[index][2] = z;
296
      }
297
298
    x += DIST;
299
    z -= DIST;
300
301
    for(int i=0; i<layers-1; i++, index++)
302
      {
303
      x -= 2*DIST;
304
      centers[index][0] = x;
305
      centers[index][1] = height;
306
      centers[index][2] = z;
307
      }
308
309
    x -= DIST;
310
    z -= DIST;
311
312
    for(int i=0; i<layers-1; i++, index++)
313
      {
314
      z += 2*DIST;
315
      centers[index][0] = x;
316
      centers[index][1] = height;
317
      centers[index][2] = z;
318
      }
319
320
    x -= DIST;
321
    z += DIST;
322
323
    for(int i=0; i<layers-1; i++, index++)
324
      {
325
      x += 2*DIST;
326
      centers[index][0] = x;
327
      centers[index][1] = height;
328
      centers[index][2] = z;
329
      }
330
331
    return index;
332
    }
333
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
336
  float[][] getCubitPositions(int layers)
337
    {
338
    int numO = getNumOctahedrons(layers);
339
    int numT = getNumTetrahedrons(layers);
340
    int index = 0;
341
    float height = 0.0f;
342
343
    float[][] CENTERS = new float[numO+numT][3];
344
345 31cd7256 Leszek Koltunski
    index = createOctaPositions(CENTERS,index,layers,height);
346 680f921e Leszek Koltunski
347
    for(int i=layers-1; i>0; i--)
348
      {
349
      height += SQ2*DIST;
350 31cd7256 Leszek Koltunski
      index = createOctaPositions(CENTERS,index,i,+height);
351
      index = createOctaPositions(CENTERS,index,i,-height);
352 680f921e Leszek Koltunski
      }
353
354
    height = DIST*SQ2/2;
355
356
    for(int i=layers; i>1; i--)
357
      {
358 31cd7256 Leszek Koltunski
      index = createTetraPositions(CENTERS,index,i,+height);
359
      index = createTetraPositions(CENTERS,index,i,-height);
360 680f921e Leszek Koltunski
      height += SQ2*DIST;
361
      }
362
363 ece1b58d Leszek Koltunski
    return CENTERS;
364
    }
365
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367
368 680f921e Leszek Koltunski
  private int retFaceTetraBelongsTo(int tetra, int numLayers)
369 ece1b58d Leszek Koltunski
    {
370 68b5f9c5 Leszek Koltunski
    for(int i=numLayers-1; i>0; i--)
371 ece1b58d Leszek Koltunski
      {
372 68b5f9c5 Leszek Koltunski
      if( tetra < 8*i ) return mTetraToFaceMap[tetra/i];
373
      tetra -= 8*i;
374 680f921e Leszek Koltunski
      }
375 68b5f9c5 Leszek Koltunski
376
    return -1;
377 680f921e Leszek Koltunski
    }
378
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380
381
  private Static4D getQuat(int cubit, int numLayers, int numO)
382
    {
383
    if( cubit<numO ) return QUATS[0];
384
385
    switch( retFaceTetraBelongsTo(cubit-numO, numLayers) )
386
      {
387 2ef489e2 Leszek Koltunski
      case 0: return QUATS[0];                          // unit quat
388
      case 1: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
389
      case 2: return QUATS[1];                          // 180 along Y
390
      case 3: return new Static4D(0,+SQ2/2,0,SQ2/2);    //  90 along
391
      case 4: return new Static4D(0,     0,1,    0);    // 180 along Z
392
      case 5: return new Static4D(SQ2/2, 0,SQ2/2,0);    //
393
      case 6: return new Static4D(     1,0,0,    0);    // 180 along X
394
      case 7: return new Static4D(-SQ2/2,0,SQ2/2,0);    //
395 ece1b58d Leszek Koltunski
      }
396
397
    return null;
398
    }
399
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401
402 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
403 ece1b58d Leszek Koltunski
    {
404 31cd7256 Leszek Koltunski
    if( mMeshes==null )
405
      {
406
      FactoryCubit factory = FactoryCubit.getInstance();
407
      factory.clear();
408
      mMeshes = new MeshBase[2];
409
      }
410
411 ece1b58d Leszek Koltunski
    MeshBase mesh;
412 680f921e Leszek Koltunski
    int numO = getNumOctahedrons(numLayers);
413 f56b53cb Leszek Koltunski
    int N = numLayers>3 ? 5:6;
414
    int E = numLayers>3 ? 1:2;
415 ece1b58d Leszek Koltunski
416 680f921e Leszek Koltunski
    if( cubit<numO )
417 ece1b58d Leszek Koltunski
      {
418 31cd7256 Leszek Koltunski
      if( mMeshes[0]==null )
419
        {
420 f56b53cb Leszek Koltunski
        float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
421 31cd7256 Leszek Koltunski
        int[] bandIndexes   = new int[] { 0,0,0,0,0,0,0,0 };
422
        float[][] corners   = new float[][] { {0.04f,0.20f} };
423
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0 };
424 b3c9061a Leszek Koltunski
        float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
425
        int[] centerIndexes = new int[] { 0,0,0,0,0,0 };
426 31cd7256 Leszek Koltunski
427
        FactoryCubit factory = FactoryCubit.getInstance();
428
429
        factory.createNewFaceTransform(VERTICES_OCTA,VERT_INDEXES_OCTA);
430
        mMeshes[0] = factory.createRoundedSolid(VERTICES_OCTA, VERT_INDEXES_OCTA,
431
                                                bands, bandIndexes,
432
                                                corners, cornerIndexes,
433 b3c9061a Leszek Koltunski
                                                centers, centerIndexes,
434 47d98cd5 Leszek Koltunski
                                                getNumCubitFaces(), null );
435 31cd7256 Leszek Koltunski
        }
436
      mesh = mMeshes[0].copy(true);
437 ece1b58d Leszek Koltunski
      }
438
    else
439
      {
440 31cd7256 Leszek Koltunski
      if( mMeshes[1]==null )
441
        {
442 f56b53cb Leszek Koltunski
        float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
443 31cd7256 Leszek Koltunski
        int[] bandIndexes   = new int[] { 0,0,0,0 };
444
        float[][] corners   = new float[][] { {0.08f,0.15f} };
445
        int[] cornerIndexes = new int[] { 0,0,0,0 };
446 b3c9061a Leszek Koltunski
        float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
447
        int[] centerIndexes = new int[] { 0,0,0,0 };
448 31cd7256 Leszek Koltunski
449
        FactoryCubit factory = FactoryCubit.getInstance();
450
451
        factory.createNewFaceTransform(VERTICES_TETRA,VERT_INDEXES_TETRA);
452
        mMeshes[1] = factory.createRoundedSolid(VERTICES_TETRA, VERT_INDEXES_TETRA,
453
                                                bands, bandIndexes,
454
                                                corners, cornerIndexes,
455 b3c9061a Leszek Koltunski
                                                centers, centerIndexes,
456 47d98cd5 Leszek Koltunski
                                                getNumCubitFaces(), null );
457 31cd7256 Leszek Koltunski
        }
458
      mesh = mMeshes[1].copy(true);
459 ece1b58d Leszek Koltunski
      }
460
461 680f921e Leszek Koltunski
    Static4D sQ = getQuat(cubit,numLayers,numO);
462
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( sQ, new Static3D(0,0,0) );
463 ece1b58d Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
464
465
    return mesh;
466
    }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
470 2ef489e2 Leszek Koltunski
  int getFaceColor(int cubit, int cubitface, int size)
471 ece1b58d Leszek Koltunski
    {
472 2ef489e2 Leszek Koltunski
    int numO = getNumOctahedrons(size);
473 680f921e Leszek Koltunski
474
    if( cubit<numO )
475
      {
476 2ef489e2 Leszek Koltunski
      int axis = 0;
477
      int layer= 1;
478
479
      switch(cubitface)
480
        {
481
        case 0: axis = 2; layer =             1; break;
482
        case 1: axis = 0; layer = (1<<(size-1)); break;
483
        case 2: axis = 3; layer =             1; break;
484
        case 3: axis = 1; layer = (1<<(size-1)); break;
485
        case 4: axis = 3; layer = (1<<(size-1)); break;
486
        case 5: axis = 1; layer =             1; break;
487
        case 6: axis = 2; layer = (1<<(size-1)); break;
488
        case 7: axis = 0; layer =             1; break;
489
        }
490
491 a4962b9c Leszek Koltunski
      return CUBITS[cubit].mRotationRow[axis] == layer ? cubitface : NUM_TEXTURES;
492 680f921e Leszek Koltunski
      }
493
    else
494
      {
495 a4962b9c Leszek Koltunski
      return cubitface>0 ? NUM_TEXTURES : retFaceTetraBelongsTo(cubit-numO, size);
496 680f921e Leszek Koltunski
      }
497 ece1b58d Leszek Koltunski
    }
498
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
501 9c06394a Leszek Koltunski
  int getColor(int face)
502 ece1b58d Leszek Koltunski
    {
503 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
504
    }
505
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507 76c2bd07 Leszek Koltunski
508 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
509
    {
510
    return mStickers[face/NUM_FACES];
511 ece1b58d Leszek Koltunski
    }
512
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514
515
  float returnMultiplier()
516
    {
517 cc99cf91 Leszek Koltunski
    return 1.5f;
518 ece1b58d Leszek Koltunski
    }
519
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521
// PUBLIC API
522
523
  public Static3D[] getRotationAxis()
524
    {
525
    return ROT_AXIS;
526
    }
527
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529
530 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
531 ece1b58d Leszek Koltunski
    {
532 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
533 ece1b58d Leszek Koltunski
    }
534
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536
537 9f171eba Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
538 ece1b58d Leszek Koltunski
    {
539 9f171eba Leszek Koltunski
    if( curr==0 )
540 ece1b58d Leszek Koltunski
      {
541 9f171eba Leszek Koltunski
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
542 ece1b58d Leszek Koltunski
      }
543
    else
544
      {
545 582617c1 Leszek Koltunski
      int newVector = rnd.nextInt(NUM_AXIS -1);
546 9f171eba Leszek Koltunski
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
547 ece1b58d Leszek Koltunski
      }
548
549
    float rowFloat = rnd.nextFloat();
550 0203be88 Leszek Koltunski
    int numLayers = getNumLayers();
551 ece1b58d Leszek Koltunski
552 0203be88 Leszek Koltunski
    for(int row=0; row<numLayers; row++)
553 ece1b58d Leszek Koltunski
      {
554 0203be88 Leszek Koltunski
      if( rowFloat*numLayers <= row+1 )
555 bbc6471c Leszek Koltunski
        {
556 9f171eba Leszek Koltunski
        scramble[curr][1] = row;
557 bbc6471c Leszek Koltunski
        break;
558
        }
559 ece1b58d Leszek Koltunski
      }
560
561 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
562
      {
563 9f171eba Leszek Koltunski
      case 0: scramble[curr][2] = -1; break;
564
      case 1: scramble[curr][2] =  1; break;
565 5043d5d0 Leszek Koltunski
      }
566 ece1b58d Leszek Koltunski
    }
567
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569 75a21cd6 Leszek Koltunski
// The Diamond is solved if and only if:
570 ece1b58d Leszek Koltunski
//
571 2ef489e2 Leszek Koltunski
// 1) all octahedrons are rotated with the same quat
572
// 2) all tetrahedrons might be also optionally rotated by a 'face neutral' pair of quats
573
//    (indexes of those are kept in the 'mFaceNeutralQuattIndex' table)
574 ad6f6f03 Leszek Koltunski
//
575 75a21cd6 Leszek Koltunski
// Note: this works for any size, because even if layers>3 - and then there are 'face-internal'
576
// octahedrons which, it would seem, can be rotated by those 'face neutral' pairs of quats - but
577
// in reality no, because if they were, the octahedrons would then not fit in the lattice...
578 ece1b58d Leszek Koltunski
579
  public boolean isSolved()
580
    {
581 ab0c28f0 Leszek Koltunski
    int q = CUBITS[0].mQuatIndex;
582 2ef489e2 Leszek Koltunski
    int layers = getNumLayers();
583
    int numO = getNumOctahedrons(layers);
584 ab0c28f0 Leszek Koltunski
585 2ef489e2 Leszek Koltunski
    for(int i=1; i<numO; i++)
586 ad6f6f03 Leszek Koltunski
      {
587 2ef489e2 Leszek Koltunski
      if( CUBITS[i].mQuatIndex != q ) return false;
588
      }
589 ad6f6f03 Leszek Koltunski
590 2ef489e2 Leszek Koltunski
    int qI, q1Index, q2Index, face;
591 ad6f6f03 Leszek Koltunski
592 2ef489e2 Leszek Koltunski
    for(int i=numO; i<NUM_CUBITS; i++)
593
      {
594
      face    = retFaceTetraBelongsTo(i-numO,layers);
595
      q1Index = mFaceNeutralQuatIndex[face][0];
596
      q2Index = mFaceNeutralQuatIndex[face][1];
597
      qI      = CUBITS[i].mQuatIndex;
598 ad6f6f03 Leszek Koltunski
599 2ef489e2 Leszek Koltunski
      if(  qI != q && qI != mulQuat(q,q1Index) && qI != mulQuat(q,q2Index) ) return false;
600 ad6f6f03 Leszek Koltunski
      }
601
602 2ef489e2 Leszek Koltunski
    return true;
603 ece1b58d Leszek Koltunski
    }
604
605 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
606
607
  public int getObjectName(int numLayers)
608
    {
609 2ef489e2 Leszek Koltunski
    switch(numLayers)
610
      {
611
      case 2: return R.string.diam2;
612
      case 3: return R.string.diam3;
613 2adf1263 Leszek Koltunski
      case 4: return R.string.diam4;
614 2ef489e2 Leszek Koltunski
      }
615
616
    return 0;
617 6fd4a72c Leszek Koltunski
    }
618
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620
621
  public int getInventor(int numLayers)
622
    {
623 2ef489e2 Leszek Koltunski
    switch(numLayers)
624
      {
625
      case 2: return R.string.diam2_inventor;
626
      case 3: return R.string.diam3_inventor;
627 2adf1263 Leszek Koltunski
      case 4: return R.string.diam4_inventor;
628 2ef489e2 Leszek Koltunski
      }
629
630
    return 0;
631 6fd4a72c Leszek Koltunski
    }
632
633
///////////////////////////////////////////////////////////////////////////////////////////////////
634
635
  public int getComplexity(int numLayers)
636
    {
637 2ef489e2 Leszek Koltunski
    switch(numLayers)
638
      {
639 2adf1263 Leszek Koltunski
      case 2: return 4;
640
      case 3: return 6;
641
      case 4: return 8;
642 2ef489e2 Leszek Koltunski
      }
643
644
    return 0;
645 6fd4a72c Leszek Koltunski
    }
646 ece1b58d Leszek Koltunski
}