Project

General

Profile

Download (8.3 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TBCube2.java @ cd595931

1 32b2e288 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 00947987 Leszek Koltunski
import org.distorted.objectlib.R;
16 32b2e288 Leszek Koltunski
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18
19 a8d83300 Leszek Koltunski
public class TBCube2 extends TablebasesPruning
20 32b2e288 Leszek Koltunski
{
21 bdcb662f Leszek Koltunski
  private final int[][][] mQuatsMap =
22
    {
23
     { { 0,21,13},  { 1, 6,18},  { 3,17, 7},  { 2,12,22},  {14, 4, 9},  { 5,10,15},  { 8,20,23},  {11,16,19} },
24
     { { 3,18, 4},  { 0,22,10},  { 2,13,20},  { 1, 7,16},  { 5,23,21},  {11, 9, 6},  {14,19,17},  { 8,15,12} },
25
     { { 1, 9,17},  { 2,15,21},  { 0,23,12},  { 3,19, 6},  { 8,13,10},  {14,18,16},  {11, 7, 4},  { 5,22,20} },
26
     { { 2,10,23},  { 3,16, 9},  { 1, 4,19},  { 0,20,15},  {11,17,18},  { 8,21,22},  { 5,12,13},  {14, 6, 7} },
27
     { {14, 7, 6},  { 5,13,12},  { 8,22,21},  {11,18,17},  { 0,15,20},  { 1,19, 4},  { 3, 9,16},  { 2,23,10} },
28
     { { 5,20,22},  {11, 4, 7},  {14,16,18},  { 8,10,13},  { 3, 6,19},  { 0,12,23},  { 2,21,15},  { 1,17, 9} },
29
     { { 8,12,15},  {14,17,19},  {11, 6, 9},  { 5,21,23},  { 1,16, 7},  { 2,20,13},  { 0,10,22},  { 3, 4,18} },
30
     { {11,19,16},  { 8,23,20},  { 5,15,10},  {14, 9, 4},  { 2,22,12},  { 3, 7,17},  { 1,18, 6},  { 0,13,21} },
31
    };
32 618f3d75 Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 a8d83300 Leszek Koltunski
  public TBCube2()
36 32b2e288 Leszek Koltunski
    {
37
    super();
38
    }
39
40 fb8eaaec Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
41 32b2e288 Leszek Koltunski
42 a8d83300 Leszek Koltunski
  public TBCube2(Resources res)
43 32b2e288 Leszek Koltunski
    {
44 cd595931 Leszek Koltunski
    //super(res, R.raw.cube_2_tablebase );
45 a8d83300 Leszek Koltunski
    super(res, new int[] {R.raw.cube_2_pruning4,R.raw.cube_2_pruning5}, new int[] {R.raw.cube_2_pruning11} );
46 32b2e288 Leszek Koltunski
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  int[][] getBasicAngles()
51
    {
52
    int[] tmp = {4,4};
53
    return new int[][] { tmp,tmp,tmp };
54
    }
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58
  Static3D[] getRotationAxis()
59
    {
60
    return new Static3D[]
61
         {
62
           new Static3D(1,0,0),
63
           new Static3D(0,1,0),
64
           new Static3D(0,0,1)
65
         };
66
    }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70
  float[][] getPosition()
71
    {
72
    return new float[][]
73
      {
74
        { -0.5f, -0.5f, -0.5f },
75
        { -0.5f, -0.5f,  0.5f },
76
        { -0.5f,  0.5f, -0.5f },
77
        { -0.5f,  0.5f,  0.5f },
78
        {  0.5f, -0.5f, -0.5f },
79
        {  0.5f, -0.5f,  0.5f },
80
        {  0.5f,  0.5f, -0.5f },
81
        {  0.5f,  0.5f,  0.5f },
82
      };
83
    }
84
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
87
  float[][] getCuts()
88
    {
89
    return new float[][] { {0.0f}, {0.0f}, {0.0f} };
90
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94
  boolean[][] getRotatable()
95
    {
96
    return new boolean[][] { {false,true},{false,true},{true,false} };
97
    }
98
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// specifically for the tablebase
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
// 7!*3^6 --> https://www.jaapsch.net/puzzles/cube2.htm
103
104
  int getSize()
105
    {
106
    return 3674160;
107
    }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111 618f3d75 Leszek Koltunski
  int getMinScramble()
112 32b2e288 Leszek Koltunski
    {
113
    return 9;
114
    }
115
116 884b702b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118 f079bf77 Leszek Koltunski
  int[] getMidPruningLevels()
119 884b702b Leszek Koltunski
    {
120 f079bf77 Leszek Koltunski
    return new int[] {4,5};
121
    }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
  int[] getHighPruningLevels()
126
    {
127 61b37d19 Leszek Koltunski
    return new int[] {11};
128 f079bf77 Leszek Koltunski
    }
129
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132
  int getGodsNumber()
133
    {
134
    return 11;
135 884b702b Leszek Koltunski
    }
136
137 618f3d75 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139 bdcb662f Leszek Koltunski
  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
140 618f3d75 Leszek Koltunski
    {
141 bdcb662f Leszek Koltunski
    return lastA!=currA;
142 618f3d75 Leszek Koltunski
    }
143
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
146
  public static int[] shrinkPerm(int[] perm8)
147
    {
148
    int[] perm7 = new int[7];
149
150
    int tmp = perm8[0];
151
    perm7[0] = tmp>1 ? tmp-1 : tmp;
152
    tmp = perm8[2];
153
    perm7[1] = tmp>1 ? tmp-1 : tmp;
154
    tmp = perm8[3];
155
    perm7[2] = tmp>1 ? tmp-1 : tmp;
156
    tmp = perm8[4];
157
    perm7[3] = tmp>1 ? tmp-1 : tmp;
158
    tmp = perm8[5];
159
    perm7[4] = tmp>1 ? tmp-1 : tmp;
160
    tmp = perm8[6];
161
    perm7[5] = tmp>1 ? tmp-1 : tmp;
162
    tmp = perm8[7];
163
    perm7[6] = tmp>1 ? tmp-1 : tmp;
164
165
    return perm7;
166
    }
167
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
170
  private static int[] growPerm(int[] perm7)
171
    {
172
    int[] perm8 = new int[8];
173
    int tmp = perm7[0];
174
    perm8[0] = tmp>=1 ? tmp+1 : tmp;
175
    perm8[1] = 1;
176
    tmp = perm7[1];
177
    perm8[2] = tmp>=1 ? tmp+1 : tmp;
178
    tmp = perm7[2];
179
    perm8[3] = tmp>=1 ? tmp+1 : tmp;
180
    tmp = perm7[3];
181
    perm8[4] = tmp>=1 ? tmp+1 : tmp;
182
    tmp = perm7[4];
183
    perm8[5] = tmp>=1 ? tmp+1 : tmp;
184
    tmp = perm7[5];
185
    perm8[6] = tmp>=1 ? tmp+1 : tmp;
186
    tmp = perm7[6];
187
    perm8[7] = tmp>=1 ? tmp+1 : tmp;
188
189
    return perm8;
190
    }
191
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
194
  private int[] getPerm(int permNum)
195
    {
196
    int[] perm7 = new int[7];
197
    TablebaseHelpers.getPermutationFromNum(perm7,7,permNum);
198
    return growPerm(perm7);
199
    }
200
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
203
  private int[] getTwist(int twistNum)
204
    {
205
    int[] twist = new int[8];
206
    twist[0] = twistNum%3;
207
    twist[1] = 0;
208
    twistNum /=3;
209
    twist[2] = twistNum%3;
210
    twistNum /=3;
211
    twist[3] = twistNum%3;
212
    twistNum /=3;
213
    twist[4] = twistNum%3;
214
    twistNum /=3;
215
    twist[5] = twistNum%3;
216
    twistNum /=3;
217
    twist[6] = twistNum%3;
218
219
    int total = (twist[0]+twist[2]+twist[3]+twist[4]+twist[5]+twist[6])%3;
220
    if( total==0 ) twist[7] = 0;
221
    else twist[7] = 3-total;
222
223
    return twist;
224
    }
225
226 32b2e288 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
227
228
  public int[] getQuats(int index)
229
    {
230 618f3d75 Leszek Koltunski
    int twistNum = index%729;
231
    int permuNum = index/729;
232
233
    int[] twist = getTwist(twistNum);
234
    int[] perm  = getPerm(permuNum);
235
236 32b2e288 Leszek Koltunski
    int[] quats = new int[8];
237 618f3d75 Leszek Koltunski
    for(int i=0; i<8; i++) quats[i] = mQuatsMap[i][perm[i]][twist[i]];
238 32b2e288 Leszek Koltunski
239
    return quats;
240
    }
241
242 618f3d75 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  private void extractTwistAndPerm(int quat, int[][] map, int[] twist, int[] perm, int index)
245
    {
246
    for(int i=0; i<8; i++)
247
      for(int j=0; j<3; j++)
248
        if( map[i][j]==quat )
249
          {
250
          twist[index] = j;
251
          perm[index] = i;
252
          break;
253
          }
254
    }
255 32b2e288 Leszek Koltunski
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258
  public int getIndex(int[] quats)
259
    {
260 618f3d75 Leszek Koltunski
    int[] twist = new int[8];
261
    int[] perm8 = new int[8];
262
263
    for(int i=0; i<8; i++) extractTwistAndPerm(quats[i],mQuatsMap[i],twist,perm8,i);
264
265
    int[] perm7 = shrinkPerm(perm8);
266
    int twistNum = twist[0] + 3*(twist[2] + 3*(twist[3] + 3*(twist[4] + 3*(twist[5] + 3*twist[6]))));
267
    int permNum  = TablebaseHelpers.computePermutationNum(perm7);
268
269
    return twistNum + 729*permNum;
270 32b2e288 Leszek Koltunski
    }
271
}