Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyCube.java @ 7d8cc029

1 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4 fdec60a3 Leszek Koltunski
// This file is part of Magic Cube.                                                              //
5 0c52af30 Leszek Koltunski
//                                                                                               //
6 fdec60a3 Leszek Koltunski
// Magic Cube is free software: you can redistribute it and/or modify                            //
7 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// Magic Cube is distributed in the hope that it will be useful,                                 //
12 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 1f9772f3 Leszek Koltunski
package org.distorted.objects;
21 0c52af30 Leszek Koltunski
22 ccf9fec5 Leszek Koltunski
import android.content.res.Resources;
23 0c52af30 Leszek Koltunski
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 0c52af30 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30 b32444ee Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
31 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
32 0c52af30 Leszek Koltunski
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34 6fd4a72c Leszek Koltunski
import org.distorted.main.R;
35 0c52af30 Leszek Koltunski
36 7c969a6d Leszek Koltunski
import java.util.Random;
37
38 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
39
40 9c2f0c91 Leszek Koltunski
class TwistyCube extends TwistyObject
41 0c52af30 Leszek Koltunski
{
42 e844c116 Leszek Koltunski
  // the three rotation axis of a RubikCube. Must be normalized.
43 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
44 efef689c Leszek Koltunski
         {
45
           new Static3D(1,0,0),
46
           new Static3D(0,1,0),
47
           new Static3D(0,0,1)
48
         };
49
50 37a25788 Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
51 efef689c Leszek Koltunski
         {
52 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
53
           COLOR_BLUE  , COLOR_GREEN,
54 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
55 efef689c Leszek Koltunski
         };
56
57 10585385 Leszek Koltunski
  // All legal rotation quats of a RubikCube of any size.
58 efef689c Leszek Koltunski
  // Here's how to compute this:
59
  // 1) compute how many rotations there are (RubikCube of any size = 24)
60
  // 2) take the AXIS, angles of rotation (90 in RubikCube's case) compute the basic quaternions
61
  // (i.e. rotations of 1 basic angle along each of the axis) and from there start semi-randomly
62
  // multiplying them and eventually you'll find all (24) legal rotations.
63 9f4c44fe Leszek Koltunski
  // Example program in C, res/raw/compute_quats.c , is included.
64 10585385 Leszek Koltunski
  private static final Static4D[] QUATS = new Static4D[]
65 efef689c Leszek Koltunski
         {
66 10585385 Leszek Koltunski
         new Static4D(  0.0f,   0.0f,   0.0f,   1.0f),
67
         new Static4D(  1.0f,   0.0f,   0.0f,   0.0f),
68
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
69
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
70
71
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
72
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
73
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
74
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
75
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
76
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
77
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
78
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
79
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
80
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
81
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
82
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
83
84
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
85
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
86
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
87
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
88
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
89
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
90
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
91
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
92 efef689c Leszek Koltunski
         };
93 411c6285 Leszek Koltunski
94 b1f2ccf5 Leszek Koltunski
  private static final double[][] VERTICES = new double[][]
95
          {
96
              { 0.5, 0.5, 0.5 },
97
              { 0.5, 0.5,-0.5 },
98
              { 0.5,-0.5, 0.5 },
99
              { 0.5,-0.5,-0.5 },
100
              {-0.5, 0.5, 0.5 },
101
              {-0.5, 0.5,-0.5 },
102
              {-0.5,-0.5, 0.5 },
103
              {-0.5,-0.5,-0.5 },
104
          };
105
106
  private static final int[][] VERT_INDEXES = new int[][]
107
          {
108
              {2,3,1,0},   // counterclockwise!
109
              {7,6,4,5},
110
              {4,0,1,5},
111
              {7,3,2,6},
112
              {6,2,0,4},
113
              {3,7,5,1}
114
          };
115
116
  private static final float[][] STICKERS = new float[][]
117
          {
118
              { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f }
119
          };
120
121 fbca0033 Leszek Koltunski
  private static MeshBase[] mMeshes;
122 40ab026e Leszek Koltunski
123 411c6285 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125 9c2f0c91 Leszek Koltunski
  TwistyCube(int size, Static4D quat, DistortedTexture texture,
126
             MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
127 411c6285 Leszek Koltunski
    {
128 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.CUBE, res, scrWidth);
129 411c6285 Leszek Koltunski
    }
130
131 ac940e24 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
132
133 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
134 ac940e24 Leszek Koltunski
    {
135
    if( mMeshes==null )
136
      {
137 b1f2ccf5 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
138
      factory.clear();
139 ac940e24 Leszek Koltunski
      mMeshes = new MeshBase[ObjectList.CUBE.getNumVariants()];
140
      }
141
142
    int ordinal= ObjectList.CUBE.ordinal();
143 d99f3a48 Leszek Koltunski
    int index  = ObjectList.getSizeIndex(ordinal,getNumLayers());
144 ac940e24 Leszek Koltunski
145
    if( mMeshes[index]==null )
146
      {
147 b1f2ccf5 Leszek Koltunski
      int extraI, extraV, num;
148
149
      switch(numLayers)
150
        {
151
        case 2 : num = 6; extraI = 2; extraV = 2; break;
152
        case 3 : num = 5; extraI = 2; extraV = 2; break;
153
        case 4 : num = 5; extraI = 1; extraV = 2; break;
154
        default: num = 5; extraI = 1; extraV = 0; break;
155
        }
156
157
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.7f,num,extraI,extraV} };
158
      int[] bandIndexes   = new int[] { 0,0,0,0,0,0};
159
      float[][] corners   = new float[][] { {0.036f,0.12f} };
160
      int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
161 b3c9061a Leszek Koltunski
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
162
      int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
163 b1f2ccf5 Leszek Koltunski
164
      FactoryCubit factory = FactoryCubit.getInstance();
165
166
      factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
167
      mMeshes[index] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
168
                                                  bands, bandIndexes,
169
                                                  corners, cornerIndexes,
170 b3c9061a Leszek Koltunski
                                                  centers, centerIndexes,
171 b1f2ccf5 Leszek Koltunski
                                                  getNumCubitFaces() );
