Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TablebasesSkewbDiamond.java @ 4fc4e364

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

    
34
  private static final int[][][] CORNER =
35
      {
36
          { {0,9},{2,4},{10,11},{6,8},{1,5},{3,7} },
37
          { {1,3},{0,11},{5,7},{9,10},{2,8},{4,6} },
38
          { {10,11},{6,8},{0,9},{2,4},{3,7},{1,5} },
39
          { {5,7},{9,10},{1,3},{0,11},{4,6},{2,8} },
40
          { {2,6},{1,7},{4,8},{3,5},{0,10},{9,11} },
41
          { {4,8},{3,5},{2,6},{1,7},{9,11},{0,10} }
42
      };
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

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

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

    
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
             { 0.0f,-SQ2/4, 0.5f}
100
         };
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

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

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

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

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

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  private int computeCenterQuat(int originalLocation, int newLocation)
131
    {
132
    return FREE_CENTER[originalLocation][newLocation][0];
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  private void computeCenterPerm(int[] output, int q0, int q1, int q2, int q3)
138
    {
139
    for(int j=0; j<4; j++)
140
      {
141
      int[] q = FREE_CENTER[0][j];
142
      if( q[0]==q0 || q[1]==q0 || q[2]==q0 ) { output[0]=j; break; }
143
      }
144
    for(int j=0; j<4; j++)
145
      {
146
      int[] q = FREE_CENTER[1][j];
147
      if( q[0]==q1 || q[1]==q1 || q[2]==q1 ) { output[1]=j; break; }
148
      }
149
    for(int j=0; j<4; j++)
150
      {
151
      int[] q = FREE_CENTER[2][j];
152
      if( q[0]==q2 || q[1]==q2 || q[2]==q2 ) { output[2]=j; break; }
153
      }
154
    for(int j=0; j<4; j++)
155
      {
156
      int[] q = FREE_CENTER[3][j];
157
      if( q[0]==q3 || q[1]==q3 || q[2]==q3 ) { output[3]=j; break; }
158
      }
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  private int computeCornerQuat(int originalLocation, int newLocation, int twist)
164
    {
165
    return CORNER[originalLocation][newLocation][twist];
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  private int computeCornerPerm(int[] output, int[] quats)
171
    {
172
    int totalTwist = 0;
173

    
174
    for(int i=0; i<6; i++)
175
      {
176
      int q = quats[i];
177
      int[][] perm = CORNER[i];
178

    
179
      for(int j=0; j<6; j++)
180
        {
181
        int[] p = perm[j];
182

    
183
        if( p[0]==q ) { output[i]=j;                         break; }
184
        if( p[1]==q ) { output[i]=j; if( i<5 ) totalTwist++; break; }
185
        }
186

    
187
      if( i<5 ) totalTwist*=2;
188
      }
189

    
190
    return totalTwist;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  public int[] getQuats(int index)
196
    {
197
    int centers_perm_num = (index%12);
198
    index /= 12;
199
    int totalTwist = (index%128);
200
    int corners_perm_num = (index/128);
201

    
202
    int[] centers_perm = new int[4];
203
    TablebaseHelpers.getEvenPermutationFromNum(centers_perm,centers_perm_num);
204
    int[] corners_perm = new int[6];
205
    TablebaseHelpers.getEvenPermutationFromNum(corners_perm,corners_perm_num);
206

    
207
    int[] quats = new int[14];
208

    
209
    for(int i=0; i<6; i++)
210
      {
211
      int twist = (totalTwist%2);
212
      totalTwist /= 2;
213
      quats[i] = computeCornerQuat(i,corners_perm[i],twist);
214
      }
215

    
216
    quats[ 6] = computeCenterQuat(0,centers_perm[0]);
217
    quats[ 8] = computeCenterQuat(1,centers_perm[1]);
218
    quats[11] = computeCenterQuat(2,centers_perm[2]);
219
    quats[13] = computeCenterQuat(3,centers_perm[3]);
220

    
221
    return quats;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public int getIndex(int[] quats)
227
    {
228
    int[] center_perm = new int[4];
229
    computeCenterPerm(center_perm, quats[6],quats[8],quats[11],quats[13]);
230
    int centers_perm_num = TablebaseHelpers.computeEvenPermutationNum(center_perm);
231
    int[] corners_perm = new int[6];
232
    int totalTwist = computeCornerPerm(corners_perm,quats);
233
    int corners_perm_num = TablebaseHelpers.computeEvenPermutationNum(corners_perm);
234

    
235
int ret = centers_perm_num + 12*(totalTwist + 32*corners_perm_num);
236

    
237
if( ret<0 || ret>=138240 )
238
  {
239
  android.util.Log.e("D", "centers_perm: "+centers_perm_num+" twist: "+totalTwist+" corners_perm: "+corners_perm_num);
240
  }
241

    
242
    return centers_perm_num + 12*(totalTwist + 32*corners_perm_num);
243
    }
244
}  
245

    
(9-9/9)