Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TBDino6.java @ 5b9f1cec

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.SQ3;
13

    
14
import android.content.res.Resources;
15

    
16
import org.distorted.library.type.Static3D;
17
import org.distorted.objectlib.R;
18

    
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
public class TBDino6 extends TablebasesPruning
22
{
23
  private static final int INDEX_INVERTED = 13379863; // quats (0,10,0,10, 11,11,11,11, 0,10,0,10)
24

    
25
  private static final int[][] QUATS =
26
      {
27
          {0,2,10,8, 1,4,6,7,   11,5,9,3},
28
          {1,0,6,10, 2,5,8,3,   7,9,4,11},
29
          {10,5,0,3, 7,6,4,1,   9,2,11,8},
30
          {7,10,4,0, 5,2,3,8,   1,11,6,9},
31
          {2,1,8,6,  0,9,10,11, 3,4,5,7 },
32
          {3,6,5,1,  9,0,11,10, 2,7,8,4 },
33
          {5,7,3,4,  10,11,0,9, 8,6,2,1 },
34
          {8,4,2,7,  11,10,9,0, 5,1,3,6 },
35
          {11,8,9,2, 4,1,7,6,   0,3,10,5},
36
          {6,9,1,11, 3,8,5,2,   4,0,7,10},
37
          {9,3,11,5, 6,7,1,4,   10,8,0,2},
38
          {4,11,7,9, 8,3,2,5,   6,10,1,0}
39
      };
40

    
41
  private int[][] mAngles;
42

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

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

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

    
52
  public TBDino6(Resources res)
53
    {
54
    super(res,new int[] {R.raw.dino_3_pruning3,R.raw.dino_3_pruning4},new int[] {R.raw.dino_3_pruning10});
55
    }
56

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

    
59
  int[][] getBasicAngles()
60
    {
61
    if( mAngles==null )
62
      {
63
      int[] tmp = {3,3,3};
64
      mAngles = new int[][] { tmp,tmp,tmp,tmp };
65
      }
66

    
67
    return mAngles;
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  Static3D[] getRotationAxis()
73
    {
74
    return new Static3D[]
75
         {
76
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
77
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
78
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
79
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
80
         };
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  float[][] getPosition()
86
    {
87
    return new float[][]
88
         {
89
             { 0.0f, 1.5f, 1.5f },
90
             { 1.5f, 0.0f, 1.5f },
91
             { 0.0f,-1.5f, 1.5f },
92
             {-1.5f, 0.0f, 1.5f },
93
             { 1.5f, 1.5f, 0.0f },
94
             { 1.5f,-1.5f, 0.0f },
95
             {-1.5f,-1.5f, 0.0f },
96
             {-1.5f, 1.5f, 0.0f },
97
             { 0.0f, 1.5f,-1.5f },
98
             { 1.5f, 0.0f,-1.5f },
99
             { 0.0f,-1.5f,-1.5f },
100
             {-1.5f, 0.0f,-1.5f }
101
         };
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  float[][] getCuts()
107
    {
108
    float[] cut = new float[] { -SQ3/3, SQ3/3 };
109
    return new float[][] { cut,cut,cut,cut };
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
// exclude the middle layer and movements of edge[0].
114

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// specifically for the tablebase
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// two solved positions: original and mirrored (left face swapped with right)
125

    
126
  @Override
127
  int[] getSolvedIndices()
128
    {
129
    return new int[] {0,INDEX_INVERTED};
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
// ditto
134

    
135
  @Override
136
  boolean isSolved(int index)
137
    {
138
    return index==0 || index==INDEX_INVERTED;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
// we can never really move the top-front edge, because if we do so, we would also rotate the
143
// rotation axis themselves! (see getIndex() where the cubit quats are normalized so that quat[0]
144
// - i.e. the front-top edge - is always 0).
145
// That's why map the moves (0,2,X) to (0,0&1,-X) and (3,0,X) to (3,1&2,-X)
146

    
147
  @Override
148
  int[] newMove(int axis, int layer, int angle)
149
    {
150
    if( axis==0 && layer==2 ) return new int[] { axis, (1<<0)+(1<<1), angle==1 ? 1:-1};
151
    if( axis==3 && layer==0 ) return new int[] { axis, (1<<1)+(1<<2), angle==1 ? 1:-1};
152

    
153
    int maxAngle = mAngles[axis][layer];
154
    angle = maxAngle-angle;
155
    if( angle> 0.5f*maxAngle ) angle -= maxAngle;
156
    return new int[] { axis, (1<<layer), angle };
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  int getSize()
162
    {
163
    return 19958400;  // see https://www.jaapsch.net/puzzles/dinocube.htm
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  int getMinScramble()
169
    {
170
    return 8;
171
    }
172

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

    
175
  int[] getMidPruningLevels()
176
    {
177
    return new int[] {3,4};
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  int[] getHighPruningLevels()
183
    {
184
    return new int[] {10};
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  int getGodsNumber()
190
    {
191
    return 10;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
197
    {
198
    return (lastA!=currA) || (lastR!=currR);
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  public static int getIndexFromPerm(int[] perm)
204
    {
205
    int[] perm11 = new int[11];
206
    for(int i=0; i<11; i++) perm11[i] = perm[i+1]-1;
207
    return TablebaseHelpers.computeEvenPermutationNum(perm11);
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
// in-place!
212

    
213
  private int[] getPermFromQuats(int[] quats)
214
    {
215
    for(int i=0; i<12; i++)
216
      {
217
      int[] Q = QUATS[i];
218
      int quat = quats[i];
219

    
220
      for(int j=0; j<12; j++)
221
        if( Q[j]==quat )
222
          {
223
          quats[i] = j;
224
          break;
225
          }
226
      }
227

    
228
    return quats;
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
// in-place!
233

    
234
  public static int[] getQuatsFromPerm(int[] perm)
235
    {
236
    for(int i=0; i<12; i++)
237
      {
238
      int p = perm[i];
239
      perm[i] = QUATS[i][p];
240
      }
241

    
242
    return perm;
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
// we rotate the whole thing so that quat[0] is always 0.
247

    
248
  private void normalizeQuats(int[] quats)
249
    {
250
    if( quats[0]!=0 )
251
      {
252
      int inverted = getInvertedQuat(quats[0]);
253
      quats[0] = 0;
254

    
255
      for(int i=1; i<12; i++)
256
        {
257
        int index = quats[i];
258
        quats[i] = getMultQuat(inverted,index);
259
        }
260
      }
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  int[] getQuats(int index)
266
    {
267
    int[] perm11 = new int[11];
268
    TablebaseHelpers.getEvenPermutationFromNum(perm11,index);
269
    int[] perm = new int[12];
270
    for(int i=1; i<12; i++) perm[i] = perm11[i-1]+1;
271
    return getQuatsFromPerm(perm);
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  int getIndex(int[] quats)
277
    {
278
    normalizeQuats(quats);
279
    int[] perm = getPermFromQuats(quats);
280
    return getIndexFromPerm(perm);
281
    }
282
}  
283

    
(5-5/15)