Project

General

Profile

« Previous | Next » 

Revision a8d83300

Added by Leszek Koltunski about 1 year ago

Minor.

View differences:

src/main/java/org/distorted/objectlib/tablebases/ImplementedTablebasesList.java
20 20

  
21 21
public enum ImplementedTablebasesList
22 22
{
23
  PYRAMINX_DUO  (ObjectSignatures.PDUO_2, TablebasesPyraminxDuo.class),
24
  IVY_CUBE      (ObjectSignatures.IVY_2 , TablebasesIvyCube.class),
25
  CU_232        (ObjectSignatures.CU_232, TablebasesCuboid232.class),
26
  PYRA_3        (ObjectSignatures.PYRA_3, TablebasesPyraminx.class),
27
  DIAMOND       (ObjectSignatures.DIAM_2, TablebasesSkewbDiamond.class),
28
  CUBE2         (ObjectSignatures.CUBE_2, TablebasesCube2.class),
23
  PYRAMINX_DUO  (ObjectSignatures.PDUO_2, TBPyraminxDuo.class),
24
  IVY_CUBE      (ObjectSignatures.IVY_2 , TBIvyCube.class),
25
  CU_232        (ObjectSignatures.CU_232, TBCuboid232.class),
26
  PYRA_3        (ObjectSignatures.PYRA_3, TBPyraminx.class),
27
  DIAMOND       (ObjectSignatures.DIAM_2, TBSkewbDiamond.class),
28
  CUBE2         (ObjectSignatures.CUBE_2, TBCube2.class),
29 29
  ;
30 30

  
31 31
  public static final int NUM_OBJECTS = values().length;
src/main/java/org/distorted/objectlib/tablebases/TBCube2.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
12
import android.content.res.Resources;
13

  
14
import org.distorted.library.main.QuatHelper;
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
import org.distorted.objectlib.R;
18

  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

  
21
public class TBCube2 extends TablebasesPruning
22
{
23
  private static final int[][] P =
24
      {
25
            { 2,-1,-1},
26
            { 2,-1, 1},
27
            { 2, 1,-1},
28
            { 2, 1, 1},
29
            {-2,-1,-1},
30
            {-2,-1, 1},
31
            {-2, 1,-1},
32
            {-2, 1, 1},
33

  
34
            {-1, 2,-1},
35
            { 1, 2,-1},
36
            {-1, 2, 1},
37
            { 1, 2, 1},
38
            {-1,-2,-1},
39
            { 1,-2,-1},
40
            {-1,-2, 1},
41
            { 1,-2, 1},
42

  
43
            {-1,-1, 2},
44
            { 1,-1, 2},
45
            {-1, 1, 2},
46
            { 1, 1, 2},
47
            {-1,-1,-2},
48
            { 1,-1,-2},
49
            {-1, 1,-2},
50
            { 1, 1,-2},
51
      };
52

  
53
  private static final int[][] PT =
54
      {
55
          {4,0},{5,0},{6,0},{7,0},
56
          {0,0},{1,0},{2,0},{3,0},
57
          {2,2},{6,1},{3,1},{7,2},
58
          {0,1},{4,2},{1,2},{5,1},
59
          {1,1},{5,2},{3,2},{7,1},
60
          {0,2},{4,1},{2,1},{6,2}
61
      };
62

  
63
  private int[][][] mQuatsMap;
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  public TBCube2()
68
    {
69
    super();
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  public TBCube2(Resources res)
75
    {
76
    super(res, new int[] {R.raw.cube_2_pruning4,R.raw.cube_2_pruning5}, new int[] {R.raw.cube_2_pruning11} );
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
  int[][] getBasicAngles()
82
    {
83
    int[] tmp = {4,4};
84
    return new int[][] { tmp,tmp,tmp };
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  Static3D[] getRotationAxis()
90
    {
91
    return new Static3D[]
92
         {
93
           new Static3D(1,0,0),
94
           new Static3D(0,1,0),
95
           new Static3D(0,0,1)
96
         };
97
    }
98

  
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

  
101
  float[][] getPosition()
102
    {
103
    return new float[][]
104
      {
105
        { -0.5f, -0.5f, -0.5f },
106
        { -0.5f, -0.5f,  0.5f },
107
        { -0.5f,  0.5f, -0.5f },
108
        { -0.5f,  0.5f,  0.5f },
109
        {  0.5f, -0.5f, -0.5f },
110
        {  0.5f, -0.5f,  0.5f },
111
        {  0.5f,  0.5f, -0.5f },
112
        {  0.5f,  0.5f,  0.5f },
113
      };
114
    }
115

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
  float[][] getCuts()
119
    {
120
    return new float[][] { {0.0f}, {0.0f}, {0.0f} };
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  boolean[][] getRotatable()
126
    {
127
    return new boolean[][] { {false,true},{false,true},{true,false} };
128
    }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// specifically for the tablebase
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
// 7!*3^6 --> https://www.jaapsch.net/puzzles/cube2.htm
134

  
135
  int getSize()
136
    {
137
    return 3674160;
138
    }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
  int getMinScramble()
143
    {
144
    return 9;
145
    }
146

  
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

  
149
  int[] getMidPruningLevels()
150
    {
151
    return new int[] {4,5};
152
    }
153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

  
156
  int[] getHighPruningLevels()
157
    {
158
    return new int[] {11};
159
    }
160

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  int getGodsNumber()
164
    {
165
    return 11;
166
    }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

  
170
  private int[] getPermTwist(float[] point)
171
    {
172
    float ERR = 0.01f;
173

  
174
    for(int i=0; i<24; i++)
175
      {
176
      float dx = point[0]-P[i][0];
177
      float dy = point[1]-P[i][1];
178
      float dz = point[2]-P[i][2];
179

  
180
      if( dx*dx + dy*dy + dz*dz < ERR ) return PT[i];
181
      }
182

  
183
    return null;
184
    }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
  private void fillOutMap(float[] buffer, int[][] map, float[] point, Static4D quat, int quatIndex)
189
    {
190
    QuatHelper.rotateVectorByQuat(buffer,point[0],point[1],point[2],1,quat);
191
    int[] pt = getPermTwist(buffer);
192
    map[pt[0]][pt[1]] = quatIndex;
193
    }
194

  
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

  
197
  private void computeMap()
198
    {
199
    final float[][] POINTS =
200
        {
201
            {-2,-1,-1},
202
            {-2,-1, 1},
203
            {-2, 1,-1},
204
            {-2, 1, 1},
205
            { 2,-1,-1},
206
            { 2,-1, 1},
207
            { 2, 1,-1},
208
            { 2, 1, 1},
209
        };
210

  
211
    mQuatsMap = new int[8][8][3];
212
    Static4D[] quats = getQuats();
213
    float[] buffer = new float[4];
214

  
215
    for(int c=0; c<8; c++)
216
      for(int q=0; q<24; q++)
217
        fillOutMap(buffer,mQuatsMap[c],POINTS[c],quats[q],q);
218
    }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

  
222
  public static int[] shrinkPerm(int[] perm8)
223
    {
224
    int[] perm7 = new int[7];
225

  
226
    int tmp = perm8[0];
227
    perm7[0] = tmp>1 ? tmp-1 : tmp;
228
    tmp = perm8[2];
229
    perm7[1] = tmp>1 ? tmp-1 : tmp;
230
    tmp = perm8[3];
231
    perm7[2] = tmp>1 ? tmp-1 : tmp;
232
    tmp = perm8[4];
233
    perm7[3] = tmp>1 ? tmp-1 : tmp;
234
    tmp = perm8[5];
235
    perm7[4] = tmp>1 ? tmp-1 : tmp;
236
    tmp = perm8[6];
237
    perm7[5] = tmp>1 ? tmp-1 : tmp;
238
    tmp = perm8[7];
239
    perm7[6] = tmp>1 ? tmp-1 : tmp;
240

  
241
    return perm7;
242
    }
243

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

  
246
  private static int[] growPerm(int[] perm7)
247
    {
248
    int[] perm8 = new int[8];
249
    int tmp = perm7[0];
250
    perm8[0] = tmp>=1 ? tmp+1 : tmp;
251
    perm8[1] = 1;
252
    tmp = perm7[1];
253
    perm8[2] = tmp>=1 ? tmp+1 : tmp;
254
    tmp = perm7[2];
255
    perm8[3] = tmp>=1 ? tmp+1 : tmp;
256
    tmp = perm7[3];
257
    perm8[4] = tmp>=1 ? tmp+1 : tmp;
258
    tmp = perm7[4];
259
    perm8[5] = tmp>=1 ? tmp+1 : tmp;
260
    tmp = perm7[5];
261
    perm8[6] = tmp>=1 ? tmp+1 : tmp;
262
    tmp = perm7[6];
263
    perm8[7] = tmp>=1 ? tmp+1 : tmp;
264

  
265
    return perm8;
266
    }
267

  
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

  
270
  private int[] getPerm(int permNum)
271
    {
272
    int[] perm7 = new int[7];
273
    TablebaseHelpers.getPermutationFromNum(perm7,7,permNum);
274
    return growPerm(perm7);
275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  private int[] getTwist(int twistNum)
280
    {
281
    int[] twist = new int[8];
282
    twist[0] = twistNum%3;
283
    twist[1] = 0;
284
    twistNum /=3;
285
    twist[2] = twistNum%3;
286
    twistNum /=3;
287
    twist[3] = twistNum%3;
288
    twistNum /=3;
289
    twist[4] = twistNum%3;
290
    twistNum /=3;
291
    twist[5] = twistNum%3;
292
    twistNum /=3;
293
    twist[6] = twistNum%3;
294

  
295
    int total = (twist[0]+twist[2]+twist[3]+twist[4]+twist[5]+twist[6])%3;
296
    if( total==0 ) twist[7] = 0;
297
    else twist[7] = 3-total;
298

  
299
    return twist;
300
    }
301

  
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

  
304
  public int[] getQuats(int index)
305
    {
306
    if( mQuatsMap==null ) computeMap();
307

  
308
    int twistNum = index%729;
309
    int permuNum = index/729;
310

  
311
    int[] twist = getTwist(twistNum);
312
    int[] perm  = getPerm(permuNum);
313

  
314
    int[] quats = new int[8];
315
    for(int i=0; i<8; i++) quats[i] = mQuatsMap[i][perm[i]][twist[i]];
316

  
317
    return quats;
318
    }
319

  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

  
322
  private void extractTwistAndPerm(int quat, int[][] map, int[] twist, int[] perm, int index)
323
    {
324
    for(int i=0; i<8; i++)
325
      for(int j=0; j<3; j++)
326
        if( map[i][j]==quat )
327
          {
328
          twist[index] = j;
329
          perm[index] = i;
330
          break;
331
          }
332
    }
333

  
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

  
336
  public int getIndex(int[] quats)
337
    {
338
    if( mQuatsMap==null ) computeMap();
339

  
340
    int[] twist = new int[8];
341
    int[] perm8 = new int[8];
342

  
343
    for(int i=0; i<8; i++) extractTwistAndPerm(quats[i],mQuatsMap[i],twist,perm8,i);
344

  
345
    int[] perm7 = shrinkPerm(perm8);
346
    int twistNum = twist[0] + 3*(twist[2] + 3*(twist[3] + 3*(twist[4] + 3*(twist[5] + 3*twist[6]))));
347
    int permNum  = TablebaseHelpers.computePermutationNum(perm7);
348

  
349
    return twistNum + 729*permNum;
350
    }
351
}  
352

  
src/main/java/org/distorted/objectlib/tablebases/TBCuboid232.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
12
import android.content.res.Resources;
13

  
14
import org.distorted.library.type.Static3D;
15

  
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

  
18
public class TBCuboid232 extends TablebasesAbstract
19
{
20
  private static final int[][] CORNER_MAP = new int[][]
21
      {
22
          {0,4,7,1,2,3,5,6},
23
          {2,0,1,6,3,4,7,5},
24
          {7,1,0,4,5,6,2,3},
25
          {1,6,2,0,7,5,3,4},
26
          {4,3,5,7,0,2,6,1},
27
          {3,2,6,5,4,0,1,7},
28
          {5,7,4,3,6,1,0,2},
29
          {6,5,3,2,1,7,4,0}
30
      };
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
  public TBCuboid232()
35
    {
36
    super();
37
    }
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
  public TBCuboid232(Resources res)
42
    {
43
    super(res,org.distorted.objectlib.R.raw.cu_232_tablebase);
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  int[][] getBasicAngles()
49
    {
50
    int[] tmp2 = {2,2};
51
    int[] tmp4 = {4,4,4};
52
    return new int[][] { tmp2,tmp4,tmp2 };
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  Static3D[] getRotationAxis()
58
    {
59
    return new Static3D[]
60
         {
61
           new Static3D(1,0,0),
62
           new Static3D(0,1,0),
63
           new Static3D(0,0,1)
64
         };
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  float[][] getPosition()
70
    {
71
    return new float[][]
72
      {
73
        { -0.5f, -1.0f, -0.5f },
74
        { -0.5f, -1.0f,  0.5f },
75
        { -0.5f,  1.0f, -0.5f },
76
        { -0.5f,  1.0f,  0.5f },
77
        {  0.5f, -1.0f, -0.5f },
78
        {  0.5f, -1.0f,  0.5f },
79
        {  0.5f,  1.0f, -0.5f },
80
        {  0.5f,  1.0f,  0.5f },
81

  
82
        { -0.5f,  0.0f, -0.5f },
83
        { -0.5f,  0.0f,  0.5f },
84
        {  0.5f,  0.0f, -0.5f },
85
        {  0.5f,  0.0f,  0.5f },
86
      };
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
  float[][] getCuts()
92
    {
93
    return new float[][] { {0.0f}, {-0.5f,0.5f}, {0.0f} };
94
    }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
  boolean[][] getRotatable()
99
    {
100
    return new boolean[][] { {false,true},{true,false,true},{true,false} };
101
    }
102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
// specifically for the tablebase
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// 8!*3! --> https://www.jaapsch.net/puzzles/cube223.htm
107

  
108
  int getSize()
109
    {
110
    return 241920;
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  int getMinScramble()
116
    {
117
    return 12;
118
    }
119

  
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

  
122
  private void getCornerQuats(int[] output, int[] perm)
123
    {
124
    for(int i=0; i<8; i++)
125
      output[i] = CORNER_MAP[i][perm[i]];
126
    }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
  private int[] getCornerPerm(int[] quats)
131
    {
132
    int[] output = new int[8];
133

  
134
    for(int i=0; i<8; i++)
135
      {
136
      int quat = quats[i];
137

  
138
      for(int j=0; j<8; j++)
139
        {
140
        if( CORNER_MAP[i][j]==quat )
141
          {
142
          output[i]=j;
143
          break;
144
          }
145
        }
146
      }
147

  
148
    return output;
149
    }
150

  
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

  
153
  private void getEdgeQuats(int[] output, int[] perm)
154
    {
155
    switch(perm[0])
156
      {
157
      case 0: output[8] = 0; break;
158
      case 2: output[8] = 5; break;
159
      case 3: output[8] = 3; break;
160
      default: android.util.Log.e("D", "getEdgeQuats ERROR1");
161
      }
162

  
163
    output[9] = 0;
164

  
165
    switch(perm[2])
166
      {
167
      case 0: output[10] = 5; break;
168
      case 2: output[10] = 0; break;
169
      case 3: output[10] = 1; break;
170
      default: android.util.Log.e("D", "getEdgeQuats ERROR2");
171
      }
172

  
173
    switch(perm[3])
174
      {
175
      case 0: output[11] = 3; break;
176
      case 2: output[11] = 1; break;
177
      case 3: output[11] = 0; break;
178
      default: android.util.Log.e("D", "getEdgeQuats ERROR3");
179
      }
180
    }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
  private int[] getEdgePerm(int[] quats)
185
    {
186
    int[] output = new int[4];
187

  
188
    switch(quats[8])
189
      {
190
      case 0: output[0] = 0; break;
191
      case 5: output[0] = 2; break;
192
      case 3: output[0] = 3; break;
193
      default: android.util.Log.e("D", "getEdgePerm ERROR1");
194
      }
195

  
196
    output[1] = 1;
197

  
198
    switch(quats[10])
199
      {
200
      case 0: output[2] = 2; break;
201
      case 1: output[2] = 3; break;
202
      case 5: output[2] = 0; break;
203
      default: android.util.Log.e("D", "getEdgePerm ERROR2");
204
      }
205

  
206
    switch(quats[11])
207
      {
208
      case 0: output[3] = 3; break;
209
      case 1: output[3] = 2; break;
210
      case 3: output[3] = 0; break;
211
      default: android.util.Log.e("D", "getEdgePerm ERROR3");
212
      }
213

  
214
    return output;
215
    }
216

  
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

  
219
  private int[] uncollapseEdgePerm(int[] perm)
220
    {
221
    int[] ret = new int[4];
222

  
223
    ret[0] = perm[0];
224
    ret[1] = 1;
225
    ret[2] = perm[1];
226
    ret[3] = perm[2];
227

  
228
    if( ret[0]>=1 ) ret[0]++;
229
    if( ret[2]>=1 ) ret[2]++;
230
    if( ret[3]>=1 ) ret[3]++;
231

  
232
    return ret;
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
  public int[] getQuats(int index)
238
    {
239
    int[] quats = new int[12];
240

  
241
    int edge_perm_num = index%6;
242
    int corn_perm_num = index/6;
243

  
244
    int[] edge_perm = new int[3];
245
    TablebaseHelpers.getPermutationFromNum(edge_perm,3,edge_perm_num);
246

  
247
    int[] corn_perm = new int[8];
248
    TablebaseHelpers.getPermutationFromNum(corn_perm,8,corn_perm_num);
249

  
250
    int[] edge_perm2 = uncollapseEdgePerm(edge_perm);
251
    getCornerQuats(quats,corn_perm);
252
    getEdgeQuats(quats,edge_perm2);
253

  
254
    return quats;
255
    }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
  private int[] collapseEdgePerm(int[] perm)
260
    {
261
    int[] ret = new int[3];
262

  
263
    ret[0] = perm[0];
264
    ret[1] = perm[2];
265
    ret[2] = perm[3];
266

  
267
    if( ret[0]>1 ) ret[0]--;
268
    if( ret[1]>1 ) ret[1]--;
269
    if( ret[2]>1 ) ret[2]--;
270

  
271
    return ret;
272
    }
273

  
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

  
276
  public int getIndex(int[] quats)
277
    {
278
    int[] edge_perm = getEdgePerm(quats);
279
    int[] corn_perm = getCornerPerm(quats);
280
    int[] edge_perm2= collapseEdgePerm(edge_perm); // edge1 is fixed!
281

  
282
    int corn_perm_num = TablebaseHelpers.computePermutationNum(corn_perm);
283
    int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm2);
284

  
285
    return edge_perm_num + 6*corn_perm_num;
286
    }
287
}  
288

  
src/main/java/org/distorted/objectlib/tablebases/TBIvyCube.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
12
import android.content.res.Resources;
13

  
14
import org.distorted.library.type.Static3D;
15
import static org.distorted.objectlib.main.TwistyObject.SQ3;
16

  
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

  
19
public class TBIvyCube extends TablebasesAbstract
20
{
21
  private static final int[] mTmp = new int[6];
22

  
23
  private static final int[][] MAP = { {0,4,2,2,5,3,4,5,3,0,1,1},
24
                                       {1,5,3,3,4,2,5,4,2,1,0,0},
25
                                       {2,0,4,5,0,5,1,1,4,3,3,2},
26
                                       {3,1,5,4,1,4,0,0,5,2,2,3},
27
                                       {4,2,0,1,3,0,3,2,1,5,4,5},
28
                                       {5,3,1,0,2,1,2,3,0,4,5,4} };
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
  public TBIvyCube()
33
    {
34
    super();
35
    }
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
  public TBIvyCube(Resources res)
40
    {
41
    super(res,org.distorted.objectlib.R.raw.ivy_2_tablebase);
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  int[][] getBasicAngles()
47
    {
48
    int[] tmp = {3,3};
49
    return new int[][] { tmp,tmp,tmp,tmp };
50
    }
51

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

  
54
  Static3D[] getRotationAxis()
55
    {
56
    return new Static3D[]
57
         {
58
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
59
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
60
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
61
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
62
         };
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  float[][] getPosition()
68
    {
69
    final float DIST_CORNER = 1;
70
    final float DIST_CENTER = 1;
71

  
72
    return new float[][]
73
      {
74
        { DIST_CORNER, DIST_CORNER, DIST_CORNER },
75
        {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
76
        {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
77
        { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
78
        { DIST_CENTER,           0,           0 },
79
        {-DIST_CENTER,           0,           0 },
80
        {           0, DIST_CENTER,           0 },
81
        {           0,-DIST_CENTER,           0 },
82
        {           0,           0, DIST_CENTER },
83
        {           0,           0,-DIST_CENTER },
84
      };
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  float[][] getCuts()
90
    {
91
    float[] cut = { 0.0f };
92
    return new float[][] { cut,cut,cut,cut };
93
    }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
  boolean[][] getRotatable()
98
    {
99
    boolean[] tmp1 = new boolean[] {false,true};
100
    boolean[] tmp2 = new boolean[] {true,false};
101

  
102
    return new boolean[][] { tmp1,tmp2,tmp2,tmp1 };
103
    }
104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// specifically for the tablebase
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
// orientations of 4 corners + any even permutation of 6 centers
109

  
110
  int getSize()
111
    {
112
    return (3*3*3*3)*(6*5*4*3);
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  int getMinScramble()
118
    {
119
    return 7;
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
  private int findFirst(int[] table, int value)
125
    {
126
    int len = table.length;
127

  
128
    for(int i=0; i<len; i++)
129
      if( table[i]==value ) return i;
130

  
131
    return -1;
132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  public int[] getQuats(int index)
137
    {
138
    int perm_num = index%360;
139
    index /= 360;
140
    int twist0 = index%3;
141
    index /= 3;
142
    int twist1 = index%3;
143
    index /= 3;
144
    int twist2 = index%3;
145
    index /= 3;
146
    int twist3 = index%3;
147

  
148
    int[] ret = new int[10];
149

  
150
    ret[0] = twist0==0 ? 0 : (twist0==1 ? 2:1);
151
    ret[1] = twist1==0 ? 0 : (twist1==1 ? 5:6);
152
    ret[2] = twist2==0 ? 0 : (twist2==1 ? 3:4);
153
    ret[3] = twist3==0 ? 0 : (twist3==1 ? 8:7);
154

  
155
    TablebaseHelpers.getEvenPermutationFromNum(mTmp,perm_num);
156

  
157
    for(int i=0; i<6; i++)
158
      {
159
      int cubitThatMoves = mTmp[i];
160
      ret[cubitThatMoves+4] = findFirst(MAP[cubitThatMoves],i);
161
      }
162

  
163
    return ret;
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  public int getIndex(int[] quats)
169
    {
170
    int twist0 = quats[0]==0 ? 0 : (quats[0]==1 ? 2:1);
171
    int twist1 = quats[1]==0 ? 0 : (quats[1]==6 ? 2:1);
172
    int twist2 = quats[2]==0 ? 0 : (quats[2]==4 ? 2:1);
173
    int twist3 = quats[3]==0 ? 0 : (quats[3]==7 ? 2:1);
174

  
175
    int c4 = MAP[0][quats[4]];
176
    int c5 = MAP[1][quats[5]];
177
    int c6 = MAP[2][quats[6]];
178
    int c7 = MAP[3][quats[7]];
179
    int c8 = MAP[4][quats[8]];
180
    int c9 = MAP[5][quats[9]];
181

  
182
    mTmp[c4]=0;
183
    mTmp[c5]=1;
184
    mTmp[c6]=2;
185
    mTmp[c7]=3;
186
    mTmp[c8]=4;
187
    mTmp[c9]=5;
188

  
189
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(mTmp);
190

  
191
    return perm_num + 360*(twist0+ 3*(twist1+ 3*(twist2+ 3*twist3)));
192
    }
193
}  
194

  
src/main/java/org/distorted/objectlib/tablebases/TBPyraminx.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
15

  
16
import android.content.res.Resources;
17

  
18
import org.distorted.library.type.Static3D;
19
import org.distorted.objectlib.R;
20

  
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

  
23
public class TBPyraminx extends TablebasesAbstract
24
{
25
  public static final int[][] EDGE_QUATS = new int[][]
26
      {
27
          { 0,10},  // even-odd quat (i.e. even-odd twist of the relevant edge piece)
28
          { 1, 7},
29
          { 4, 8},
30
          { 2, 6},
31
          { 3, 5},
32
          {11, 9}
33
      };
34

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

  
37
  public TBPyraminx()
38
    {
39
    super();
40
    }
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
  public TBPyraminx(Resources res)
45
    {
46
    super(res, R.raw.pyra_3_tablebase);
47
    }
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
  int[][] getBasicAngles()
52
    {
53
    int[] tmp = {3,3};
54
    return new int[][] { tmp,tmp,tmp,tmp };
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
  Static3D[] getRotationAxis()
60
    {
61
    return new Static3D[]
62
         {
63
           new Static3D(     0,-SQ3/3,-SQ6/3),
64
           new Static3D(     0,-SQ3/3, SQ6/3),
65
           new Static3D( SQ6/3, SQ3/3,     0),
66
           new Static3D(-SQ6/3, SQ3/3,     0),
67
         };
68
    }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  float[][] getPosition()
73
    {
74
    return new float[][]
75
         {
76
             { 0.0f,-SQ2/4, 0.5f},
77
             { 0.0f,-SQ2/4,-0.5f},
78
             {-0.5f, SQ2/4, 0.0f},
79
             { 0.5f, SQ2/4, 0.0f},
80

  
81
             { 0.0f,-SQ2/2, 0.0f},   // index=0 has the quats already set up so that
82
             { 0.0f,-SQ2/2, 0.0f},   // all the edges fall into right spots, so here
83
             { 0.0f,-SQ2/2, 0.0f},   // they need to be all in one place
84
             { 0.0f,-SQ2/2, 0.0f},
85
             { 0.0f,-SQ2/2, 0.0f},
86
             { 0.0f,-SQ2/2, 0.0f},
87
         };
88
    }
89

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

  
92
  float[][] getCuts()
93
    {
94
    float[] cut = { 0.25f*(SQ6/3) };
95
    return new float[][] { cut,cut,cut,cut };
96
    }
97

  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100
  boolean[][] getRotatable()
101
    {
102
    boolean[] tmp = new boolean[] {false,true};
103
    return new boolean[][] { tmp,tmp,tmp,tmp };
104
    }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
// specifically for the tablebase
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  private void addMove(int[] move, int axis, int twist)
111
    {
112
    move[0] = axis;
113
    move[1] = 4;
114
    move[2] = (twist==2 ? -1:twist);
115
    }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
  private void includeTip(int[] move, int[] extra, int index)
120
    {
121
    move[1] = 6;
122
    extra[index] += (move[2]==1 ? 2:1);
123
    }
124

  
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

  
127
  private boolean failedInsertingTipMove(int[][] moves, int[] extra, int extraIndex, int axis)
128
    {
129
    int numAxis = 0;
130
    boolean ret = true;
131
    extra[extraIndex]+=3; // make sure extra is positive
132

  
133
    for( int[] move : moves )
134
      {
135
      if( move[0]==axis )
136
        {
137
        numAxis++;
138
        if( (numAxis==1 && (move[2]-extra[extraIndex])%3==0 ) || numAxis>=2 ) ret=false;
139
        }
140
      }
141

  
142
    int currAx = 0;
143
    int numMoves = moves.length;
144
    int foreIndex=-1;
145
    int lastIndex = -1;
146

  
147
    for( int index=0; index<numMoves; index++ )
148
      {
149
      int[] move = moves[index];
150

  
151
      if( move[0]==axis )
152
        {
153
             if( currAx <  numAxis-2 ) includeTip(move,extra,extraIndex);
154
        else if( currAx == numAxis-2 ) foreIndex = index;
155
        else if( currAx == numAxis-1 ) lastIndex = index;
156
        currAx++;
157
        }
158
      }
159

  
160
    extra[extraIndex] = (extra[extraIndex]%3);
161

  
162
    if( foreIndex>=0 )
163
      {
164
      int foreAngle = moves[foreIndex][2];
165
      int lastAngle = moves[lastIndex][2];
166

  
167
      if( extra[extraIndex]==1 )
168
        {
169
        if( foreAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
170
        else
171
          {
172
          includeTip(moves[lastIndex],extra,extraIndex);
173
          if( lastAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
174
          }
175
        }
176
      else if( extra[extraIndex]==2 )
177
        {
178
        if( foreAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
179
        else
180
          {
181
          includeTip(moves[lastIndex],extra,extraIndex);
182
          if( lastAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
183
          }
184
        }
185
      }
186
    else if( lastIndex>=0 )
187
      {
188
      int lastAngle = moves[lastIndex][2];
189

  
190
      if( (extra[extraIndex]-lastAngle)%3 ==0 )
191
        includeTip(moves[lastIndex],extra,extraIndex);
192
      }
193

  
194
    extra[extraIndex] = (extra[extraIndex]%3);
195

  
196
    return ret;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200
// extra = cornerTips
201

  
202
  @Override
203
  int[][] extraInfo(int[][] moves, int[] extra)
204
    {
205
    int lenExtra = 0;
206

  
207
    if( failedInsertingTipMove(moves,extra,0,1) && extra[0]!=0 ) lenExtra++;
208
    if( failedInsertingTipMove(moves,extra,1,0) && extra[1]!=0 ) lenExtra++;
209
    if( failedInsertingTipMove(moves,extra,2,3) && extra[2]!=0 ) lenExtra++;
210
    if( failedInsertingTipMove(moves,extra,3,2) && extra[3]!=0 ) lenExtra++;
211

  
212
    if( lenExtra>0 )
213
      {
214
      int[][] extraMoves = new int[lenExtra][3];
215

  
216
      int index=0;
217
      if( extra[0]!=0 ) { addMove(extraMoves[index],1,extra[0]); index++; }
218
      if( extra[1]!=0 ) { addMove(extraMoves[index],0,extra[1]); index++; }
219
      if( extra[2]!=0 ) { addMove(extraMoves[index],3,extra[2]); index++; }
220
      if( extra[3]!=0 ) { addMove(extraMoves[index],2,extra[3]);          }
221

  
222
      int len = moves.length;
223
      int totalLen = len+lenExtra;
224
      int[][] totalMoves = new int[totalLen][];
225

  
226
      if( len>0 ) System.arraycopy(moves, 0, totalMoves, 0, len);
227
      System.arraycopy(extraMoves, 0, totalMoves, len, lenExtra);
228

  
229
      return totalMoves;
230
      }
231

  
232
    return moves;
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
  int getSize()
238
    {
239
    return 933120;  // see https://www.jaapsch.net/puzzles/pyraminx.htm
240
    }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

  
244
  int getMinScramble()
245
    {
246
    return 9;
247
    }
248

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

  
251
  public static void getEdgePermutation(int[] output, int[] quats, int index)
252
    {
253
    for(int i=0; i<6; i++ )
254
      {
255
      int quat = quats[i+index];
256

  
257
      for(int j=0; j<6; j++)
258
        {
259
        int[] edge = EDGE_QUATS[j];
260
        if( quat==edge[0] || quat==edge[1] ) { output[i]=j; break; }
261
        }
262
      }
263
    }
264

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
  public static void getEdgeTwist(int[] output, int[] quats, int index)
268
    {
269
    for(int i=0; i<6; i++)
270
      {
271
      int quat = quats[i+index];
272

  
273
      for(int j=0; j<6; j++)
274
        {
275
        int[] edge = EDGE_QUATS[j];
276
        if( quat==edge[0] ) { output[i]=0; break; }
277
        if( quat==edge[1] ) { output[i]=1; break; }
278
        }
279
      }
280
    }
281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
  private void getEdgeQuats(int twist, int[] perm, int[] output)
285
    {
286
    int totalTwist = 0;
287

  
288
    for(int i=0; i<5; i++)
289
      {
290
      int p = perm[i];
291
      int t = (twist%2);
292
      twist/=2;
293
      output[i+4] = EDGE_QUATS[p][t];
294

  
295
      totalTwist += t;
296
      }
297

  
298
    int p = perm[5];
299
    int t = (totalTwist%2)==0 ? 0:1;
300
    output[9] = EDGE_QUATS[p][t];
301
    }
302

  
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

  
305
  private int getVertexTwist(int[] quats)
306
    {
307
    int twist = 0;
308

  
309
    if( quats[3]==5 ) twist += 1;
310
    if( quats[3]==6 ) twist += 2;
311
    twist *= 3;
312
    if( quats[2]==7 ) twist += 1;
313
    if( quats[2]==8 ) twist += 2;
314
    twist *= 3;
315
    if( quats[1]==1 ) twist += 1;
316
    if( quats[1]==2 ) twist += 2;
317
    twist *= 3;
318
    if( quats[0]==3 ) twist += 1;
319
    if( quats[0]==4 ) twist += 2;
320

  
321
    return twist;
322
    }
323

  
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

  
326
  private void getVertexQuats(int twist, int[] output)
327
    {
328
    switch(twist%3)
329
      {
330
      case 0: output[0]=0; break;
331
      case 1: output[0]=3; break;
332
      case 2: output[0]=4; break;
333
      }
334
    twist /= 3;
335

  
336
    switch(twist%3)
337
      {
338
      case 0: output[1]=0; break;
339
      case 1: output[1]=1; break;
340
      case 2: output[1]=2; break;
341
      }
342
    twist /= 3;
343

  
344
    switch(twist%3)
345
      {
346
      case 0: output[2]=0; break;
347
      case 1: output[2]=7; break;
348
      case 2: output[2]=8; break;
349
      }
350
    twist /= 3;
351

  
352
    switch(twist%3)
353
      {
354
      case 0: output[3]=0; break;
355
      case 1: output[3]=5; break;
356
      case 2: output[3]=6; break;
357
      }
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  public int[] getQuats(int index)
363
    {
364
    int vertexTwist = (index%81);
365
    index /= 81;
366
    int edgeTwist = (index%32);
367
    int perm_num = index/32;
368

  
369
    int[] quats = new int[10];
370

  
371
    getVertexQuats(vertexTwist,quats);
372
    int[] permutation = new int[6];
373
    TablebaseHelpers.getEvenPermutationFromNum(permutation,perm_num);
374
    getEdgeQuats(edgeTwist,permutation,quats);
375

  
376
    return quats;
377
    }
378

  
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

  
381
  public int getIndex(int[] quats)
382
    {
383
    int vertexTwist = getVertexTwist(quats);
384
    int[] permutation = new int[6];
385
    getEdgePermutation(permutation,quats,4);
386
    int[] twist = new int[6];
387
    getEdgeTwist(twist,quats,4);
388

  
389
    int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
390
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
391

  
392
    return vertexTwist + 81*(edgeTwist + 32*perm_num);
393
    }
394
}  
395

  
src/main/java/org/distorted/objectlib/tablebases/TBPyraminxDuo.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
15

  
16
import android.content.res.Resources;
17

  
18
import org.distorted.library.type.Static3D;
19

  
20
///////////////////////////////////////////////////////////////////////////////////////////////////
21

  
22
public class TBPyraminxDuo extends TablebasesAbstract
23
{
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

  
26
  public TBPyraminxDuo()
27
    {
28
    super();
29
    }
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
  public TBPyraminxDuo(Resources res)
34
    {
35
    super(res,org.distorted.objectlib.R.raw.pduo_2_tablebase);
36
    }
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  int[][] getBasicAngles()
41
    {
42
    int[] tmp = {3,3};
43
    return new int[][] { tmp,tmp,tmp,tmp };
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  Static3D[] getRotationAxis()
49
    {
50
    return new Static3D[]
51
         {
52
           new Static3D(     0,-SQ3/3,-SQ6/3),
53
           new Static3D(     0,-SQ3/3, SQ6/3),
54
           new Static3D( SQ6/3, SQ3/3,     0),
55
           new Static3D(-SQ6/3, SQ3/3,     0),
56
         };
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
  float[][] getPosition()
62
    {
63
    return new float[][]
64
         {
65
           { 0.000f, -SQ2/2, 1.000f },
66
           { 0.000f, -SQ2/2,-1.000f },
67
           {-1.000f,  SQ2/2, 0.000f },
68
           { 1.000f,  SQ2/2, 0.000f },
69

  
70
           { 0.000f,  SQ2/6, 1.0f/3 },
71
           { 0.000f,  SQ2/6,-1.0f/3 },
72
           {-1.0f/3, -SQ2/6, 0.000f },
73
           { 1.0f/3, -SQ2/6, 0.000f },
74
         };
75
    }
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
  float[][] getCuts()
80
    {
81
    float[] cut = { 0.0f };
82
    return new float[][] { cut,cut,cut,cut };
83
    }
84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

  
87
  boolean[][] getRotatable()
88
    {
89
    boolean[] tmp = new boolean[] {false,true};
90
    return new boolean[][] { tmp,tmp,tmp,tmp };
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
// specifically for the tablebase
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
  int getSize()
98
    {
99
    return 324;  // see https://www.jaapsch.net/puzzles/pyraduo.htm
100
    }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

  
104
  int getMinScramble()
105
    {
106
    return 4;
107
    }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
  int[] getQuats(int index)
112
    {
113
    int c = index%4; index/=4;
114
    int b3= index%3; index/=3;
115
    int b2= index%3; index/=3;
116
    int b1= index%3; index/=3;
117
    int b0= index%3;
118

  
119
    // we don't need to care about the values of the last 3 quats, but do include them.
120
    int[] quats = new int[8];
121

  
122
    switch(c)
123
      {
124
      case 0: quats[4] = 2; break;
125
      case 1: quats[4] = 5; break;
126
      case 2: quats[4] = 4; break;
127
      case 3: quats[4] = 3; break;
128
      }
129

  
130
    switch(b3)
131
      {
132
      case 0: quats[3] = 0; break;
133
      case 1: quats[3] = 5; break;
134
      case 2: quats[3] = 6; break;
135
      }
136

  
137
    switch(b2)
138
      {
139
      case 0: quats[2] = 0; break;
140
      case 1: quats[2] = 7; break;
141
      case 2: quats[2] = 8; break;
142
      }
143

  
144
    switch(b1)
145
      {
146
      case 0: quats[1] = 0; break;
147
      case 1: quats[1] = 1; break;
148
      case 2: quats[1] = 2; break;
149
      }
150

  
151
    switch(b0)
152
      {
153
      case 0: quats[0] = 0; break;
154
      case 1: quats[0] = 3; break;
155
      case 2: quats[0] = 4; break;
156
      }
157

  
158
    return quats;
159
    }
160

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  private int computeCornerTwistFromQuat(int quat)
164
    {
165
    switch(quat)
166
      {
167
      case 0: case 9: case 10: case 11: return 0;
168
      case 1: case 3: case  5: case  7: return 1;
169
      case 2: case 4: case  6: case  8: return 2;
170
      }
171

  
172
    return -1;
173
    }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
  int getIndex(int[] quats)
178
    {
179
    int b0 = computeCornerTwistFromQuat(quats[0]);
180
    int b1 = computeCornerTwistFromQuat(quats[1]);
181
    int b2 = computeCornerTwistFromQuat(quats[2]);
182
    int b3 = computeCornerTwistFromQuat(quats[3]);
183

  
184
    int c = -1;
185
    switch(quats[4])
186
      {
187
      case  0: case  1: case  2: c=0; break;
188
      case  5: case  8: case 10: c=1; break;
189
      case  4: case  7: case 11: c=2; break;
190
      case  3: case  6: case  9: c=3; break;
191
      }
192

  
193
    return c + 4*(b3 + 3*(b2 + 3*(b1 + 3*b0)));
194
    }
195
}  
196

  
src/main/java/org/distorted/objectlib/tablebases/TBSkewbDiamond.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.tablebases;
11

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff