Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / tablebases / TablebasesIvyCube.java @ 884b702b

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

    
14
import org.distorted.library.type.Static3D;
15
import static org.distorted.objectlib.main.TwistyObject.SQ3;
16

    
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

    
19
public class TablebasesIvyCube extends TablebasesAbstract
20
{
21
  private static final int[] mTmp = new int[6];
22

    
23
  private static final int[][] MAP = { {0,4,2,2,5,3,4,5,3,0,1,1},
24
                                       {1,5,3,3,4,2,5,4,2,1,0,0},
25
                                       {2,0,4,5,0,5,1,1,4,3,3,2},
26
                                       {3,1,5,4,1,4,0,0,5,2,2,3},
27
                                       {4,2,0,1,3,0,3,2,1,5,4,5},
28
                                       {5,3,1,0,2,1,2,3,0,4,5,4} };
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
  public TablebasesIvyCube()
33
    {
34
    super();
35
    }
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  public TablebasesIvyCube(Resources res)
40
    {
41
    super(res,org.distorted.objectlib.R.raw.ivy_2_tablebase);
42
    }
43

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

    
46
  int[][] getBasicAngles()
47
    {
48
    int[] tmp = {3,3};
49
    return new int[][] { tmp,tmp,tmp,tmp };
50
    }
51

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

    
54
  Static3D[] getRotationAxis()
55
    {
56
    return new Static3D[]
57
         {
58
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
59
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
60
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
61
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
62
         };
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  float[][] getPosition()
68
    {
69
    final float DIST_CORNER = 1;
70
    final float DIST_CENTER = 1;
71

    
72
    return new float[][]
73
      {
74
        { DIST_CORNER, DIST_CORNER, DIST_CORNER },
75
        {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
76
        {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
77
        { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
78
        { DIST_CENTER,           0,           0 },
79
        {-DIST_CENTER,           0,           0 },
80
        {           0, DIST_CENTER,           0 },
81
        {           0,-DIST_CENTER,           0 },
82
        {           0,           0, DIST_CENTER },
83
        {           0,           0,-DIST_CENTER },
84
      };
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  float[][] getCuts()
90
    {
91
    float[] cut = { 0.0f };
92
    return new float[][] { cut,cut,cut,cut };
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  boolean[][] getRotatable()
98
    {
99
    boolean[] tmp1 = new boolean[] {false,true};
100
    boolean[] tmp2 = new boolean[] {true,false};
101

    
102
    return new boolean[][] { tmp1,tmp2,tmp2,tmp1 };
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// specifically for the tablebase
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
// orientations of 4 corners + any even permutation of 6 centers
109

    
110
  int getSize()
111
    {
112
    return (3*3*3*3)*(6*5*4*3);
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  int getMinScramble()
118
    {
119
    return 7;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  int[] getPruningLevels()
125
    {
126
    return null;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  private int findFirst(int[] table, int value)
132
    {
133
    int len = table.length;
134

    
135
    for(int i=0; i<len; i++)
136
      if( table[i]==value ) return i;
137

    
138
    return -1;
139
    }
140

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

    
143
  public int[] getQuats(int index)
144
    {
145
    int perm_num = index%360;
146
    index /= 360;
147
    int twist0 = index%3;
148
    index /= 3;
149
    int twist1 = index%3;
150
    index /= 3;
151
    int twist2 = index%3;
152
    index /= 3;
153
    int twist3 = index%3;
154

    
155
    int[] ret = new int[10];
156

    
157
    ret[0] = twist0==0 ? 0 : (twist0==1 ? 2:1);
158
    ret[1] = twist1==0 ? 0 : (twist1==1 ? 5:6);
159
    ret[2] = twist2==0 ? 0 : (twist2==1 ? 3:4);
160
    ret[3] = twist3==0 ? 0 : (twist3==1 ? 8:7);
161

    
162
    TablebaseHelpers.getEvenPermutationFromNum(mTmp,perm_num);
163

    
164
    for(int i=0; i<6; i++)
165
      {
166
      int cubitThatMoves = mTmp[i];
167
      ret[cubitThatMoves+4] = findFirst(MAP[cubitThatMoves],i);
168
      }
169

    
170
    return ret;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public int getIndex(int[] quats)
176
    {
177
    int twist0 = quats[0]==0 ? 0 : (quats[0]==1 ? 2:1);
178
    int twist1 = quats[1]==0 ? 0 : (quats[1]==6 ? 2:1);
179
    int twist2 = quats[2]==0 ? 0 : (quats[2]==4 ? 2:1);
180
    int twist3 = quats[3]==0 ? 0 : (quats[3]==7 ? 2:1);
181

    
182
    int c4 = MAP[0][quats[4]];
183
    int c5 = MAP[1][quats[5]];
184
    int c6 = MAP[2][quats[6]];
185
    int c7 = MAP[3][quats[7]];
186
    int c8 = MAP[4][quats[8]];
187
    int c9 = MAP[5][quats[9]];
188

    
189
    mTmp[c4]=0;
190
    mTmp[c5]=1;
191
    mTmp[c6]=2;
192
    mTmp[c7]=3;
193
    mTmp[c8]=4;
194
    mTmp[c9]=5;
195

    
196
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(mTmp);
197

    
198
    return perm_num + 360*(twist0+ 3*(twist1+ 3*(twist2+ 3*twist3)));
199
    }
200
}  
201

    
(8-8/12)