Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TBPyraminxDiamond.java @ e1e92738

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

    
14
import org.distorted.library.type.Static3D;
15
import org.distorted.objectlib.R;
16
import org.distorted.objectlib.helpers.OperatingSystemInterface;
17

    
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
public class TBPyraminxDiamond extends TablebasesPruning
21
{
22
  private static final int[][] CORNER_QUATS =
23
      {
24
          {0,6,5,4},
25
          {0,4,5,6},
26
          {0,3,2,1},
27
          {0,9,8,7},
28
          {0,7,8,9},
29
          {0,1,2,3},
30
      };
31

    
32
  private static final int[][][] CENTER_QUATS =
33
      {
34
          { {21,15, 0}, {10,13, 5}, {17, 9, 3}, {16,18,11}, {19, 1, 6}, { 2,12,23}, { 7,14, 4}, { 8,20,22} },
35
          { { 5,23,20}, { 0,22,12}, {19,16,14}, { 7,17, 1}, { 4,11, 9}, {10, 8,15}, { 6, 3,18}, {21, 2,13} },
36
          { { 1,17, 7}, {14,16,19}, { 0,12,22}, { 5,20,23}, {13, 2,21}, { 6,18, 3}, {15, 8,10}, { 4, 9,11} },
37
          { {18,11,16}, { 9, 3,17}, { 5,10,13}, { 0,21,15}, {20,22, 8}, { 4, 7,14}, {12,23, 2}, { 6,19, 1} },
38
          { { 4,19, 3}, { 6, 7,11}, {15, 2,20}, {13, 8,12}, { 0,10,23}, { 1,16, 9}, { 5,21,22}, {14,17,18} },
39
          { {10, 2,22}, {21, 8,23}, { 4, 1,18}, { 6,14, 9}, { 7,16, 3}, { 0,13,20}, {19,17,11}, { 5,15,12} },
40
          { { 6,14, 9}, { 4, 1,18}, {21, 8,23}, {10, 2,22}, { 5,15,12}, {19,17,11}, { 0,13,20}, { 7,16, 3} },
41
          { {12, 8,13}, {20, 2,15}, { 6,11, 7}, { 4, 3,19}, {18,17,14}, { 5,22,21}, { 9,16, 1}, { 0,23,10} },
42
      };
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  public TBPyraminxDiamond()
47
    {
48
    super();
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public TBPyraminxDiamond(OperatingSystemInterface os)
54
    {
55
    super(os, new int[] {R.raw.pdia_3_pruning3,R.raw.pdia_3_pruning4}, new int[] {R.raw.pdia_3_pruning10});
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  int[][] getBasicAngles()
61
    {
62
    int[] tmp = {4,4,4};
63
    return new int[][] { tmp,tmp,tmp };
64
    }
65

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

    
68
  Static3D[] getRotationAxis()
69
    {
70
    return new Static3D[]
71
         {
72
         new Static3D(SQ2/2, 0, SQ2/2),
73
         new Static3D(    0, 1,     0),
74
         new Static3D(SQ2/2, 0,-SQ2/2)
75
         };
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  float[][] getPosition()
81
    {
82
    float B0 = 1.5f*SQ2;
83
    float C0 = 1.5f;
84
    float A  = 1.03f;
85
    float B1 = 0.5f*SQ2*A;
86
    float C1 = A;
87

    
88
    return new float[][]
89
         {
90
             {  0, B0,  0 },
91
             {  0,-B0,  0 },
92
             { C0,  0, C0 },
93
             { C0,  0,-C0 },
94
             {-C0,  0, C0 },
95
             {-C0,  0,-C0 },
96

    
97
             {  0, B1, C1 },
98
             {  0, B1,-C1 },
99
             {  0,-B1, C1 },
100
             {  0,-B1,-C1 },
101
             { C1, B1,  0 },
102
             { C1,-B1,  0 },
103
             {-C1, B1,  0 },
104
             {-C1,-B1,  0 },
105
         };
106
    }
107

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

    
110
  float[][] getCuts()
111
    {
112
    float C = 0.5f*SQ2;
113
    float[] cut = { -C,C};
114
    return new float[][] { cut,cut,cut };
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  boolean[][] getRotatable()
120
    {
121
    boolean[] tmp = {true,false,true};
122
    return new boolean[][] { tmp,tmp,tmp };
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
// specifically for the tablebase
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
// 4^6 - corner twists; 8! - center permutation; divide by 2 because parity of permutation must
129
// agree with parity of total twists = (4^6)*8! / 2 = 82.575.360
130

    
131
  int getSize()
132
    {
133
    return 82575360;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  int getMinScramble()
139
    {
140
    return 8;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  int[] getMidPruningLevels()
146
    {
147
    return new int[] {3,4};
148
    }
149

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

    
152
  int[] getHighPruningLevels()
153
    {
154
    return new int[] {10};
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  int getGodsNumber()
160
    {
161
    return 10;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
167
    {
168
    return (lastA!=currA) || (lastR!=currR);
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  private int findIndex1(int[] table, int entry)
174
    {
175
    int len = table.length;
176

    
177
    for(int i=0; i<len; i++)
178
      if( table[i]==entry ) return i;
179

    
180
    return -1;
181
    }
182

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

    
185
  private int findIndex2(int[][] table, int entry)
186
    {
187
    int len = table.length;
188

    
189
    for(int i=0; i<len; i++)
190
      {
191
      int[] t = table[i];
192
      if( t[0]==entry || t[1]==entry || t[2]==entry ) return i;
193
      }
194

    
195
    return -1;
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

    
200
  public int[] getQuats(int index)
201
    {
202
    int[] quats = new int[14];
203
    int[] perm  = new int[8];
204
    int[] twist = new int[6];
205

    
206
    int centers_perm_num = index/2048;
207
    int total_twist = index%2048;
208

    
209
    TablebaseHelpers.getPermutationFromNum(perm,8,centers_perm_num);
210
    boolean even = TablebaseHelpers.permutationIsEven(perm);
211

    
212
    for(int i=0; i<5; i++) { twist[i] = total_twist%4; total_twist /=4; }
213

    
214
    int total = twist[0]+twist[1]+twist[2]+twist[3]+twist[4]+(even?0:1);
215
    twist[5] = 2*total_twist + (total%2);
216

    
217
    for(int i=0; i<6; i++) quats[i  ] = CORNER_QUATS[i][twist[i]];
218
    for(int i=0; i<8; i++) quats[i+6] = CENTER_QUATS[i][perm[i]][0];
219

    
220
    return quats;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  public int getIndex(int[] quats)
226
    {
227
    int[] twist = new int[6];
228
    int[] perm  = new int[8];
229

    
230
    for(int i=0; i<6; i++) twist[i] = findIndex1(CORNER_QUATS[i],quats[i]);
231
    for(int i=0; i<8; i++) perm[i]  = findIndex2(CENTER_QUATS[i],quats[i+6]);
232

    
233
    int centers_perm_num = TablebaseHelpers.computePermutationNum(perm);
234
    int total_twist = twist[0]+ 4*(twist[1]+ 4*(twist[2]+ 4*(twist[3]+ 4*(twist[4]+ 4*(twist[5]>1 ? 1:0)))));
235

    
236
    return total_twist + 2048*centers_perm_num;
237
    }
238
}  
239

    
(12-12/19)