Project

General

Profile

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

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

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

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

    
20
public class TBPyraminxDiamond extends TablebasesAbstract
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(Resources res)
54
    {
55
    super(res, 0);
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
  private int findIndex1(int[] table, int entry)
146
    {
147
    int len = table.length;
148

    
149
    for(int i=0; i<len; i++)
150
      if( table[i]==entry ) return i;
151

    
152
    return -1;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  private int findIndex2(int[][] table, int entry)
158
    {
159
    int len = table.length;
160

    
161
    for(int i=0; i<len; i++)
162
      {
163
      int[] t = table[i];
164
      if( t[0]==entry || t[1]==entry || t[2]==entry ) return i;
165
      }
166

    
167
    return -1;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public int[] getQuats(int index)
173
    {
174
    int[] quats = new int[14];
175
    int[] perm  = new int[8];
176
    int[] twist = new int[6];
177

    
178
    int centers_perm_num = index/2048;
179
    int total_twist = index%2048;
180

    
181
    TablebaseHelpers.getPermutationFromNum(perm,8,centers_perm_num);
182
    boolean even = TablebaseHelpers.permutationIsEven(perm);
183

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

    
186
    int total = twist[0]+twist[1]+twist[2]+twist[3]+twist[4]+(even?0:1);
187
    twist[5] = 2*(1-total_twist) + (total%2);
188

    
189
    for(int i=0; i<6; i++) quats[i  ] = CORNER_QUATS[i][twist[i]];
190
    for(int i=0; i<8; i++) quats[i+6] = CENTER_QUATS[i][perm[i]][0];
191

    
192
    return quats;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  public int getIndex(int[] quats)
198
    {
199
    int[] twist = new int[6];
200
    int[] perm  = new int[8];
201

    
202
    for(int i=0; i<6; i++) twist[i] = findIndex1(CORNER_QUATS[i],quats[i]);
203
    for(int i=0; i<8; i++) perm[i]  = findIndex2(CENTER_QUATS[i],quats[i]);
204

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

    
208
    return total_twist + 2048*centers_perm_num;
209
    }
210
}  
211

    
(11-11/18)