Project

General

Profile

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

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

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.5f,  0.0f,-0.5f},
76
             { 0.5f,  0.0f, 0.5f},
77
             {-0.5f,  0.0f,-0.5f},
78
             {-0.5f,  0.0f, 0.5f},
79
             { 0.0f, SQ2/2, 0.0f},
80
         };
81
    }
82

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

    
85
  float[][] getCuts()
86
    {
87
    float[] cut = { 0.25f*(SQ6/3) };
88
    return new float[][] { cut,cut,cut,cut };
89
    }
90

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

    
93
  boolean[][] getRotatable()
94
    {
95
    boolean[] tmp = new boolean[] {false,true};
96
    return new boolean[][] { tmp,tmp,tmp,tmp };
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// specifically for the tablebase
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  int getSize()
104
    {
105
    return 933120;  // see https://www.jaapsch.net/puzzles/pyraminx.htm
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  public static void getEdgePermutation(int[] output, int[] quats, int index)
111
    {
112
    for(int i=0; i<6; i++ )
113
      {
114
      int quat = quats[i+index];
115

    
116
      for(int j=0; j<6; j++)
117
        {
118
        int[] edge = EDGE_QUATS[j];
119
        if( quat==edge[0] || quat==edge[1] ) { output[i]=j; break; }
120
        }
121
      }
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  public static void getEdgeTwist(int[] output, int[] quats, int index)
127
    {
128
    for(int i=0; i<6; i++)
129
      {
130
      int quat = quats[i+index];
131

    
132
      for(int j=0; j<6; j++)
133
        {
134
        int[] edge = EDGE_QUATS[j];
135
        if( quat==edge[0] ) { output[i]=0; break; }
136
        if( quat==edge[1] ) { output[i]=1; break; }
137
        }
138
      }
139
    }
140

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

    
143
  private void getEdgeQuats(int twist, int[] perm, int[] output)
144
    {
145
    for(int i=0; i<6; i++)
146
      {
147
      int p = perm[i];
148
      int t = twist%2;
149
      twist/=2;
150
      output[i] = EDGE_QUATS[p][t];
151
      }
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  private int getVertexTwist(int[] quats)
157
    {
158
    int twist = 0;
159

    
160
    if( quats[3]==5 ) twist += 1;
161
    if( quats[3]==6 ) twist += 2;
162
    twist *= 3;
163
    if( quats[2]==7 ) twist += 1;
164
    if( quats[2]==8 ) twist += 2;
165
    twist *= 3;
166
    if( quats[1]==1 ) twist += 1;
167
    if( quats[1]==2 ) twist += 2;
168
    twist *= 3;
169
    if( quats[0]==3 ) twist += 1;
170
    if( quats[0]==4 ) twist += 2;
171

    
172
    return twist;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  private void getVertexQuats(int twist, int[] output)
178
    {
179
    switch(twist%3)
180
      {
181
      case 0: output[0]=0; break;
182
      case 1: output[0]=3; break;
183
      case 2: output[0]=4; break;
184
      }
185
    twist /= 3;
186

    
187
    switch(twist%3)
188
      {
189
      case 0: output[1]=0; break;
190
      case 1: output[1]=1; break;
191
      case 2: output[1]=2; break;
192
      }
193
    twist /= 3;
194

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

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  int[] getQuats(int index)
214
    {
215
    int vertexTwist = (index%81);
216
    index /= 81;
217
    int edgeTwist = (index%32);
218
    int perm_num = index/32;
219

    
220
    int[] quats = new int[10];
221

    
222
    getVertexQuats(vertexTwist,quats);
223
    int[] permutation = new int[6];
224
    TablebaseHelpers.getPermutationFromNum(permutation,6,perm_num);
225
    getEdgeQuats(edgeTwist,permutation,quats);
226

    
227
    return quats;
228
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  int getIndex(int[] quats)
233
    {
234
    int vertexTwist = getVertexTwist(quats);
235
    int[] permutation = new int[6];
236
    getEdgePermutation(permutation,quats,4);
237
    int[] twist = new int[6];
238
    getEdgeTwist(twist,quats,4);
239

    
240
    int edgeTwist = twist[0]+ 2*(twist[1]+ 2*(twist[2]+ 2*(twist[3]+ 2*twist[4])));
241
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(permutation);
242

    
243
    return vertexTwist + 81*(edgeTwist + 32*perm_num);
244
    }
245
}  
246

    
(7-7/8)