172 ac940e24 Leszek Koltunski
      }
173
174
    return mMeshes[index].copy(true);
175
    }
176
177 7289fd6c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
178
179 ae755eda Leszek Koltunski
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
180 7289fd6c Leszek Koltunski
    {
181 76c2bd07 Leszek Koltunski
    float R = 0.10f;
182 2fcfce81 Leszek Koltunski
    float S = 0.08f;
183 7289fd6c Leszek Koltunski
184 b89898c5 Leszek Koltunski
    FactorySticker factory = FactorySticker.getInstance();
185 b1f2ccf5 Leszek Koltunski
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
186 7289fd6c Leszek Koltunski
    }
187
188 411c6285 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190 b1f2ccf5 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
191 a10ada2a Leszek Koltunski
    {
192 b1f2ccf5 Leszek Koltunski
    int numCubits = numLayers>1 ? 6*numLayers*numLayers - 12*numLayers + 8 : 1;
193 e6cf7283 Leszek Koltunski
    float[][] tmp = new float[numCubits][];
194 beb325a0 Leszek Koltunski
195 b1f2ccf5 Leszek Koltunski
    float diff = 0.5f*(numLayers-1);
196 a10ada2a Leszek Koltunski
    int currentPosition = 0;
197 beb325a0 Leszek Koltunski
198 b1f2ccf5 Leszek Koltunski
    for(int x = 0; x<numLayers; x++)
199
      for(int y = 0; y<numLayers; y++)
200
        for(int z = 0; z<numLayers; z++)
201
          if( x==0 || x==numLayers-1 || y==0 || y==numLayers-1 || z==0 || z==numLayers-1 )
202 beb325a0 Leszek Koltunski
            {
203 e6cf7283 Leszek Koltunski
            tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
204 a10ada2a Leszek Koltunski
            }
205 47ba5ddc Leszek Koltunski
206 a10ada2a Leszek Koltunski
    return tmp;
207
    }
208 47ba5ddc Leszek Koltunski
209 beb325a0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
210
211 10585385 Leszek Koltunski
  Static4D[] getQuats()
