Project

General

Profile

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

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

1 786cb5f5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 f9980f6a Leszek Koltunski
  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 786cb5f5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32
  public TablebasesIvyCube()
33
    {
34
    super();
35
    }
36
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39
  public TablebasesIvyCube(Resources res)
40
    {
41 f9980f6a Leszek Koltunski
    super(res,org.distorted.objectlib.R.raw.ivy_2_tablebase);
42 786cb5f5 Leszek Koltunski
    }
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 f9980f6a Leszek Koltunski
        {           0, DIST_CENTER,           0 },
75
        {           0,-DIST_CENTER,           0 },
76
        {           0,           0, DIST_CENTER },
77
        {           0,           0,-DIST_CENTER },
78 786cb5f5 Leszek Koltunski
      };
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 f9980f6a Leszek Koltunski
    boolean[] tmp1 = new boolean[] {false,true};
94
    boolean[] tmp2 = new boolean[] {true,false};
95
96
    return new boolean[][] { tmp1,tmp2,tmp2,tmp1 };
97 786cb5f5 Leszek Koltunski
    }
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 f9980f6a Leszek Koltunski
  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 786cb5f5 Leszek Koltunski
    {
125 f9980f6a Leszek Koltunski
    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 786cb5f5 Leszek Koltunski
    }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155 f9980f6a Leszek Koltunski
  public int getIndex(int[] quats)
156 786cb5f5 Leszek Koltunski
    {
157 f9980f6a Leszek Koltunski
    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 786cb5f5 Leszek Koltunski
    }
180
}