Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDiamond.java @ 2adf1263

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 f56b53cb Leszek Koltunski
    int N = numLayers>3 ? 5:6;
407
    int E = numLayers>3 ? 1:2;
408 ece1b58d Leszek Koltunski
409 680f921e Leszek Koltunski
    if( cubit<numO )
410 ece1b58d Leszek Koltunski
      {
411 31cd7256 Leszek Koltunski
      if( mMeshes[0]==null )
412
        {
413 f56b53cb Leszek Koltunski
        float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
414 31cd7256 Leszek Koltunski
        int[] bandIndexes   = new int[] { 0,0,0,0,0,0,0,0 };
415
        float[][] corners   = new float[][] { {0.04f,0.20f} };
416
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0 };
417 b3c9061a Leszek Koltunski
        float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
418
        int[] centerIndexes = new int[] { 0,0,0,0,0,0 };
419 31cd7256 Leszek Koltunski
420
        FactoryCubit factory = FactoryCubit.getInstance();
421
422
        factory.createNewFaceTransform(VERTICES_OCTA,VERT_INDEXES_OCTA);
423
        mMeshes[0] = factory.createRoundedSolid(VERTICES_OCTA, VERT_INDEXES_OCTA,
424
                                                bands, bandIndexes,
425
                                                corners, cornerIndexes,
426 b3c9061a Leszek Koltunski
                                                centers, centerIndexes,
427 31cd7256 Leszek Koltunski
                                                getNumCubitFaces() );
428
        }
429
      mesh = mMeshes[0].copy(true);
430 ece1b58d Leszek Koltunski
      }
431
    else
432
      {
433 31cd7256 Leszek Koltunski
      if( mMeshes[1]==null )
434
        {
435 f56b53cb Leszek Koltunski
        float[][] bands     = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
436 31cd7256 Leszek Koltunski
        int[] bandIndexes   = new int[] { 0,0,0,0 };
437
        float[][] corners   = new float[][] { {0.08f,0.15f} };
438
        int[] cornerIndexes = new int[] { 0,0,0,0 };
439 b3c9061a Leszek Koltunski
        float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
440
        int[] centerIndexes = new int[] { 0,0,0,0 };
441 31cd7256 Leszek Koltunski
442
        FactoryCubit factory = FactoryCubit.getInstance();
443
444
        factory.createNewFaceTransform(VERTICES_TETRA,VERT_INDEXES_TETRA);
445
        mMeshes[1] = factory.createRoundedSolid(VERTICES_TETRA, VERT_INDEXES_TETRA,
446
                                                bands, bandIndexes,
447
                                                corners, cornerIndexes,
448 b3c9061a Leszek Koltunski
                                                centers, centerIndexes,
449 31cd7256 Leszek Koltunski
                                                getNumCubitFaces() );
450
        }
451
      mesh = mMeshes[1].copy(true);
452 ece1b58d Leszek Koltunski
      }
453
454 680f921e Leszek Koltunski
    Static4D sQ = getQuat(cubit,numLayers,numO);
455
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( sQ, new Static3D(0,0,0) );
456 ece1b58d Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
457
458
    return mesh;
459
    }
460
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462
463 2ef489e2 Leszek Koltunski
  int getFaceColor(int cubit, int cubitface, int size)
464 ece1b58d Leszek Koltunski
    {
465 2ef489e2 Leszek Koltunski
    int numO = getNumOctahedrons(size);
466 680f921e Leszek Koltunski
467
    if( cubit<numO )
468
      {
469 2ef489e2 Leszek Koltunski
      int axis = 0;
470
      int layer= 1;
471
472
      switch(cubitface)
473
        {
474
        case 0: axis = 2; layer =             1; break;
475
        case 1: axis = 0; layer = (1<<(size-1)); break;
476
        case 2: axis = 3; layer =             1; break;
477
        case 3: axis = 1; layer = (1<<(size-1)); break;
478
        case 4: axis = 3; layer = (1<<(size-1)); break;
479
        case 5: axis = 1; layer =             1; break;
480
        case 6: axis = 2; layer = (1<<(size-1)); break;
481
        case 7: axis = 0; layer =             1; break;
482
        }
483
484 a4962b9c Leszek Koltunski
      return CUBITS[cubit].mRotationRow[axis] == layer ? cubitface : NUM_TEXTURES;
485 680f921e Leszek Koltunski
      }
486
    else
487
      {
488 a4962b9c Leszek Koltunski
      return cubitface>0 ? NUM_TEXTURES : retFaceTetraBelongsTo(cubit-numO, size);
489 680f921e Leszek Koltunski
      }
490 ece1b58d Leszek Koltunski
    }
491
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
494 ae755eda Leszek Koltunski
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
495 ece1b58d Leszek Koltunski
    {
496 76c2bd07 Leszek Koltunski
    float R = 0.06f;
497
    float S = 0.07f;
498
499 b89898c5 Leszek Koltunski
    FactorySticker factory = FactorySticker.getInstance();
500 31cd7256 Leszek Koltunski
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
501 ece1b58d Leszek Koltunski
    }
502
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504
505
  float returnMultiplier()
506
    {
507 cc99cf91 Leszek Koltunski
    return 1.5f;
508 ece1b58d Leszek Koltunski
    }
509
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511
// PUBLIC API
512
513
  public Static3D[] getRotationAxis()
514
    {
515
    return ROT_AXIS;
516
    }
517
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519
520 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
521 ece1b58d Leszek Koltunski
    {
522 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
523 ece1b58d Leszek Koltunski
    }