212 a10ada2a Leszek Koltunski
    {
213 10585385 Leszek Koltunski
    return QUATS;
214 a10ada2a Leszek Koltunski
    }
215 47ba5ddc Leszek Koltunski
216 eaee1ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
217
218
  boolean shouldResetTextureMaps()
219
    {
220
    return false;
221
    }
222
223 47ba5ddc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
224
225 411c6285 Leszek Koltunski
  int getNumFaces()
226 a10ada2a Leszek Koltunski
    {
227 411c6285 Leszek Koltunski
    return FACE_COLORS.length;
228 8f53e513 Leszek Koltunski
    }
229
230 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232 a64e07d0 Leszek Koltunski
  float[] getCuts(int numLayers)
233 7403cdfa Leszek Koltunski
    {
234 a64e07d0 Leszek Koltunski
    float[] cuts = new float[numLayers-1];
235 a97e02b7 Leszek Koltunski
236 a64e07d0 Leszek Koltunski
    for(int i=0; i<numLayers-1; i++)
237 a97e02b7 Leszek Koltunski
      {
238 a64e07d0 Leszek Koltunski
      cuts[i] = (2-numLayers)*0.5f + i;
239 a97e02b7 Leszek Koltunski
      }
240
241
    return cuts;
242 7403cdfa Leszek Koltunski
    }
243
244 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
245
246 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
247 eab9d8f8 Leszek Koltunski
    {
248 b1f2ccf5 Leszek Koltunski
    return STICKERS.length;
249 eab9d8f8 Leszek Koltunski
    }
250
251 8f53e513 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
252
253
  int getNumCubitFaces()
254
    {
255
    return FACE_COLORS.length;
256 411c6285 Leszek Koltunski
    }
257 47ba5ddc Leszek Koltunski
258 f0fa83ae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
259
260
  float getScreenRatio()
261
    {
262
    return 0.5f;
263
    }
264
265 f6d06256 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
266
267
  int getFaceColor(int cubit, int cubitface, int size)
268
    {
269 2ef489e2 Leszek Koltunski
    return CUBITS[cubit].mRotationRow[cubitface/2] == (cubitface%2==0 ? (1<<(size-1)):1) ? cubitface : NUM_FACES;
270 f6d06256 Leszek Koltunski
    }
271
272 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
273
274
  float returnMultiplier()
275
    {
276 d99f3a48 Leszek Koltunski
    return getNumLayers();
277 fb377dae Leszek Koltunski
    }
278
279 7c969a6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
280
281 a64e07d0 Leszek Koltunski
  float[] getRowChances(int numLayers)
282 7c969a6d Leszek Koltunski
    {
283 d99f3a48 Leszek Koltunski
    float[] chances = new float[numLayers];
284 7c969a6d Leszek Koltunski
285 d99f3a48 Leszek Koltunski
    for(int i=0; i<numLayers; i++)
286 7c969a6d Leszek Koltunski
      {
287 d99f3a48 Leszek Koltunski
      chances[i] = (i+1.0f) / numLayers;
288 7c969a6d Leszek Koltunski
      }
289
290
    return chances;
291
    }
292
293 e844c116 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
294
// PUBLIC API
295
296 12ad3fca Leszek Koltunski
  public Static3D[] getRotationAxis()
297
    {
298 ad38d800 Leszek Koltunski
    return ROT_AXIS;
299 12ad3fca Leszek Koltunski
    }
300
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302
303 e844c116 Leszek Koltunski
  public int getBasicAngle()
304
    {
305
    return 4;
306
    }
307 39e74052 Leszek Koltunski
308 7c969a6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
309
310 5043d5d0 Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
311 7c969a6d Leszek Koltunski
    {
312 5043d5d0 Leszek Koltunski
    if( num==0 )
313 5cf34c5f Leszek Koltunski
      {
314 5043d5d0 Leszek Koltunski
      scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length);
315 7c969a6d Leszek Koltunski
      }
316
    else
