Project

General

Profile

« Previous | Next » 

Revision 618f3d75

Added by Leszek Koltunski about 1 year ago

Cube2 tablebases solver finished.

View differences:

src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
367 367
    return moves;
368 368
    }
369 369

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

  
372
  Static4D[] getQuats()
373
    {
374
    return mQuats;
375
    }
376

  
370 377
///////////////////////////////////////////////////////////////////////////////////////////////////
371 378

  
372 379
  public int[][] solution(int index, int[] extra)
src/main/java/org/distorted/objectlib/tablebases/TablebasesCube2.java
11 11

  
12 12
import android.content.res.Resources;
13 13

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

  
16 18
///////////////////////////////////////////////////////////////////////////////////////////////////
17 19

  
18 20
public class TablebasesCube2 extends TablebasesAbstract
19 21
{
22
  private static final int[][] P =
23
      {
24
            { 2,-1,-1},
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

  
33
            {-1, 2,-1},
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

  
42
            {-1,-1, 2},
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
      };
51

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

  
62
  private int[][][] mQuatsMap;
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
20 66
  public TablebasesCube2()
21 67
    {
22 68
    super();
......
26 72

  
27 73
  public TablebasesCube2(Resources res)
28 74
    {
29
    super(res,org.distorted.objectlib.R.raw.cu_232_tablebase);
75
    super(res,org.distorted.objectlib.R.raw.cube_2_tablebase);
30 76
    }
31 77

  
32 78
///////////////////////////////////////////////////////////////////////////////////////////////////
......
92 138

  
93 139
///////////////////////////////////////////////////////////////////////////////////////////////////
94 140

  
95
 int getMinScramble()
141
  int getMinScramble()
96 142
    {
97 143
    return 9;
98 144
    }
99 145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
  private int[] getPermTwist(float[] point)
149
    {
150
    float ERR = 0.01f;
151

  
152
    for(int i=0; i<24; i++)
153
      {
154
      float dx = point[0]-P[i][0];
155
      float dy = point[1]-P[i][1];
156
      float dz = point[2]-P[i][2];
157

  
158
      if( dx*dx + dy*dy + dz*dz < ERR ) return PT[i];
159
      }
160

  
161
    return null;
162
    }
163

  
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
  private void fillOutMap(float[] buffer, int[][] map, float[] point, Static4D quat, int quatIndex)
167
    {
168
    QuatHelper.rotateVectorByQuat(buffer,point[0],point[1],point[2],1,quat);
169
    int[] pt = getPermTwist(buffer);
170
    map[pt[0]][pt[1]] = quatIndex;
171
    }
172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

  
175
  private void computeMap()
176
    {
177
    final float[][] POINTS =
178
        {
179
            {-2,-1,-1},
180
            {-2,-1, 1},
181
            {-2, 1,-1},
182
            {-2, 1, 1},
183
            { 2,-1,-1},
184
            { 2,-1, 1},
185
            { 2, 1,-1},
186
            { 2, 1, 1},
187
        };
188

  
189
    mQuatsMap = new int[8][8][3];
190
    Static4D[] quats = getQuats();
191
    float[] buffer = new float[4];
192

  
193
    for(int c=0; c<8; c++)
194
      for(int q=0; q<24; q++)
195
        fillOutMap(buffer,mQuatsMap[c],POINTS[c],quats[q],q);
196
    }
197

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

  
200
  public static int[] shrinkPerm(int[] perm8)
201
    {
202
    int[] perm7 = new int[7];
203

  
204
    int tmp = perm8[0];
205
    perm7[0] = tmp>1 ? tmp-1 : tmp;
206
    tmp = perm8[2];
207
    perm7[1] = tmp>1 ? tmp-1 : tmp;
208
    tmp = perm8[3];
209
    perm7[2] = tmp>1 ? tmp-1 : tmp;
210
    tmp = perm8[4];
211
    perm7[3] = tmp>1 ? tmp-1 : tmp;
212
    tmp = perm8[5];
213
    perm7[4] = tmp>1 ? tmp-1 : tmp;
214
    tmp = perm8[6];
215
    perm7[5] = tmp>1 ? tmp-1 : tmp;
216
    tmp = perm8[7];
217
    perm7[6] = tmp>1 ? tmp-1 : tmp;
218

  
219
    return perm7;
220
    }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

  
224
  private static int[] growPerm(int[] perm7)
225
    {
226
    int[] perm8 = new int[8];
227
    int tmp = perm7[0];
228
    perm8[0] = tmp>=1 ? tmp+1 : tmp;
229
    perm8[1] = 1;
230
    tmp = perm7[1];
231
    perm8[2] = tmp>=1 ? tmp+1 : tmp;
232
    tmp = perm7[2];
233
    perm8[3] = tmp>=1 ? tmp+1 : tmp;
234
    tmp = perm7[3];
235
    perm8[4] = tmp>=1 ? tmp+1 : tmp;
236
    tmp = perm7[4];
237
    perm8[5] = tmp>=1 ? tmp+1 : tmp;
238
    tmp = perm7[5];
239
    perm8[6] = tmp>=1 ? tmp+1 : tmp;
240
    tmp = perm7[6];
241
    perm8[7] = tmp>=1 ? tmp+1 : tmp;
242

  
243
    return perm8;
244
    }
245

  
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

  
248
  private int[] getPerm(int permNum)
249
    {
250
    int[] perm7 = new int[7];
251
    TablebaseHelpers.getPermutationFromNum(perm7,7,permNum);
252
    return growPerm(perm7);
253
    }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

  
257
  private int[] getTwist(int twistNum)
258
    {
259
    int[] twist = new int[8];
260
    twist[0] = twistNum%3;
261
    twist[1] = 0;
262
    twistNum /=3;
263
    twist[2] = twistNum%3;
264
    twistNum /=3;
265
    twist[3] = twistNum%3;
266
    twistNum /=3;
267
    twist[4] = twistNum%3;
268
    twistNum /=3;
269
    twist[5] = twistNum%3;
270
    twistNum /=3;
271
    twist[6] = twistNum%3;
272

  
273
    int total = (twist[0]+twist[2]+twist[3]+twist[4]+twist[5]+twist[6])%3;
274
    if( total==0 ) twist[7] = 0;
275
    else twist[7] = 3-total;
276

  
277
    return twist;
278
    }
279

  
100 280
///////////////////////////////////////////////////////////////////////////////////////////////////
101 281

  
102 282
  public int[] getQuats(int index)
103 283
    {
284
    if( mQuatsMap==null ) computeMap();
285

  
286
    int twistNum = index%729;
287
    int permuNum = index/729;
288

  
289
    int[] twist = getTwist(twistNum);
290
    int[] perm  = getPerm(permuNum);
291

  
104 292
    int[] quats = new int[8];
293
    for(int i=0; i<8; i++) quats[i] = mQuatsMap[i][perm[i]][twist[i]];
105 294

  
106 295
    return quats;
107 296
    }
108 297

  
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

  
300
  private void extractTwistAndPerm(int quat, int[][] map, int[] twist, int[] perm, int index)
301
    {
302
    for(int i=0; i<8; i++)
303
      for(int j=0; j<3; j++)
304
        if( map[i][j]==quat )
305
          {
306
          twist[index] = j;
307
          perm[index] = i;
308
          break;
309
          }
310
    }
109 311

  
110 312
///////////////////////////////////////////////////////////////////////////////////////////////////
111 313

  
112 314
  public int getIndex(int[] quats)
113 315
    {
114
    return 0;
316
    if( mQuatsMap==null ) computeMap();
317

  
318
    int[] twist = new int[8];
319
    int[] perm8 = new int[8];
320

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

  
323
    int[] perm7 = shrinkPerm(perm8);
324
    int twistNum = twist[0] + 3*(twist[2] + 3*(twist[3] + 3*(twist[4] + 3*(twist[5] + 3*twist[6]))));
325
    int permNum  = TablebaseHelpers.computePermutationNum(perm7);
326

  
327
    return twistNum + 729*permNum;
115 328
    }
116 329
}  
117 330

  

Also available in: Unified diff