Project

General

Profile

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

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

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