317
      {
318 bbc6471c Leszek Koltunski
      int newVector = rnd.nextInt(ROTATION_AXIS.length-1);
319 5043d5d0 Leszek Koltunski
      scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector);
320 5cf34c5f Leszek Koltunski
      }
321
322 7c969a6d Leszek Koltunski
    float rowFloat = rnd.nextFloat();
323
324
    for(int row=0; row<mRowChances.length; row++)
325
      {
326 bbc6471c Leszek Koltunski
      if( rowFloat<=mRowChances[row] )
327
        {
328 5043d5d0 Leszek Koltunski
        scramble[num][1] = row;
329 bbc6471c Leszek Koltunski
        break;
330
        }
331 7c969a6d Leszek Koltunski
      }
332
333 5043d5d0 Leszek Koltunski
    switch( rnd.nextInt(4) )
334
      {
335
      case 0: scramble[num][2] = -2; break;
336
      case 1: scramble[num][2] = -1; break;
337
      case 2: scramble[num][2] =  1; break;
338
      case 3: scramble[num][2] =  2; break;
339
      }
340 e46e17fb Leszek Koltunski
    }
341 f0336037 Leszek Koltunski
342 6b6504fe Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
343
344
  public boolean isSolved()
345
    {
346
    int index = CUBITS[0].mQuatIndex;
347
348
    for(int i=1; i<NUM_CUBITS; i++)
349
      {
350 722b2512 Leszek Koltunski
      if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
351 6b6504fe Leszek Koltunski
      }
352
353
    return true;
354
    }
355
356 f0336037 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
357 a304ee64 Leszek Koltunski
// order: Up --> Right --> Front --> Down --> Left --> Back
358
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)
359
//
360 fa0f7a56 Leszek Koltunski
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"
361 a304ee64 Leszek Koltunski
//
362 fa0f7a56 Leszek Koltunski
// s : size of the cube; let index = a*s + b    (i.e. a,b = row,column)
363
//
364
// Up    :   index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a
365 a304ee64 Leszek Koltunski
// Right :   index --> 6*s*s - 12*s + 7 - index
366 fa0f7a56 Leszek Koltunski
// Front :   index --> if b==0  : s*s - 1 - index
367
//                     if b==s-1: 6*s*s -11*s +6 - index
368
//                     else
369
//                         a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s
370
//                         else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a)
371
// Down  :   index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a
372
// Left  :   index --> (s-1-a)*s + b
373
// Back  :   index --> if b==s-1: s*(s-1-a)
374
//                     if b==0  : 5*s*s -12*s + 8 + (s-1-a)*s
375
//                     else
376
//                        if a==s-1: s*s + 4*(s-2-b)*(s-1)
377
//                        else     : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2
378 f0336037 Leszek Koltunski
379 20931cf6 Leszek Koltunski
  public String retObjectString()
380 f0336037 Leszek Koltunski
    {
381 fa0f7a56 Leszek Koltunski
    StringBuilder objectString = new StringBuilder();
382 d99f3a48 Leszek Koltunski
    int layers = getNumLayers();
383
    int len = layers*layers;
384 ac940e24 Leszek Koltunski
    int cubitIndex, row, col, color,face;
385 fa0f7a56 Leszek Koltunski
386
    final int RIGHT= 0;
387
    final int LEFT = 1;
388
    final int UP   = 2;
389
    final int DOWN = 3;
390
    final int FRONT= 4;
391
    final int BACK = 5;
392
393 fb52fae9 Leszek Koltunski
    // 'I' - interior, theoretically can happen
394
    final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B', 'I'};
395 49595e4b Leszek Koltunski
396
    face = UP;
397
398 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
399
      {
400 d99f3a48 Leszek Koltunski
      row = i/layers;
401
      col = i%layers;
402 fa0f7a56 Leszek Koltunski
403 d99f3a48 Leszek Koltunski
      cubitIndex = col<layers-1 ? (layers-1)*(layers+4*col) + row : 6*layers*layers - 13*layers + 8 + row;
404 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
405 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
406
      }
407
408 49595e4b Leszek Koltunski
    face = RIGHT;
409
410 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
411
      {
412 d99f3a48 Leszek Koltunski
      cubitIndex = 6*layers*layers - 12*layers +7 - i;
413 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
414 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
415
      }
416
417 064ccc31 Leszek Koltunski
    face = FRONT;
418 49595e4b Leszek Koltunski
419 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
420
      {
421 d99f3a48 Leszek Koltunski
      row = i/layers;
422
      col = i%layers;
423 fa0f7a56 Leszek Koltunski
424 d99f3a48 Leszek Koltunski
      if( col==layers-1 ) cubitIndex = 6*layers*layers - 11*layers + 6 -i;
425
      else if(   col==0 ) cubitIndex = layers*layers - 1 - i;
426 fa0f7a56 Leszek Koltunski
      else
427
        {
428 d99f3a48 Leszek Koltunski
        if( row==0 ) cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-2) + layers;
429
        else         cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-1-row);
430 fa0f7a56 Leszek Koltunski
        }
