Project

General

Profile

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

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

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 org.distorted.objectlib.objects.TwistyIvy;
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 TwistyIvy.ROT_AXIS;
57
    }
58

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

    
61
  float[][] getPosition()
62
    {
63
    final float DIST_CORNER = 1;
64
    final float DIST_CENTER = 1;
65

    
66
    return new float[][]
67
      {
68
        { DIST_CORNER, DIST_CORNER, DIST_CORNER },
69
        {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
70
        {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
71
        { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
72
        { DIST_CENTER,           0,           0 },
73
        {-DIST_CENTER,           0,           0 },
74
        {           0, DIST_CENTER,           0 },
75
        {           0,-DIST_CENTER,           0 },
76
        {           0,           0, DIST_CENTER },
77
        {           0,           0,-DIST_CENTER },
78
      };
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  float[][] getCuts()
84
    {
85
    float[] cut = { 0.0f };
86
    return new float[][] { cut,cut,cut,cut };
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  boolean[][] getRotatable()
92
    {
93
    boolean[] tmp1 = new boolean[] {false,true};
94
    boolean[] tmp2 = new boolean[] {true,false};
95

    
96
    return new boolean[][] { tmp1,tmp2,tmp2,tmp1 };
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// specifically for the tablebase
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
// orientations of 4 corners + any even permutation of 6 centers
103

    
104
  int getSize()
105
    {
106
    return (3*3*3*3)*(6*5*4*3);
107
    }
108

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

    
111
  private int findFirst(int[] table, int value)
112
    {
113
    int len = table.length;
114

    
115
    for(int i=0; i<len; i++)
116
      if( table[i]==value ) return i;
117

    
118
    return -1;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public int[] getQuats(int index)
124
    {
125
    int perm_num = index%360;
126
    index /= 360;
127
    int twist0 = index%3;
128
    index /= 3;
129
    int twist1 = index%3;
130
    index /= 3;
131
    int twist2 = index%3;
132
    index /= 3;
133
    int twist3 = index%3;
134

    
135
    int[] ret = new int[10];
136

    
137
    ret[0] = twist0==0 ? 0 : (twist0==1 ? 2:1);
138
    ret[1] = twist1==0 ? 0 : (twist1==1 ? 5:6);
139
    ret[2] = twist2==0 ? 0 : (twist2==1 ? 3:4);
140
    ret[3] = twist3==0 ? 0 : (twist3==1 ? 8:7);
141

    
142
    TablebaseHelpers.getEvenPermutationFromNum(mTmp,6,perm_num);
143

    
144
    for(int i=0; i<6; i++)
145
      {
146
      int cubitThatMoves = mTmp[i];
147
      ret[cubitThatMoves+4] = findFirst(MAP[cubitThatMoves],i);
148
      }
149

    
150
    return ret;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public int getIndex(int[] quats)
156
    {
157
    int twist0 = quats[0]==0 ? 0 : (quats[0]==1 ? 2:1);
158
    int twist1 = quats[1]==0 ? 0 : (quats[1]==6 ? 2:1);
159
    int twist2 = quats[2]==0 ? 0 : (quats[2]==4 ? 2:1);
160
    int twist3 = quats[3]==0 ? 0 : (quats[3]==7 ? 2:1);
161

    
162
    int c4 = MAP[0][quats[4]];
163
    int c5 = MAP[1][quats[5]];
164
    int c6 = MAP[2][quats[6]];
165
    int c7 = MAP[3][quats[7]];
166
    int c8 = MAP[4][quats[8]];
167
    int c9 = MAP[5][quats[9]];
168

    
169
    mTmp[c4]=0;
170
    mTmp[c5]=1;
171
    mTmp[c6]=2;
172
    mTmp[c7]=3;
173
    mTmp[c8]=4;
174
    mTmp[c9]=5;
175

    
176
    int perm_num = TablebaseHelpers.computeEvenPermutationNum(mTmp);
177

    
178
    return perm_num + 360*(twist0+ 3*(twist1+ 3*(twist2+ 3*twist3)));
179
    }
180
}  
181

    
(6-6/7)