Project

General

Profile

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

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

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 android.content.res.Resources;
15

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

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

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

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

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public TBPyraminxDiamond(Resources res)
55
    {
56
    super(res, new int[] {R.raw.pdia_3_pruning3,R.raw.pdia_3_pruning4}, new int[] {R.raw.pdia_3_pruning10});
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

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

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

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

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

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

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

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

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

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

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

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

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

    
181
    return -1;
182
    }
183

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

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

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

    
196
    return -1;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

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

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

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

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

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

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

    
221
    return quats;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

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

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

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

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

    
(11-11/18)