431
432 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
433 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
434
      }
435
436 49595e4b Leszek Koltunski
    face = DOWN;
437
438 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
439
      {
440 d99f3a48 Leszek Koltunski
      row = i/layers;
441
      col = i%layers;
442 fa0f7a56 Leszek Koltunski
443 d99f3a48 Leszek Koltunski
      cubitIndex = col==0 ? layers-1-row : layers*layers + layers-1 + 4*(col-1)*(layers-1) - row;
444 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
445 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
446
      }
447
448 49595e4b Leszek Koltunski
    face = LEFT;
449
450 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
451
      {
452 d99f3a48 Leszek Koltunski
      row = i/layers;
453
      col = i%layers;
454 fa0f7a56 Leszek Koltunski
455 d99f3a48 Leszek Koltunski
      cubitIndex = (layers-1-row)*layers + col;
456 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
457 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
458
      }
459
460 49595e4b Leszek Koltunski
    face = BACK;
461
462 fa0f7a56 Leszek Koltunski
    for(int i=0; i<len; i++)
463
      {
464 d99f3a48 Leszek Koltunski
      row = i/layers;
465
      col = i%layers;
466 fa0f7a56 Leszek Koltunski
467 d99f3a48 Leszek Koltunski
      if( col==layers-1 ) cubitIndex = layers*(layers-1-row);
468
      else if(   col==0 ) cubitIndex = 5*layers*layers - 12*layers + 8 + (layers-1-row)*layers;
469 fa0f7a56 Leszek Koltunski
      else
470
        {
471 d99f3a48 Leszek Koltunski
        if( row==layers-1 ) cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1);
472
        else                cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1) + layers + 2*(layers-2-row);
473 fa0f7a56 Leszek Koltunski
        }
474
475 49595e4b Leszek Koltunski
      color = getCubitFaceColorIndex(cubitIndex,face);
476 fa0f7a56 Leszek Koltunski
      objectString.append(FACE_NAMES[color]);
477
      }
478
479
    return objectString.toString();
480 f0336037 Leszek Koltunski
    }
481 6fd4a72c Leszek Koltunski
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483
484
  public int getObjectName(int numLayers)
485
    {
486
    switch(numLayers)
487
      {
488
      case 2: return R.string.cube2;
489
      case 3: return R.string.cube3;
490
      case 4: return R.string.cube4;
491
      case 5: return R.string.cube5;
492
      }
493
    return R.string.cube3;
494
    }
495
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497
498
  public int getInventor(int numLayers)
499
    {
500
    switch(numLayers)
501
      {
502
      case 2: return R.string.cube2_inventor;
503
      case 3: return R.string.cube3_inventor;
504
      case 4: return R.string.cube4_inventor;
505
      case 5: return R.string.cube5_inventor;
506
      }
507
    return R.string.cube3_inventor;
508
    }
509
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511
512
  public int getComplexity(int numLayers)
513
    {
514
    switch(numLayers)
515
      {
516
      case 2: return 4;
517
      case 3: return 6;
518
      case 4: return 8;
519
      case 5: return 10;
520
      }
521
    return 6;
522
    }
523 0c52af30 Leszek Koltunski
}