Project

General

Profile

« Previous | Next » 

Revision 4a5157a1

Added by Leszek Koltunski over 2 years ago

Rotations of a Cuboid - finished.

View differences:

src/main/java/org/distorted/objectlib/helpers/ScrambleState.java
25 25

  
26 26
public class ScrambleState
27 27
{
28
  private final int mTotal, mNumAxis;
28
  private final int mTotal, mNumAxis, mNumNonZero;
29 29
  private final int[] mNum;
30 30
  private final int[] mInfo;
31 31
  private final int[] mTmp;
......
39 39

  
40 40
    mNumAxis = axis.length;
41 41
    mNum = new int[mNumAxis];
42
    int total =0;
42
    int nonzero=0, total =0;
43 43

  
44 44
    for(int i=0; i<mNumAxis; i++)
45 45
      {
......
47 47
      total += mNum[i];
48 48
      }
49 49

  
50
    for(int i=0; i<mNumAxis; i++) if( mNum[i]>0 ) nonzero++;
51

  
52
    mNumNonZero = nonzero;
50 53
    mTotal = total;
51 54

  
52 55
    mInfo = new int[LEN*total];
......
84 87
    {
85 88
    int num=0, total=0, max=0, ax, layer;
86 89

  
90
    if( mNumNonZero<2 ) indexExcluded=-1;
91

  
87 92
    for(int i=0; i<mTotal; i++)
88 93
      {
89 94
      ax = mInfo[LEN*i];
src/main/java/org/distorted/objectlib/main/TwistyObjectScrambler.java
69 69
      }
70 70
    }
71 71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
74

  
75
  void initializeQuatMult()
76
    {
77
    mQuatMult = new int[][]
78
      {
79
        {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
80
        {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
81
        {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
82
        {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
83
        {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
84
        {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
85
        {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
86
        {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
87
        {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
88
        {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
89
        { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
90
        { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
91
        { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
92
        { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
93
        { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
94
        { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
95
        { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
96
        { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
97
        { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
98
        { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
99
        { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
100
        { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
101
        { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
102
        { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
103
      };
104
    }
105

  
106 72
///////////////////////////////////////////////////////////////////////////////////////////////////
107 73

  
108 74
  private void initializeScrambling()
......
155 121
    }
156 122

  
157 123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// TYPE 1
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

  
129
  void initializeQuatMult()
130
    {
131
    mQuatMult = new int[][]
132
      {
133
        {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
134
        {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
135
        {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
136
        {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
137
        {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
138
        {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
139
        {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
140
        {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
141
        {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
142
        {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
143
        { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
144
        { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
145
        { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
146
        { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
147
        { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
148
        { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
149
        { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
150
        { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
151
        { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
152
        { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
153
        { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
154
        { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
155
        { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
156
        { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
157
      };
158
    }
159

  
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
// TYPE 1
158 162

  
159 163
  private boolean cornerIsUp(int index)
160 164
    {
......
162 166
    }
163 167

  
164 168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
// TYPE 1
165 170

  
166 171
  private boolean cornerIsLeft(int index)
167 172
    {
......
183 188
    }
184 189

  
185 190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
// TYPE 1
186 192

  
187 193
  private boolean quatIsBad(int quatIndex, int corner)
188 194
    {
......
201 207
    }
202 208

  
203 209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
// TYPE 1
204 211

  
205 212
  private boolean isPermittedDo(int angle)
206 213
    {
......
220 227
    }
221 228

  
222 229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
// TYPE 1
223 231

  
224 232
  private boolean isPermittedUp(int angle)
225 233
    {
......
239 247
    }
240 248

  
241 249
///////////////////////////////////////////////////////////////////////////////////////////////////
250
// TYPE 1
242 251

  
243 252
  private void computePermittedAngles()
244 253
    {
......
258 267
    }
259 268

  
260 269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
// TYPE 1
261 271

  
262 272
  private int getNextAngle(Random rnd, int layer)
263 273
    {
......
268 278
    }
269 279

  
270 280
///////////////////////////////////////////////////////////////////////////////////////////////////
281
// TYPE 1
271 282

  
272 283
  private int getNextAngleNotZero(Random rnd, int layer)
273 284
    {
......
278 289
    }
279 290

  
280 291
///////////////////////////////////////////////////////////////////////////////////////////////////
292
// TYPE 1
281 293

  
282 294
  private int makeQuat(int axis,int index)
283 295
    {
......
287 299
    }
288 300

  
289 301
///////////////////////////////////////////////////////////////////////////////////////////////////
302
// TYPE 1
290 303

  
291 304
  private boolean cornerBelongs(int index, int axis, int layer)
292 305
    {
......
303 316
    }
304 317

  
305 318
///////////////////////////////////////////////////////////////////////////////////////////////////
319
// TYPE 1
306 320

  
307 321
  private void updateCornerQuats(int[] rotInfo)
308 322
    {
......
325 339
    }
326 340

  
327 341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
// TYPE 1
328 343

  
329 344
  private void randomizeNewScramble1(int[][] scramble, Random rnd, int curr, int total)
330 345
    {
src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
75 75

  
76 76
  private int[] createEdges(int size, boolean full, int vertex)
77 77
    {
78
    if( size==1 ) return null;
79

  
78 80
    if( full )
79 81
      {
80 82
      int[] ret = new int[9*size];
......
128 130
      int[][] mY = new int[16][];
129 131
      int[][] mZ = new int[16][];
130 132

  
131
      for(int i=1; i<16; i++) mX[i] = createEdges(X,Y==Z,i);
132
      for(int i=1; i<16; i++) mY[i] = createEdges(Y,X==Z,i);
133
      for(int i=1; i<16; i++) mZ[i] = createEdges(Z,X==Y,i);
133
      for(int i=0; i<16; i++)
134
        {
135
        mX[i] = createEdges(X,Y==Z,i);
136
        mY[i] = createEdges(Y,X==Z,i);
137
        mZ[i] = createEdges(Z,X==Y,i);
138
        }
134 139

  
135
      mStates = new ScrambleState[]
140
      if( X>1 && Y>1 && Z>1 )
136 141
        {
137
        new ScrambleState( new int[][] { mX[ 1], mY[ 2], mZ[ 3] } ),  //  0 0
138
        new ScrambleState( new int[][] {   null, mY[ 4], mZ[ 5] } ),  //  1 x
139
        new ScrambleState( new int[][] { mX[ 6],   null, mZ[ 7] } ),  //  2 y
140
        new ScrambleState( new int[][] { mX[ 8], mY[ 9],   null } ),  //  3 z
141
        new ScrambleState( new int[][] { mX[10],   null, mZ[ 7] } ),  //  4 xy
142
        new ScrambleState( new int[][] { mX[11], mY[ 9],   null } ),  //  5 xz
143
        new ScrambleState( new int[][] {   null, mY[12], mZ[ 5] } ),  //  6 yx
144
        new ScrambleState( new int[][] { mX[ 8], mY[13],   null } ),  //  7 yz
145
        new ScrambleState( new int[][] {   null, mY[ 4], mZ[14] } ),  //  8 zx
146
        new ScrambleState( new int[][] { mX[ 6],   null, mZ[15] } ),  //  9 zy
147
        new ScrambleState( new int[][] {   null,   null, mZ[ 5] } ),  // 10 xyx
148
        new ScrambleState( new int[][] {   null, mY[ 4],   null } ),  // 11 xzx
149
        new ScrambleState( new int[][] {   null,   null, mZ[ 7] } ),  // 12 yxy
150
        new ScrambleState( new int[][] { mX[ 6],   null,   null } ),  // 13 yzy
151
        new ScrambleState( new int[][] {   null, mY[ 9],   null } ),  // 14 zxz
152
        new ScrambleState( new int[][] { mX[ 8],   null,   null } ),  // 15 zyz
153
        };
142
        mStates = new ScrambleState[]
143
          {
144
          new ScrambleState( new int[][] { mX[ 1], mY[ 2], mZ[ 3] } ),  //  0 0
145
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[ 5] } ),  //  1 x
146
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[ 7] } ),  //  2 y
147
          new ScrambleState( new int[][] { mX[ 8], mY[ 9],   null } ),  //  3 z
148
          new ScrambleState( new int[][] { mX[10],   null, mZ[ 7] } ),  //  4 xy
149
          new ScrambleState( new int[][] { mX[11], mY[ 9],   null } ),  //  5 xz
150
          new ScrambleState( new int[][] {   null, mY[12], mZ[ 5] } ),  //  6 yx
151
          new ScrambleState( new int[][] { mX[ 8], mY[13],   null } ),  //  7 yz
152
          new ScrambleState( new int[][] {   null, mY[ 4], mZ[14] } ),  //  8 zx
153
          new ScrambleState( new int[][] { mX[ 6],   null, mZ[15] } ),  //  9 zy
154
          new ScrambleState( new int[][] {   null,   null, mZ[ 5] } ),  // 10 xyx
155
          new ScrambleState( new int[][] {   null, mY[ 4],   null } ),  // 11 xzx
156
          new ScrambleState( new int[][] {   null,   null, mZ[ 7] } ),  // 12 yxy
157
          new ScrambleState( new int[][] { mX[ 6],   null,   null } ),  // 13 yzy
158
          new ScrambleState( new int[][] {   null, mY[ 9],   null } ),  // 14 zxz
159
          new ScrambleState( new int[][] { mX[ 8],   null,   null } ),  // 15 zyz
160
          };
161
        }
162
      else if( X==1 && Y==1 && Z==1 )
163
        {
164
        int[] state = new int[] {0,-1,0,0,1,0,0,2,0};
165

  
166
        mStates = new ScrambleState[]
167
          {
168
          new ScrambleState( new int[][] { state, state, state } )
169
          };
170
        }
171
      else
172
        {
173
        mStates = new ScrambleState[]
174
          {
175
          new ScrambleState( new int[][] { mX[ 0], mY[ 0], mZ[ 0] } )
176
          };
177
        }
178

  
154 179
      }
155 180

  
156 181
    return mStates;

Also available in: Unified diff