Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TBCuboid232.java @ 6777e712

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 org.distorted.library.type.Static3D;
13
import org.distorted.objectlib.helpers.OperatingSystemInterface;
14

    
15
///////////////////////////////////////////////////////////////////////////////////////////////////
16

    
17
public class TBCuboid232 extends TablebasesAbstract
18
{
19
  private static final int[][] CORNER_MAP = new int[][]
20
      {
21
          {0,4,7,1,2,3,5,6},
22
          {2,0,1,6,3,4,7,5},
23
          {7,1,0,4,5,6,2,3},
24
          {1,6,2,0,7,5,3,4},
25
          {4,3,5,7,0,2,6,1},
26
          {3,2,6,5,4,0,1,7},
27
          {5,7,4,3,6,1,0,2},
28
          {6,5,3,2,1,7,4,0}
29
      };
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  public TBCuboid232()
34
    {
35
    super();
36
    }
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  public TBCuboid232(OperatingSystemInterface os)
41
    {
42
    super(os,org.distorted.objectlib.R.raw.cu_232_tablebase);
43
    }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  int[][] getBasicAngles()
48
    {
49
    int[] tmp2 = {2,2};
50
    int[] tmp4 = {4,4,4};
51
    return new int[][] { tmp2,tmp4,tmp2 };
52
    }
53

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

    
56
  Static3D[] getRotationAxis()
57
    {
58
    return new Static3D[]
59
         {
60
           new Static3D(1,0,0),
61
           new Static3D(0,1,0),
62
           new Static3D(0,0,1)
63
         };
64
    }
65

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

    
68
  float[][] getPosition()
69
    {
70
    return new float[][]
71
      {
72
        { -0.5f, -1.0f, -0.5f },
73
        { -0.5f, -1.0f,  0.5f },
74
        { -0.5f,  1.0f, -0.5f },
75
        { -0.5f,  1.0f,  0.5f },
76
        {  0.5f, -1.0f, -0.5f },
77
        {  0.5f, -1.0f,  0.5f },
78
        {  0.5f,  1.0f, -0.5f },
79
        {  0.5f,  1.0f,  0.5f },
80

    
81
        { -0.5f,  0.0f, -0.5f },
82
        { -0.5f,  0.0f,  0.5f },
83
        {  0.5f,  0.0f, -0.5f },
84
        {  0.5f,  0.0f,  0.5f },
85
      };
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  float[][] getCuts()
91
    {
92
    return new float[][] { {0.0f}, {-0.5f,0.5f}, {0.0f} };
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  boolean[][] getRotatable()
98
    {
99
    return new boolean[][] { {false,true},{true,false,true},{true,false} };
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
// specifically for the tablebase
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
// 8!*3! --> https://www.jaapsch.net/puzzles/cube223.htm
106

    
107
  int getSize()
108
    {
109
    return 241920;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  int getMinScramble()
115
    {
116
    return 12;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  private void getCornerQuats(int[] output, int[] perm)
122
    {
123
    for(int i=0; i<8; i++)
124
      output[i] = CORNER_MAP[i][perm[i]];
125
    }
126

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

    
129
  private int[] getCornerPerm(int[] quats)
130
    {
131
    int[] output = new int[8];
132

    
133
    for(int i=0; i<8; i++)
134
      {
135
      int quat = quats[i];
136

    
137
      for(int j=0; j<8; j++)
138
        {
139
        if( CORNER_MAP[i][j]==quat )
140
          {
141
          output[i]=j;
142
          break;
143
          }
144
        }
145
      }
146

    
147
    return output;
148
    }
149

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

    
152
  private void getEdgeQuats(int[] output, int[] perm)
153
    {
154
    switch(perm[0])
155
      {
156
      case 0: output[8] = 0; break;
157
      case 2: output[8] = 5; break;
158
      case 3: output[8] = 3; break;
159
      default: android.util.Log.e("D", "getEdgeQuats ERROR1");
160
      }
161

    
162
    output[9] = 0;
163

    
164
    switch(perm[2])
165
      {
166
      case 0: output[10] = 5; break;
167
      case 2: output[10] = 0; break;
168
      case 3: output[10] = 1; break;
169
      default: android.util.Log.e("D", "getEdgeQuats ERROR2");
170
      }
171

    
172
    switch(perm[3])
173
      {
174
      case 0: output[11] = 3; break;
175
      case 2: output[11] = 1; break;
176
      case 3: output[11] = 0; break;
177
      default: android.util.Log.e("D", "getEdgeQuats ERROR3");
178
      }
179
    }
180

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

    
183
  private int[] getEdgePerm(int[] quats)
184
    {
185
    int[] output = new int[4];
186

    
187
    switch(quats[8])
188
      {
189
      case 0: output[0] = 0; break;
190
      case 5: output[0] = 2; break;
191
      case 3: output[0] = 3; break;
192
      default: android.util.Log.e("D", "getEdgePerm ERROR1");
193
      }
194

    
195
    output[1] = 1;
196

    
197
    switch(quats[10])
198
      {
199
      case 0: output[2] = 2; break;
200
      case 1: output[2] = 3; break;
201
      case 5: output[2] = 0; break;
202
      default: android.util.Log.e("D", "getEdgePerm ERROR2");
203
      }
204

    
205
    switch(quats[11])
206
      {
207
      case 0: output[3] = 3; break;
208
      case 1: output[3] = 2; break;
209
      case 3: output[3] = 0; break;
210
      default: android.util.Log.e("D", "getEdgePerm ERROR3");
211
      }
212

    
213
    return output;
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  private int[] uncollapseEdgePerm(int[] perm)
219
    {
220
    int[] ret = new int[4];
221

    
222
    ret[0] = perm[0];
223
    ret[1] = 1;
224
    ret[2] = perm[1];
225
    ret[3] = perm[2];
226

    
227
    if( ret[0]>=1 ) ret[0]++;
228
    if( ret[2]>=1 ) ret[2]++;
229
    if( ret[3]>=1 ) ret[3]++;
230

    
231
    return ret;
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  public int[] getQuats(int index)
237
    {
238
    int[] quats = new int[12];
239

    
240
    int edge_perm_num = index%6;
241
    int corn_perm_num = index/6;
242

    
243
    int[] edge_perm = new int[3];
244
    TablebaseHelpers.getPermutationFromNum(edge_perm,3,edge_perm_num);
245

    
246
    int[] corn_perm = new int[8];
247
    TablebaseHelpers.getPermutationFromNum(corn_perm,8,corn_perm_num);
248

    
249
    int[] edge_perm2 = uncollapseEdgePerm(edge_perm);
250
    getCornerQuats(quats,corn_perm);
251
    getEdgeQuats(quats,edge_perm2);
252

    
253
    return quats;
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  private int[] collapseEdgePerm(int[] perm)
259
    {
260
    int[] ret = new int[3];
261

    
262
    ret[0] = perm[0];
263
    ret[1] = perm[2];
264
    ret[2] = perm[3];
265

    
266
    if( ret[0]>1 ) ret[0]--;
267
    if( ret[1]>1 ) ret[1]--;
268
    if( ret[2]>1 ) ret[2]--;
269

    
270
    return ret;
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  public int getIndex(int[] quats)
276
    {
277
    int[] edge_perm = getEdgePerm(quats);
278
    int[] corn_perm = getCornerPerm(quats);
279
    int[] edge_perm2= collapseEdgePerm(edge_perm); // edge1 is fixed!
280

    
281
    int corn_perm_num = TablebaseHelpers.computePermutationNum(corn_perm);
282
    int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm2);
283

    
284
    return edge_perm_num + 6*corn_perm_num;
285
    }
286
}  
287

    
(4-4/19)