Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyBandaged3Plate.java @ e50d4668

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static4D;
28
import org.distorted.main.R;
29

    
30
import java.util.Random;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
class TwistyBandaged3Plate extends TwistyBandagedAbstract
35
{
36
  private int mCurrState;
37
  private boolean mUseX;
38
  private boolean mUseY;
39
  private boolean mUseZ;
40

    
41
  private static class State
42
    {
43
    private final int mNumX, mNumY, mNumZ;
44
    private final int[] mInfo;
45
    private final int[] mTmp;
46
    private final int LEN = 4;
47

    
48
    State(int[] x, int[] y, int[] z)
49
      {
50
      mTmp = new int[LEN];
51

    
52
      mNumX = x==null ? 0 : x.length/(LEN-1);
53
      mNumY = y==null ? 0 : y.length/(LEN-1);
54
      mNumZ = z==null ? 0 : z.length/(LEN-1);
55

    
56
      mInfo = new int[LEN*(mNumX+mNumY+mNumZ)];
57
      int start = 0;
58

    
59
      for(int i=0; i<mNumX; i++)
60
        {
61
        mInfo[LEN*i   + start] = 0;
62
        mInfo[LEN*i+1 + start] = x[(LEN-1)*i  ];
63
        mInfo[LEN*i+2 + start] = x[(LEN-1)*i+1];
64
        mInfo[LEN*i+3 + start] = x[(LEN-1)*i+2];
65
        }
66

    
67
      start = LEN*mNumX;
68

    
69
      for(int i=0; i<mNumY; i++)
70
        {
71
        mInfo[LEN*i   + start] = 1;
72
        mInfo[LEN*i+1 + start] = y[(LEN-1)*i  ];
73
        mInfo[LEN*i+2 + start] = y[(LEN-1)*i+1];
74
        mInfo[LEN*i+3 + start] = y[(LEN-1)*i+2];
75
        }
76

    
77
      start = LEN*(mNumX+mNumY);
78

    
79
      for(int i=0; i<mNumZ; i++)
80
        {
81
        mInfo[LEN*i   + start] = 2;
82
        mInfo[LEN*i+1 + start] = z[(LEN-1)*i  ];
83
        mInfo[LEN*i+2 + start] = z[(LEN-1)*i+1];
84
        mInfo[LEN*i+3 + start] = z[(LEN-1)*i+2];
85
        }
86
      }
87

    
88
    private int getIndex(int num, boolean useX, boolean useY, boolean useZ)
89
      {
90
      int current= -1, total= mNumX + mNumY + mNumZ;
91

    
92
      for(int i=0; i<total; i++)
93
        {
94
        if( (mInfo[LEN*i]==0 && useX) || (mInfo[LEN*i]==1 && useY) || (mInfo[LEN*i]==2 && useZ) )
95
          {
96
          if( ++current==num ) return i;
97
          }
98
        }
99

    
100
      return -1;
101
      }
102

    
103
    int getTotal(boolean useX, boolean useY, boolean useZ)
104
      {
105
      int total = 0;
106

    
107
      if( useX ) total += mNumX;
108
      if( useY ) total += mNumY;
109
      if( useZ ) total += mNumZ;
110

    
111
      return total;
112
      }
113

    
114
    int[] getInfo(int num, boolean useX, boolean useY, boolean useZ)
115
      {
116
      int index = getIndex(num,useX,useY,useZ);
117

    
118
      mTmp[0] = mInfo[LEN*index  ];   // axis
119
      mTmp[1] = mInfo[LEN*index+1];   // row
120
      mTmp[2] = mInfo[LEN*index+2];   // angle
121
      mTmp[3] = mInfo[LEN*index+3];   // next state
122

    
123
      return mTmp;
124
      }
125
    }
126

    
127
  // The 16 'significant' states of the 3Plate bandaged cube.
128
  // One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
129
  // rotations of the Cube are possible.
130
  // There are 27 such states in total, but 2 of them are unreachable from the initial State, and
131
  // 9 more and 'insignificant' - i.e. States which only permit rotation along a single axis.
132
  // When doing an automatic scramble, we never want to enter such 'insignificant' states because
133
  // that would mean we'd have to do two rotations in a row along the same axis.
134

    
135
  private final State[] mStates = new State[]
136
      {
137
         new State( new int[] { 2,-1, 1, 2, 1, 6                  }, new int[] { 0,-1, 5, 0, 1, 3                  }, new int[] { 2,-1, 2, 2, 1, 4                  } ),
138
         new State( new int[] { 2, 1, 0                           }, null                                           , new int[] { 2, 1,10, 2, 2, 7                  } ),
139
         new State( null                                           , new int[] { 0,-1,11, 0, 2, 8                  }, new int[] { 2, 1, 0                           } ),
140
         new State( new int[] { 2, 1,12, 2, 2, 9                  }, new int[] { 0,-1, 0                           }, null                                            ),
141
         new State( new int[] { 2,-1,10, 2, 2,13                  }, null                                           , new int[] { 2,-1, 0                           } ),
142
         new State( null                                           , new int[] { 0, 1, 0                           }, new int[] { 2,-1,11, 2, 2,14                  } ),
143
         new State( new int[] { 2,-1, 0                           }, new int[] { 0, 1,12, 0, 2,15                  }, null                                            ),
144
         new State( null                                           , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1                  } ),
145
         new State( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2                  }, null                                            ),
