Project

General

Profile

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

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

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 org.distorted.objectlib.R;
16

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

    
19
public class TBCube2 extends TablebasesPruning
20
{
21
  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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
  public TBCube2()
36
    {
37
    super();
38
    }
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
/*
42
  public TBCube2(Resources res)
43
    {
44
    super(res, R.raw.cube_2_tablebase );
45
    }
46
*/
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public TBCube2(Resources res)
50
    {
51
    super(res, new int[] {R.raw.cube_2_pruning4,R.raw.cube_2_pruning5}, new int[] {R.raw.cube_2_pruning11} );
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  int[][] getBasicAngles()
57
    {
58
    int[] tmp = {4,4};
59
    return new int[][] { tmp,tmp,tmp };
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  Static3D[] getRotationAxis()
65
    {
66
    return new Static3D[]
67
         {
68
           new Static3D(1,0,0),
69
           new Static3D(0,1,0),
70
           new Static3D(0,0,1)
71
         };
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  float[][] getPosition()
77
    {
78
    return new float[][]
79
      {
80
        { -0.5f, -0.5f, -0.5f },
81
        { -0.5f, -0.5f,  0.5f },
82
        { -0.5f,  0.5f, -0.5f },
83
        { -0.5f,  0.5f,  0.5f },
84
        {  0.5f, -0.5f, -0.5f },
85
        {  0.5f, -0.5f,  0.5f },
86
        {  0.5f,  0.5f, -0.5f },
87
        {  0.5f,  0.5f,  0.5f },
88
      };
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  float[][] getCuts()
94
    {
95
    return new float[][] { {0.0f}, {0.0f}, {0.0f} };
96
    }
97

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

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

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// specifically for the tablebase
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
// 7!*3^6 --> https://www.jaapsch.net/puzzles/cube2.htm
109

    
110
  int getSize()
111
    {
112
    return 3674160;
113
    }
114

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

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

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

    
124
  int[] getMidPruningLevels()
125
    {
126
    return new int[] {4,5};
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  int[] getHighPruningLevels()
132
    {
133
    return new int[] {11};
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  int getGodsNumber()
139
    {
140
    return 11;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
146
    {
147
    return lastA!=currA;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public static int[] shrinkPerm(int[] perm8)
153
    {
154
    int[] perm7 = new int[7];
155

    
156
    int tmp = perm8[0];
157
    perm7[0] = tmp>1 ? tmp-1 : tmp;
158
    tmp = perm8[2];
159
    perm7[1] = tmp>1 ? tmp-1 : tmp;
160
    tmp = perm8[3];
161
    perm7[2] = tmp>1 ? tmp-1 : tmp;
162
    tmp = perm8[4];
163
    perm7[3] = tmp>1 ? tmp-1 : tmp;
164
    tmp = perm8[5];
165
    perm7[4] = tmp>1 ? tmp-1 : tmp;
166
    tmp = perm8[6];
167
    perm7[5] = tmp>1 ? tmp-1 : tmp;
168
    tmp = perm8[7];
169
    perm7[6] = tmp>1 ? tmp-1 : tmp;
170

    
171
    return perm7;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  private static int[] growPerm(int[] perm7)
177
    {
178
    int[] perm8 = new int[8];
179
    int tmp = perm7[0];
180
    perm8[0] = tmp>=1 ? tmp+1 : tmp;
181
    perm8[1] = 1;
182
    tmp = perm7[1];
183
    perm8[2] = tmp>=1 ? tmp+1 : tmp;
184
    tmp = perm7[2];
185
    perm8[3] = tmp>=1 ? tmp+1 : tmp;
186
    tmp = perm7[3];
187
    perm8[4] = tmp>=1 ? tmp+1 : tmp;
188
    tmp = perm7[4];
189
    perm8[5] = tmp>=1 ? tmp+1 : tmp;
190
    tmp = perm7[5];
191
    perm8[6] = tmp>=1 ? tmp+1 : tmp;
192
    tmp = perm7[6];
193
    perm8[7] = tmp>=1 ? tmp+1 : tmp;
194

    
195
    return perm8;
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

    
200
  private int[] getPerm(int permNum)
201
    {
202
    int[] perm7 = new int[7];
203
    TablebaseHelpers.getPermutationFromNum(perm7,7,permNum);
204
    return growPerm(perm7);
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  private int[] getTwist(int twistNum)
210
    {
211
    int[] twist = new int[8];
212
    twist[0] = twistNum%3;
213
    twist[1] = 0;
214
    twistNum /=3;
215
    twist[2] = twistNum%3;
216
    twistNum /=3;
217
    twist[3] = twistNum%3;
218
    twistNum /=3;
219
    twist[4] = twistNum%3;
220
    twistNum /=3;
221
    twist[5] = twistNum%3;
222
    twistNum /=3;
223
    twist[6] = twistNum%3;
224

    
225
    int total = (twist[0]+twist[2]+twist[3]+twist[4]+twist[5]+twist[6])%3;
226
    if( total==0 ) twist[7] = 0;
227
    else twist[7] = 3-total;
228

    
229
    return twist;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  public int[] getQuats(int index)
235
    {
236
    int twistNum = index%729;
237
    int permuNum = index/729;
238

    
239
    int[] twist = getTwist(twistNum);
240
    int[] perm  = getPerm(permuNum);
241

    
242
    int[] quats = new int[8];
243
    for(int i=0; i<8; i++) quats[i] = mQuatsMap[i][perm[i]][twist[i]];
244

    
245
    return quats;
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  private void extractTwistAndPerm(int quat, int[][] map, int[] twist, int[] perm, int index)
251
    {
252
    for(int i=0; i<8; i++)
253
      for(int j=0; j<3; j++)
254
        if( map[i][j]==quat )
255
          {
256
          twist[index] = j;
257
          perm[index] = i;
258
          break;
259
          }
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  public int getIndex(int[] quats)
265
    {
266
    int[] twist = new int[8];
267
    int[] perm8 = new int[8];
268

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

    
271
    int[] perm7 = shrinkPerm(perm8);
272
    int twistNum = twist[0] + 3*(twist[2] + 3*(twist[3] + 3*(twist[4] + 3*(twist[5] + 3*twist[6]))));
273
    int permNum  = TablebaseHelpers.computePermutationNum(perm7);
274

    
275
    return twistNum + 729*permNum;
276
    }
277
}  
278

    
(3-3/12)