Project

General

Profile

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

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

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
  private int findFirst(int[] table, int value)
118
    {
119
    int len = table.length;
120

    
121
    for(int i=0; i<len; i++)
122
      if( table[i]==value ) return i;
123

    
124
    return -1;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  public int[] getQuats(int index)
130
    {
131
    int perm_num = index%360;
132
    index /= 360;
133
    int twist0 = index%3;
134
    index /= 3;
135
    int twist1 = index%3;
136
    index /= 3;
137
    int twist2 = index%3;
138
    index /= 3;
139
    int twist3 = index%3;
140

    
141
    int[] ret = new int[10];
142

    
143
    ret[0] = twist0==0 ? 0 : (twist0==1 ? 2:1);
144
    ret[1] = twist1==0 ? 0 : (twist1==1 ? 5:6);
145
    ret[2] = twist2==0 ? 0 : (twist2==1 ? 3:4);
146
    ret[3] = twist3==0 ? 0 : (twist3==1 ? 8:7);
147

    
148
    TablebaseHelpers.getEvenPermutationFromNum(mTmp,6,perm_num);
149

    
150
    for(int i=0; i<6; i++)
151
      {
152
      int cubitThatMoves = mTmp[i];
153
      ret[cubitThatMoves+4] = findFirst(MAP[cubitThatMoves],i);
154
      }
155

    
156
    return ret;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public int getIndex(int[] quats)
162
    {
163
    int twist0 = quats[0]==0 ? 0 : (quats[0]==1 ? 2:1);
164
    int twist1 = quats[1]==0 ? 0 : (quats[1]==6 ? 2:1);
165
    int twist2 = quats[2]==0 ? 0 : (quats[2]==4 ? 2:1);
166
    int twist3 = quats[3]==0 ? 0 : (quats[3]==7 ? 2:1);
167

    
168
    int c4 = MAP[0][quats[4]];
169
    int c5 = MAP[1][quats[5]];
170
    int c6 = MAP[2][quats[6]];
171
    int c7 = MAP[3][quats[7]];
172
    int c8 = MAP[4][quats[8]];
173
    int c9 = MAP[5][quats[9]];
174

    
175
    mTmp[c4]=0;
176
    mTmp[c5]=1;
177
    mTmp[c6]=2;
178
    mTmp[c7]=3;
179
    mTmp[c8]=4;
180
    mTmp[c9]=5;
181

    
182
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(mTmp);
183

    
184
    return perm_num + 360*(twist0+ 3*(twist1+ 3*(twist2+ 3*twist3)));
185
    }
186
}  
187

    
(6-6/8)