146
         new State( new int[] { 2,-1,12, 2, 2, 3                  }, null                                           , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
147
         new State( new int[] { 2,-1,13, 2, 1, 4                  }, new int[] { 2,-2,10, 2,-1,10, 2, 1,10, 2, 2,10}, new int[] { 2,-1, 1, 2, 1, 7                  } ),
148
         new State( new int[] { 0,-2,11, 0,-1,11, 0, 1,11, 0, 2,11}, new int[] { 0,-1, 8, 0, 1, 2                  }, new int[] { 2,-1,14, 2, 1, 5                  } ),
149
         new State( new int[] { 2,-1, 3, 2, 1, 9                  }, new int[] { 0,-1, 6, 0, 1,15                  }, new int[] { 0,-2,12, 0,-1,12, 0, 1,12, 0, 2,12} ),
150
         new State( new int[] { 2, 1,10, 2, 2, 4                  }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null                                            ),
151
         new State( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null                                           , new int[] { 2, 1,11, 2, 2, 5                  } ),
152
         new State( null                                           , new int[] { 0, 1,12, 0, 2, 6                  }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
153
      };
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
158
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
159
    {
160
    super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  int getCubitVariant(int cubit)
166
    {
167
    return cubit<=2 ? 3:0;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  int getNumCubits()
173
    {
174
    return 17;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  float[] getCubitPosition(int cubit)
180
    {
181
    switch(cubit)
182
      {
183
      case  0: return new float[] {-1.0f,  1.0f,  1.0f,
184
                                   -1.0f,  0.0f,  1.0f,
185
                                    0.0f,  1.0f,  1.0f,
186
                                    0.0f,  0.0f,  1.0f};
187
      case  1: return new float[] { 1.0f,  0.0f, -1.0f,
188
                                    1.0f,  0.0f,  0.0f,
189
                                    1.0f,  1.0f, -1.0f,
190
                                    1.0f,  1.0f,  0.0f};
191
      case  2: return new float[] {-1.0f, -1.0f, -1.0f,
192
                                   -1.0f, -1.0f,  0.0f,
193
                                    0.0f, -1.0f, -1.0f,
194
                                    0.0f, -1.0f,  0.0f};
195
      case  3: return new float[] { 1.0f,  1.0f,  1.0f};
196
      case  4: return new float[] { 1.0f,  0.0f,  1.0f};
197
      case  5: return new float[] { 1.0f, -1.0f,  1.0f};
198
      case  6: return new float[] {-1.0f, -1.0f,  1.0f};
199
      case  7: return new float[] { 0.0f, -1.0f,  1.0f};
200
      case  8: return new float[] { 1.0f, -1.0f,  0.0f};
201
      case  9: return new float[] { 1.0f, -1.0f, -1.0f};
202
      case 10: return new float[] {-1.0f,  1.0f, -1.0f};
203
      case 11: return new float[] {-1.0f,  1.0f,  0.0f};
204
      case 12: return new float[] { 0.0f,  1.0f, -1.0f};
205
      case 13: return new float[] { 0.0f,  1.0f,  0.0f};
206
      case 14: return new float[] {-1.0f,  0.0f, -1.0f};
207
      case 15: return new float[] {-1.0f,  0.0f,  0.0f};
208
      case 16: return new float[] { 0.0f,  0.0f, -1.0f};
209
      }
210

    
211
    return null;
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  int getQuatIndex(int cubit)
217
    {
218
    switch(cubit)
219
      {
220
      case 0: return 1;
221
      case 1: return 3;
222
      }
223

    
224
    return 0;
225
    }
226

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
// PUBLIC API
229

    
230
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
231
    {
232
    if( num==0 )
233
      {
234
      mCurrState = 0;
235
      mUseX = true;
236
      mUseY = true;
237
      mUseZ = true;
238
      }
239

    
240
    int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ);
241
    int random= rnd.nextInt(total);
242
    int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ);
243

    
244
    scramble[num][0] = info[0];
245
    scramble[num][1] = info[1];
246
    scramble[num][2] = info[2];
247

    
248
    mCurrState = info[3];
249

    
250
    switch(info[0])
251
      {
252
      case 0: mUseX = false; mUseY = true ; mUseZ = true ; break;
253
      case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
254
      case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
255
      }
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  public int getObjectName(int numLayers)
261
    {
262
    return R.string.bandaged_3plate;
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  public int getInventor(int numLayers)
268
    {
269
    return R.string.bandaged_3plate_inventor;
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
  public int getComplexity(int numLayers)
275
    {
276
    return 8;
277
    }
278
}
(17-17/35)