Project

General

Profile

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

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

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