Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TablebasesSkewbDiamond.java @ 884b702b

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 static org.distorted.objectlib.main.TwistyObject.SQ2;
13
import static org.distorted.objectlib.main.TwistyObject.SQ3;
14
import static org.distorted.objectlib.main.TwistyObject.SQ6;
15

    
16
import android.content.res.Resources;
17

    
18
import org.distorted.library.type.Static3D;
19
import org.distorted.objectlib.R;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class TablebasesSkewbDiamond extends TablebasesAbstract
24
{
25
  private static final int[][][] FREE_CENTER =
26
      {
27
          { {0,5, 6}, {1,4,10}, {2,7, 9}, {3,8,11} },
28
          { {2,3,10}, {0,7, 8}, {1,6,11}, {4,5, 9} },
29
          { {1,8, 9}, {2,5,11}, {0,3, 4}, {6,7,10} },
30
          { {4,7,11}, {3,6, 9}, {5,8,10}, {0,1, 2} }
31
      };
32

    
33
  public static final int[][][] CORNER_QUATS =
34
      {
35
          { {0,9},{2,4},{10,11},{8,6},{1,5},{3,7} },   // order of each pair determines the twist.
36
          { {1,3},{0,11},{5,7},{10,9},{2,8},{6,4} },
37
          { {10,11},{6,8},{0,9},{4,2},{7,3},{5,1} },
38
          { {7,5},{10,9},{3,1},{0,11},{6,4},{2,8} },
39
          { {2,6},{1,7},{8,4},{5,3},{0,10},{9,11} },
40
          { {4,8},{5,3},{6,2},{1,7},{9,11},{0,10} }
41
      };
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public TablebasesSkewbDiamond()
46
    {
47
    super();
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  public TablebasesSkewbDiamond(Resources res)
53
    {
54
    super(res, R.raw.diam_2_tablebase);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  int[][] getBasicAngles()
60
    {
61
    int[] tmp = {3,3};
62
    return new int[][] { tmp,tmp,tmp,tmp };
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  Static3D[] getRotationAxis()
68
    {
69
    return new Static3D[]
70
         {
71
           new Static3D( SQ6/3, SQ3/3,     0),
72
           new Static3D(-SQ6/3, SQ3/3,     0),
73
           new Static3D(     0,-SQ3/3,-SQ6/3),
74
           new Static3D(     0,-SQ3/3, SQ6/3)
75
         };
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  float[][] getPosition()
81
    {
82
    return new float[][]
83
         {
84
             { 0.5f, 0.0f,  0.5f},
85
             { 0.5f, 0.0f, -0.5f},
86
             {-0.5f, 0.0f, -0.5f},
87
             {-0.5f, 0.0f,  0.5f},
88
             { 0.0f, SQ2/2, 0.0f},
89
             { 0.0f,-SQ2/2, 0.0f},
90

    
91
             { 0.0f, SQ2/4, 0.5f},
92
             { 0.5f, SQ2/4, 0.0f},
93
             { 0.0f, SQ2/4,-0.5f},
94
             {-0.5f, SQ2/4, 0.0f},
95
             { 0.0f,-SQ2/4, 0.5f},
96
             { 0.5f,-SQ2/4, 0.0f},
97
             { 0.0f,-SQ2/4,-0.5f},
98
             {-0.5f,-SQ2/4, 0.0f}
99
         };
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  float[][] getCuts()
105
    {
106
    float[] cut = { 0.0f };
107
    return new float[][] { cut,cut,cut,cut };
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  boolean[][] getRotatable()
113
    {
114
    boolean[] tmp = new boolean[] {false,true};
115
    return new boolean[][] { tmp,tmp,tmp,tmp };
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
// specifically for the tablebase
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  int getSize()
123
    {
124
    return 138240;  // see https://www.jaapsch.net/puzzles/diamond.htm
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  int getMinScramble()
130
    {
131
    return 8;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  int[] getPruningLevels()
137
    {
138
    return null;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  private int computeCenterQuat(int originalLocation, int newLocation)
144
    {
145
    return FREE_CENTER[originalLocation][newLocation][0];
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  private void computeCenterPerm(int[] output, int q0, int q1, int q2, int q3)
151
    {
152
    for(int j=0; j<4; j++)
153
      {
154
      int[] q = FREE_CENTER[0][j];
155
      if( q[0]==q0 || q[1]==q0 || q[2]==q0 ) { output[0]=j; break; }
156
      }
157
    for(int j=0; j<4; j++)
158
      {
159
      int[] q = FREE_CENTER[1][j];
160
      if( q[0]==q1 || q[1]==q1 || q[2]==q1 ) { output[1]=j; break; }
161
      }
162
    for(int j=0; j<4; j++)
163
      {
164
      int[] q = FREE_CENTER[2][j];
165
      if( q[0]==q2 || q[1]==q2 || q[2]==q2 ) { output[2]=j; break; }
166
      }
167
    for(int j=0; j<4; j++)
168
      {
169
      int[] q = FREE_CENTER[3][j];
170
      if( q[0]==q3 || q[1]==q3 || q[2]==q3 ) { output[3]=j; break; }
171
      }
172
    }
173

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

    
176
  private int computeCornerQuat(int originalLocation, int newLocation, int twist)
177
    {
178
    return CORNER_QUATS[originalLocation][newLocation][twist];
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  private int computeCornerPerm(int[] output, int[] quats)
184
    {
185
    int totalTwist = 0;
186

    
187
    for(int i=0; i<6; i++)
188
      {
189
      int q = quats[i];
190
      int[][] perm = CORNER_QUATS[i];
191

    
192
      for(int j=0; j<6; j++)
193
        {
194
        int[] p = perm[j];
195

    
196
        if( p[0]==q ) { output[i]=j;                               break; }
197
        if( p[1]==q ) { output[i]=j; if( i<5 ) totalTwist+=(1<<i); break; }
198
        }
199
      }
200

    
201
    return totalTwist;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  public int[] getQuats(int index)
207
    {
208
    int centers_perm_num = (index%12);
209
    index /= 12;
210
    int totalTwist = (index%32);
211
    int corners_perm_num = (index/32);
212

    
213
    int[] centers_perm = new int[4];
214
    TablebaseHelpers.getEvenPermutationFromNum(centers_perm,centers_perm_num);
215
    int[] corners_perm = new int[6];
216
    TablebaseHelpers.getEvenPermutationFromNum(corners_perm,corners_perm_num);
217

    
218
    int[] quats = new int[14];
219

    
220
    for(int i=0; i<6; i++)
221
      {
222
      int twist = (totalTwist%2);
223
      totalTwist /= 2;
224
      quats[i] = computeCornerQuat(i,corners_perm[i],twist);
225
      }
226

    
227
    quats[ 6] = computeCenterQuat(0,centers_perm[0]);
228
    quats[ 8] = computeCenterQuat(1,centers_perm[1]);
229
    quats[11] = computeCenterQuat(2,centers_perm[2]);
230
    quats[13] = computeCenterQuat(3,centers_perm[3]);
231

    
232
    return quats;
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  public int getIndex(int[] quats)
238
    {
239
    int[] center_perm = new int[4];
240
    computeCenterPerm(center_perm, quats[6],quats[8],quats[11],quats[13]);
241
    int centers_perm_num = TablebaseHelpers.computeEvenPermutationNum(center_perm);
242
    int[] corners_perm = new int[6];
243
    int totalTwist = computeCornerPerm(corners_perm,quats);
244
    int corners_perm_num = TablebaseHelpers.computeEvenPermutationNum(corners_perm);
245

    
246
    return centers_perm_num + 12*(totalTwist + 32*corners_perm_num);
247
    }
248
}  
249

    
(12-12/12)