Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TablebasesPyraminx.java @ bf890718

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.SQ6;
14

    
15
import android.content.res.Resources;
16

    
17
import org.distorted.library.type.Static3D;
18
import org.distorted.objectlib.objects.TwistyPyraminx;
19

    
20
///////////////////////////////////////////////////////////////////////////////////////////////////
21

    
22
public class TablebasesPyraminx extends TablebasesAbstract
23
{
24
  public static final int[][] EDGE_QUATS = new int[][]
25
      {
26
          { 0,10},  // even-odd quat (i.e. even-odd twist of the relevant edge piece)
27
          { 1, 7},
28
          { 4, 8},
29
          { 2, 6},
30
          { 3, 5},
31
          { 9,11}
32
      };
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  public TablebasesPyraminx()
37
    {
38
    super();
39
    }
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  public TablebasesPyraminx(Resources res)
44
    {
45
    super(res,org.distorted.objectlib.R.raw.pduo_2_tablebase);
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  int[][] getBasicAngles()
51
    {
52
    int[] tmp = {3,3};
53
    return new int[][] { tmp,tmp,tmp,tmp };
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  Static3D[] getRotationAxis()
59
    {
60
    return TwistyPyraminx.ROT_AXIS;
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  float[][] getPosition()
66
    {
67
    return new float[][]
68
         {
69
             { 0.0f,-SQ2/4, 0.5f},
70
             { 0.0f,-SQ2/4,-0.5f},
71
             {-0.5f, SQ2/4, 0.0f},
72
             { 0.5f, SQ2/4, 0.0f},
73

    
74
             { 0.0f,-SQ2/2, 0.0f},
75
             { 0.0f,-SQ2/2, 0.0f},
76
             { 0.0f,-SQ2/2, 0.0f},
77
             { 0.0f,-SQ2/2, 0.0f},
78
             { 0.0f,-SQ2/2, 0.0f},
79
             { 0.0f,-SQ2/2, 0.0f},
80

    
81
             /*
82
             { 0.5f,  0.0f,-0.5f},
83
             { 0.5f,  0.0f, 0.5f},
84
             {-0.5f,  0.0f,-0.5f},
85
             {-0.5f,  0.0f, 0.5f},
86
             { 0.0f, SQ2/2, 0.0f},
87
              */
88
         };
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  float[][] getCuts()
94
    {
95
    float[] cut = { 0.25f*(SQ6/3) };
96
    return new float[][] { cut,cut,cut,cut };
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  boolean[][] getRotatable()
102
    {
103
    boolean[] tmp = new boolean[] {false,true};
104
    return new boolean[][] { tmp,tmp,tmp,tmp };
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
// specifically for the tablebase
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  int getSize()
112
    {
113
    return 933120;  // see https://www.jaapsch.net/puzzles/pyraminx.htm
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public static void getEdgePermutation(int[] output, int[] quats, int index)
119
    {
120
    for(int i=0; i<6; i++ )
121
      {
122
      int quat = quats[i+index];
123

    
124
      for(int j=0; j<6; j++)
125
        {
126
        int[] edge = EDGE_QUATS[j];
127
        if( quat==edge[0] || quat==edge[1] ) { output[i]=j; break; }
128
        }
129
      }
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public static void getEdgeTwist(int[] output, int[] quats, int index)
135
    {
136
    for(int i=0; i<6; i++)
137
      {
138
      int quat = quats[i+index];
139

    
140
      for(int j=0; j<6; j++)
141
        {
142
        int[] edge = EDGE_QUATS[j];
143
        if( quat==edge[0] ) { output[i]=0; break; }
144
        if( quat==edge[1] ) { output[i]=1; break; }
145
        }
146
      }
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  private void getEdgeQuats(int twist, int[] perm, int[] output)
152
    {
153
    for(int i=0; i<6; i++)
154
      {
155
      int p = perm[i];
156
      int t = twist%2;
157
      twist/=2;
158
      output[i+4] = EDGE_QUATS[p][t];
159
      }
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  private int getVertexTwist(int[] quats)
165
    {
166
    int twist = 0;
167

    
168
    if( quats[3]==5 ) twist += 1;
169
    if( quats[3]==6 ) twist += 2;
170
    twist *= 3;
171
    if( quats[2]==7 ) twist += 1;
172
    if( quats[2]==8 ) twist += 2;
173
    twist *= 3;
174
    if( quats[1]==1 ) twist += 1;
175
    if( quats[1]==2 ) twist += 2;
176
    twist *= 3;
177
    if( quats[0]==3 ) twist += 1;
178
    if( quats[0]==4 ) twist += 2;
179

    
180
    return twist;
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  private void getVertexQuats(int twist, int[] output)
186
    {
187
    switch(twist%3)
188
      {
189
      case 0: output[0]=0; break;
190
      case 1: output[0]=3; break;
191
      case 2: output[0]=4; break;
192
      }
193
    twist /= 3;
194

    
195
    switch(twist%3)
196
      {
197
      case 0: output[1]=0; break;
198
      case 1: output[1]=1; break;
199
      case 2: output[1]=2; break;
200
      }
201
    twist /= 3;
202

    
203
    switch(twist%3)
204
      {
205
      case 0: output[2]=0; break;
206
      case 1: output[2]=7; break;
207
      case 2: output[2]=8; break;
208
      }
209
    twist /= 3;
210

    
211
    switch(twist%3)
212
      {
213
      case 0: output[3]=0; break;
214
      case 1: output[3]=5; break;
215
      case 2: output[3]=6; break;
216
      }
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  int[] getQuats(int index)
222
    {
223
    int vertexTwist = (index%81);
224
    index /= 81;
225
    int edgeTwist = (index%32);
226
    int perm_num = index/32;
227

    
228
    int[] quats = new int[10];
229

    
230
    getVertexQuats(vertexTwist,quats);
231
    int[] permutation = new int[6];
232
    TablebaseHelpers.getPermutationFromNum(permutation,6,perm_num);
233
    getEdgeQuats(edgeTwist,permutation,quats);
234

    
235
    return quats;
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  int getIndex(int[] quats)
241
    {
242
    int vertexTwist = getVertexTwist(quats);
243
    int[] permutation = new int[6];
244
    getEdgePermutation(permutation,quats,4);
245
    int[] twist = new int[6];
246
    getEdgeTwist(twist,quats,4);
247

    
248
    int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
249
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
250

    
251
int ret = vertexTwist + 81*(edgeTwist + 32*perm_num);
252

    
253
if( ret<0 || ret>=933120 )
254
  {
255
  android.util.Log.e("D", "vertexTwist="+vertexTwist+" edgeTwist="+edgeTwist+" perm_num="+perm_num);
256
  android.util.Log.e("D", "perm: "+permutation[0]+" "+permutation[1]+" "+permutation[2]+" "+permutation[3]+" "+permutation[4]+" "+permutation[5]);
257
  android.util.Log.e("D", "quat: "+quats[4]+" "+quats[5]+" "+quats[6]+" "+quats[7]+" "+quats[8]+" "+quats[9]);
258
  }
259

    
260
    return vertexTwist + 81*(edgeTwist + 32*perm_num);
261
    }
262
}  
263

    
(7-7/8)