Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare2.java @ d5380277

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static4D;
31
import org.distorted.main.R;
32

    
33
import java.util.Random;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
class TwistySquare2 extends TwistySquare
38
{
39
  private static final int NUM_STICKERS = 6;
40

    
41
  private int mCurrState;
42
  private int mIndexExcluded;
43
  private final ScrambleState[] mStates;
44
  private int[][] mScrambleTable;
45
  private int[] mNumOccurences;
46
  private int[] mQuatNumber;
47
  private float[][] mCenters;
48
  private int[][] mStickerColor;
49
  private int[][] mStickerType;
50
  private ObjectSticker[] mStickers;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
55
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
56
    {
57
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
58

    
59
    int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
60
    int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
61
    int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
62
    int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
63
    int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
64

    
65
    mStates = new ScrambleState[]
66
      {
67
      new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
68
      new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
69
      new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
70
      new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
71
      new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
72
      };
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  int[] getSolvedQuats(int cubit, int numLayers)
78
    {
79
    return null;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  ObjectShape getObjectShape(int cubit, int numLayers)
85
    {
86
    int variant = getCubitVariant(cubit,numLayers);
87

    
88
    if( variant==0 )
89
      {
90
      double[][] vertices = new double[][]
91
        {
92
         { -1.5-X, 0.5, 1.5 },
93
         {    0.0, 0.5, 1.5 },
94
         {    0.0, 0.5,-1.5 },
95
         { -1.5+X, 0.5,-1.5 },
96
         { -1.5-X,-0.5, 1.5 },
97
         {    0.0,-0.5, 1.5 },
98
         {    0.0,-0.5,-1.5 },
99
         { -1.5+X,-0.5,-1.5 }
100
        };
101

    
102
      int[][] vert_indices = new int[][]
103
        {
104
         {0,1,2,3},
105
         {4,5,6,7},
106
         {4,5,1,0},
107
         {5,6,2,1},
108
         {6,7,3,2},
109
         {7,4,0,3}
110
        };
111

    
112
      float[][] bands     = new float[][] { {0.040f,35,0.8f,1.0f,5,2,1}, {0.020f,35,0.8f,1.0f,5,2,1}, {0.001f,35,0.8f,1.0f,5,2,1} };
113
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
114
      float[][] corners   = new float[][] { {0.03f,0.05f} };
115
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
116
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
117
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
118
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
119
      }
120
    else if( variant==1 )
121
      {
122
      double[][] vertices = new double[][]
123
        {
124
         { -X, 0.5, 0.0 },
125
         { +X, 0.5, 0.0 },
126
         {0.0, 0.5,-1.5 },
127
         { -X,-0.5, 0.0 },
128
         { +X,-0.5, 0.0 },
129
         {0.0,-0.5,-1.5 },
130
        };
131

    
132
      int[][] vert_indices = new int[][]
133
        {
134
         {0,1,2},
135
         {3,4,5},
136
         {3,4,1,0},
137
         {4,5,2,1},
138
         {5,3,0,2}
139
        };
140

    
141
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
142
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
143
      float[][] corners   = new float[][] { {0.04f,0.15f} };
144
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
145
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
146
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
147
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
148
      }
149
    else
150
      {
151
      double[][] vertices = new double[][]
152
        {
153
         {-0.75f+X/2, 0.5,  0.0 },
154
         { 0.75f-X/2, 0.5,  0.0 },
155
         {-0.75f-X/2, 0.5, -1.5 },
156
         {-0.75f+X/2,-0.5,  0.0 },
157
         { 0.75f-X/2,-0.5,  0.0 },
158
         {-0.75f-X/2,-0.5, -1.5 }
159
        };
160
      int[][] vert_indices = new int[][]
161
        {
162
         {0,1,2},
163
         {5,4,3},
164
         {3,4,1,0},
165
         {4,5,2,1},
166
         {5,3,0,2}
167
        };
168

    
169
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
170
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
171
      float[][] corners   = new float[][] { {0.05f,0.13f} };
172
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
173
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
174
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
175
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
176
      }
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  Static4D getQuat(int cubit, int numLayers)
182
    {
183
    if( mQuats==null ) initializeQuats();
184

    
185
    if( mQuatNumber ==null )
186
      {
187
      mQuatNumber = new int[]
188
        {
189
        0, 6,
190
        0, 9, 6, 3, 18, 15, 12, 21,
191
        0, 9, 6, 3, 0, 9, 6, 3,
192
        15, 12, 21, 18, 15, 12, 21, 18
193
        };
194
      }
195

    
196
    return mQuats[mQuatNumber[cubit]];
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  int getNumCubitVariants(int numLayers)
202
    {
203
    return 3;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  int getCubitVariant(int cubit, int numLayers)
209
    {
210
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  ObjectSticker retSticker(int face)
216
    {
217
    if( mStickers==null )
218
      {
219
      float[][] STICKERS = new float[][]
220
        {
221
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
222
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
223
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
224
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
225
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
226
          { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
227
        };
228

    
229
      final float R1 = 0.06f;
230
      final float R2 = 0.04f;
231
      final float R3 = 0.11f;
232
      final float R4 = 0.03f;
233
      final float R5 = 0.11f;
234
      final float R6 = 0.025f;
235
      final float[][] radii  = { {R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4},{R5,R5,R5,R5},{R6,R6,R6} };
236
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
237

    
238
      mStickers = new ObjectSticker[NUM_STICKERS];
239

    
240
      for(int s=0; s<NUM_STICKERS; s++)
241
        {
242
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
243
        }
244
      }
245

    
246
    return mStickers[face/NUM_FACES];
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  float[][] getCubitPositions(int numLayers)
252
    {
253
    if( mCenters ==null )
254
      {
255
      float Y = 0.75f + X/2;
256

    
257
      mCenters = new float[][]
258
        {
259
         { 1.5f, 0.0f, 0.0f },
260
         {-1.5f, 0.0f, 0.0f },
261

    
262
         { 0.0f, 1.0f, 1.5f },
263
         { 1.5f, 1.0f, 0.0f },
264
         { 0.0f, 1.0f,-1.5f },
265
         {-1.5f, 1.0f, 0.0f },
266
         { 0.0f,-1.0f, 1.5f },
267
         { 1.5f,-1.0f, 0.0f },
268
         { 0.0f,-1.0f,-1.5f },
269
         {-1.5f,-1.0f, 0.0f },
270

    
271
         {    Y, 1.0f, 1.5f },
272
         { 1.5f, 1.0f,   -Y },
273
         {   -Y, 1.0f,-1.5f },
274
         {-1.5f, 1.0f,    Y },
275
         {    Y,-1.0f, 1.5f },
276
         { 1.5f,-1.0f,   -Y },
277
         {   -Y,-1.0f,-1.5f },
278
         {-1.5f,-1.0f,    Y },
279

    
280
         { 1.5f, 1.0f,    Y },
281
         {    Y, 1.0f,-1.5f },
282
         {-1.5f, 1.0f,   -Y },
283
         {   -Y, 1.0f, 1.5f },
284
         { 1.5f,-1.0f,    Y },
285
         {    Y,-1.0f,-1.5f },
286
         {-1.5f,-1.0f,   -Y },
287
         {   -Y,-1.0f, 1.5f },
288
        };
289
      }
290

    
291
    return mCenters;
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  int getSolvedFunctionIndex()
297
    {
298
    return 3;
299
    }
300

    
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

    
303
  int getNumStickerTypes(int numLayers)
304
    {
305
    return NUM_STICKERS;
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  int getFaceColor(int cubit, int cubitface, int numLayers)
311
    {
312
    if( mStickerColor==null )
313
      {
314
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
315
      mStickerColor = new int[][]
316
        {
317
         { 0, 0, 4, 0, 5, 0 }, // 0
318
         { 0, 0, 5, 1, 4, 0 },
319

    
320
         { 2, 0, 4, 0, 0, 0 }, // 2
321
         { 2, 0, 0, 0, 0, 0 },
322
         { 2, 0, 5, 0, 0, 0 },
323
         { 2, 0, 1, 0, 0, 0 },
324
         { 3, 0, 4, 0, 0, 0 },
325
         { 3, 0, 0, 0, 0, 0 },
326
         { 3, 0, 5, 0, 0, 0 },
327
         { 3, 0, 1, 0, 0, 0 },
328

    
329
         { 2, 0, 4, 0, 0, 0 }, // 10
330
         { 2, 0, 0, 0, 0, 0 },
331
         { 2, 0, 5, 0, 0, 0 },
332
         { 2, 0, 1, 0, 0, 0 },
333
         { 0, 3, 4, 0, 0, 0 },
334
         { 0, 3, 0, 0, 0, 0 },
335
         { 0, 3, 5, 0, 0, 0 },
336
         { 0, 3, 1, 0, 0, 0 },
337

    
338
         { 0, 2, 0, 0, 0, 0 }, // 18
339
         { 0, 2, 5, 0, 0, 0 },
340
         { 0, 2, 1, 0, 0, 0 },
341
         { 0, 2, 4, 0, 0, 0 },
342
         { 3, 0, 0, 0, 0, 0 },
343
         { 3, 0, 5, 0, 0, 0 },
344
         { 3, 0, 1, 0, 0, 0 },
345
         { 3, 0, 4, 0, 0, 0 },
346
        };
347
      }
348

    
349
    if( mStickerType==null )
350
      {
351
      mStickerType = new int[][]
352
        {
353
         {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
354
         {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
355
         {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
356
         {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
357
        };
358
      }
359

    
360
    int type;
361

    
362
         if( cubit< 2             ) type = 0;
363
    else if( cubit<10             ) type = 1;
364
    else if( cubit>13 && cubit<22 ) type = 3;
365
    else                            type = 2;
366

    
367
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  private void initializeScrambling()
373
    {
374
    int numLayers = getNumLayers();
375

    
376
    if( mScrambleTable ==null )
377
      {
378
      mScrambleTable = new int[NUM_AXIS][numLayers];
379
      }
380
    if( mNumOccurences ==null )
381
      {
382
      int max=0;
383

    
384
      for (ScrambleState mState : mStates)
385
        {
386
        int tmp = mState.getTotal(-1);
387
        if (max < tmp) max = tmp;
388
        }
389

    
390
      mNumOccurences = new int[max];
391
      }
392

    
393
    for(int i=0; i<NUM_AXIS; i++)
394
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
// PUBLIC API
399

    
400
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
401
    {
402
    if( curr==0 )
403
      {
404
      mCurrState     = 0;
405
      mIndexExcluded =-1;
406
      initializeScrambling();
407
      }
408

    
409
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
410

    
411
    scramble[curr][0] = info[0];
412
    scramble[curr][1] = info[1];
413
    scramble[curr][2] = info[2];
414

    
415
    mCurrState     = info[3];
416
    mIndexExcluded = info[0];
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public int getObjectName(int numLayers)
422
    {
423
    return R.string.squa2;
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  public int getInventor(int numLayers)
429
    {
430
    return R.string.squa2_inventor;
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public int getComplexity(int numLayers)
436
    {
437
    return 7;
438
    }
439
}
(40-40/41)