Project

General

Profile

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

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

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.R;
19
import org.distorted.objectlib.objects.TwistyPyraminx;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

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

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  public TablebasesPyraminx(Resources res)
45
    {
46
    super(res, R.raw.pyra_3_tablebase);
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

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

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

    
75
             { 0.0f,-SQ2/2, 0.0f},   // index=0 has the quats already set up so that
76
             { 0.0f,-SQ2/2, 0.0f},   // all the edges fall into right spots, so here
77
             { 0.0f,-SQ2/2, 0.0f},   // they need to be all in one place
78
             { 0.0f,-SQ2/2, 0.0f},
79
             { 0.0f,-SQ2/2, 0.0f},
80
             { 0.0f,-SQ2/2, 0.0f},
81
         };
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

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

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

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

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

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

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

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

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

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

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

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

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  private void getEdgeQuats(int twist, int[] perm, int[] output)
145
    {
146
    int totalTwist = 0;
147

    
148
    for(int i=0; i<5; i++)
149
      {
150
      int p = perm[i];
151
      int t = (twist%2);
152
      twist/=2;
153
      output[i+4] = EDGE_QUATS[p][t];
154

    
155
      totalTwist += t;
156
      }
157

    
158
    int p = perm[5];
159
    int t = (totalTwist%2)==0 ? 0:1;
160
    output[9] = EDGE_QUATS[p][t];
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

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

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

    
181
    return twist;
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

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

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

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

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

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

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

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

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

    
236
    return quats;
237
    }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

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

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

    
252
    return vertexTwist + 81*(edgeTwist + 32*perm_num);
253
    }
254
}  
255

    
(7-7/8)