524
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526
527 9f171eba Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
528 ece1b58d Leszek Koltunski
    {
529 9f171eba Leszek Koltunski
    if( curr==0 )
530 ece1b58d Leszek Koltunski
      {
531 9f171eba Leszek Koltunski
      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
532 ece1b58d Leszek Koltunski
      }
533
    else
534
      {
535 582617c1 Leszek Koltunski
      int newVector = rnd.nextInt(NUM_AXIS -1);
536 9f171eba Leszek Koltunski
      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
537 ece1b58d Leszek Koltunski
      }
538
539
    float rowFloat = rnd.nextFloat();
540 0203be88 Leszek Koltunski
    int numLayers = getNumLayers();
541 ece1b58d Leszek Koltunski
542 0203be88 Leszek Koltunski
    for(int row=0; row<numLayers; row++)
543 ece1b58d Leszek Koltunski
      {
544 0203be88 Leszek Koltunski
      if( rowFloat*numLayers <= row+1 )
545 bbc6471c Leszek Koltunski
        {
546 9f171eba Leszek Koltunski
        scramble[curr][1] = row;
547 bbc6471c Leszek Koltunski
        break;
548
        }
549 ece1b58d Leszek Koltunski
      }
550
551 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(2) )
552
      {
553 9f171eba Leszek Koltunski
      case 0: scramble[curr][2] = -1; break;
554
      case 1: scramble[curr][2] =  1; break;
555 5043d5d0 Leszek Koltunski
      }
556 ece1b58d Leszek Koltunski
    }
557
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559 75a21cd6 Leszek Koltunski
// The Diamond is solved if and only if:
560 ece1b58d Leszek Koltunski
//
561 2ef489e2 Leszek Koltunski
// 1) all octahedrons are rotated with the same quat
562
// 2) all tetrahedrons might be also optionally rotated by a 'face neutral' pair of quats
563
//    (indexes of those are kept in the 'mFaceNeutralQuattIndex' table)
564 ad6f6f03 Leszek Koltunski
//
565 75a21cd6 Leszek Koltunski
// Note: this works for any size, because even if layers>3 - and then there are 'face-internal'
566
// octahedrons which, it would seem, can be rotated by those 'face neutral' pairs of quats - but
567
// in reality no, because if they were, the octahedrons would then not fit in the lattice...
568 ece1b58d Leszek Koltunski
569
  public boolean isSolved()
570
    {
571 ab0c28f0 Leszek Koltunski
    int q = CUBITS[0].mQuatIndex;
572 2ef489e2 Leszek Koltunski
    int layers = getNumLayers();
573
    int numO = getNumOctahedrons(layers);
574 ab0c28f0 Leszek Koltunski
575 2ef489e2 Leszek Koltunski
    for(int i=1; i<numO; i++)
576 ad6f6f03 Leszek Koltunski
      {
577 2ef489e2 Leszek Koltunski
      if( CUBITS[i].mQuatIndex != q ) return false;
578
      }
579 ad6f6f03 Leszek Koltunski
580 2ef489e2 Leszek Koltunski
    int qI, q1Index, q2Index, face;
581 ad6f6f03 Leszek Koltunski
582 2ef489e2 Leszek Koltunski
    for(int i=numO; i<NUM_CUBITS; i++)
583
      {
584
      face    = retFaceTetraBelongsTo(i-numO,layers);
585
      q1Index = mFaceNeutralQuatIndex[face][0];
586
      q2Index = mFaceNeutralQuatIndex[face][1];
587
      qI      = CUBITS[i].mQuatIndex;
588 ad6f6f03 Leszek Koltunski
589 2ef489e2 Leszek Koltunski
      if(  qI != q && qI != mulQuat(q,q1Index) && qI != mulQuat(q,q2Index) ) return false;
590 ad6f6f03 Leszek Koltunski
      }
591
592 2ef489e2 Leszek Koltunski
    return true;
593 ece1b58d Leszek Koltunski
    }
594
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596 ab0c28f0 Leszek Koltunski
// only needed for solvers - there are no Diamond solvers ATM
597 ece1b58d Leszek Koltunski
598
  public String retObjectString()
599
    {
600
    return "";
601
    }
602
603 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
604
605
  public int getObjectName(int numLayers)
606
    {
607 2ef489e2 Leszek Koltunski
    switch(numLayers)
608
      {
609
      case 2: return R.string.diam2;
610
      case 3: return R.string.diam3;
611 2adf1263 Leszek Koltunski
      case 4: return R.string.diam4;
612 2ef489e2 Leszek Koltunski
      }
613
614
    return 0;
615 6fd4a72c Leszek Koltunski
    }
616
617
///////////////////////////////////////////////////////////////////////////////////////////////////
618
619
  public int getInventor(int numLayers)
620
    {
621 2ef489e2 Leszek Koltunski
    switch(numLayers)
622
      {
623
      case 2: return R.string.diam2_inventor;
624
      case 3: return R.string.diam3_inventor;
625 2adf1263 Leszek Koltunski
      case 4: return R.string.diam4_inventor;
626 2ef489e2 Leszek Koltunski
      }
627
628
    return 0;
629 6fd4a72c Leszek Koltunski
    }
630
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632
633
  public int getComplexity(int numLayers)
634
    {
635 2ef489e2 Leszek Koltunski
    switch(numLayers)
636
      {
637 2adf1263 Leszek Koltunski
      case 2: return 4;
638
      case 3: return 6;
639
      case 4: return 8;
640 2ef489e2 Leszek Koltunski
      }
641
642
    return 0;
643 6fd4a72c Leszek Koltunski
    }
644 ece1b58d Leszek Koltunski
}