Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDiamond.java @ 516451c4

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