Project

General

Profile

« Previous | Next » 

Revision bdcb662f

Added by Leszek Koltunski about 1 year ago

Progress with TablebasesPruning

View differences:

src/main/java/org/distorted/objectlib/tablebases/TBCube2.java
11 11

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

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

  
19 17
///////////////////////////////////////////////////////////////////////////////////////////////////
20 18

  
21 19
public class TBCube2 extends TablebasesPruning
22 20
{
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;
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
    };
64 32

  
65 33
///////////////////////////////////////////////////////////////////////////////////////////////////
66 34

  
......
167 135

  
168 136
///////////////////////////////////////////////////////////////////////////////////////////////////
169 137

  
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)
138
  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
189 139
    {
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);
140
    return lastA!=currA;
218 141
    }
219 142

  
220 143
///////////////////////////////////////////////////////////////////////////////////////////////////
......
303 226

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

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

  
......
335 256

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

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

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

  
268
if( permNum<0 )
269
  {
270
  android.util.Log.e("D", " permNum="+permNum );
271

  
272
  StringBuilder sb2 = new StringBuilder();
273
  for(int i=0; i<8; i++) { sb2.append(' '); sb2.append(perm8[i]); }
274
  android.util.Log.e("D", " perm8="+sb2 );
275

  
276
  StringBuilder sb3 = new StringBuilder();
277
  for(int i=0; i<8; i++) { sb3.append(' '); sb3.append(quats[i]); }
278
  android.util.Log.e("D", " quats="+sb3 );
279
  }
280

  
349 281
    return twistNum + 729*permNum;
350 282
    }
351 283
}  

Also available in: Unified diff