1 |
538ee7a6
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
eff371f4
|
Leszek Koltunski
|
import java.util.Random;
|
31 |
|
|
|
32 |
538ee7a6
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
class TwistyBandaged3Plate extends TwistyBandagedAbstract
|
35 |
|
|
{
|
36 |
e50d4668
|
Leszek Koltunski
|
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 |
69341f31
|
Leszek Koltunski
|
//
|
135 |
|
|
// 4th State's first ('x') array being '2,-1,10, 2, 2,13' means the following:
|
136 |
|
|
// if we are in the 4th state, and make move (2,-1) [i.e. rotation along the X axis, 2nd row, -1 angle]
|
137 |
|
|
// then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other
|
138 |
|
|
// 'x' moves that lead to a 'significant' state.
|
139 |
e50d4668
|
Leszek Koltunski
|
|
140 |
|
|
private final State[] mStates = new State[]
|
141 |
|
|
{
|
142 |
|
|
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 } ),
|
143 |
|
|
new State( new int[] { 2, 1, 0 }, null , new int[] { 2, 1,10, 2, 2, 7 } ),
|
144 |
|
|
new State( null , new int[] { 0,-1,11, 0, 2, 8 }, new int[] { 2, 1, 0 } ),
|
145 |
|
|
new State( new int[] { 2, 1,12, 2, 2, 9 }, new int[] { 0,-1, 0 }, null ),
|
146 |
|
|
new State( new int[] { 2,-1,10, 2, 2,13 }, null , new int[] { 2,-1, 0 } ),
|
147 |
|
|
new State( null , new int[] { 0, 1, 0 }, new int[] { 2,-1,11, 2, 2,14 } ),
|
148 |
|
|
new State( new int[] { 2,-1, 0 }, new int[] { 0, 1,12, 0, 2,15 }, null ),
|
149 |
|
|
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 } ),
|
150 |
|
|
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 ),
|
151 |
|
|
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} ),
|
152 |
|
|
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 } ),
|
153 |
|
|
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 } ),
|
154 |
|
|
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} ),
|
155 |
|
|
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 ),
|
156 |
|
|
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 } ),
|
157 |
|
|
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} )
|
158 |
|
|
};
|
159 |
|
|
|
160 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161 |
|
|
|
162 |
538ee7a6
|
Leszek Koltunski
|
TwistyBandaged3Plate(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
163 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
164 |
|
|
{
|
165 |
42fe3bad
|
Leszek Koltunski
|
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth);
|
166 |
538ee7a6
|
Leszek Koltunski
|
}
|
167 |
|
|
|
168 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
|
|
|
170 |
|
|
int getCubitVariant(int cubit)
|
171 |
|
|
{
|
172 |
|
|
return cubit<=2 ? 3:0;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
|
|
int getNumCubits()
|
178 |
|
|
{
|
179 |
|
|
return 17;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183 |
|
|
|
184 |
|
|
float[] getCubitPosition(int cubit)
|
185 |
|
|
{
|
186 |
|
|
switch(cubit)
|
187 |
|
|
{
|
188 |
92ec91b9
|
Leszek Koltunski
|
case 0: return new float[] {-1.0f, 1.0f, 1.0f,
|
189 |
|
|
-1.0f, 0.0f, 1.0f,
|
190 |
|
|
0.0f, 1.0f, 1.0f,
|
191 |
|
|
0.0f, 0.0f, 1.0f};
|
192 |
|
|
case 1: return new float[] { 1.0f, 0.0f, -1.0f,
|
193 |
|
|
1.0f, 0.0f, 0.0f,
|
194 |
|
|
1.0f, 1.0f, -1.0f,
|
195 |
|
|
1.0f, 1.0f, 0.0f};
|
196 |
|
|
case 2: return new float[] {-1.0f, -1.0f, -1.0f,
|
197 |
|
|
-1.0f, -1.0f, 0.0f,
|
198 |
|
|
0.0f, -1.0f, -1.0f,
|
199 |
|
|
0.0f, -1.0f, 0.0f};
|
200 |
538ee7a6
|
Leszek Koltunski
|
case 3: return new float[] { 1.0f, 1.0f, 1.0f};
|
201 |
|
|
case 4: return new float[] { 1.0f, 0.0f, 1.0f};
|
202 |
|
|
case 5: return new float[] { 1.0f, -1.0f, 1.0f};
|
203 |
|
|
case 6: return new float[] {-1.0f, -1.0f, 1.0f};
|
204 |
|
|
case 7: return new float[] { 0.0f, -1.0f, 1.0f};
|
205 |
|
|
case 8: return new float[] { 1.0f, -1.0f, 0.0f};
|
206 |
|
|
case 9: return new float[] { 1.0f, -1.0f, -1.0f};
|
207 |
|
|
case 10: return new float[] {-1.0f, 1.0f, -1.0f};
|
208 |
|
|
case 11: return new float[] {-1.0f, 1.0f, 0.0f};
|
209 |
|
|
case 12: return new float[] { 0.0f, 1.0f, -1.0f};
|
210 |
|
|
case 13: return new float[] { 0.0f, 1.0f, 0.0f};
|
211 |
|
|
case 14: return new float[] {-1.0f, 0.0f, -1.0f};
|
212 |
|
|
case 15: return new float[] {-1.0f, 0.0f, 0.0f};
|
213 |
|
|
case 16: return new float[] { 0.0f, 0.0f, -1.0f};
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
return null;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220 |
|
|
|
221 |
|
|
int getQuatIndex(int cubit)
|
222 |
|
|
{
|
223 |
|
|
switch(cubit)
|
224 |
|
|
{
|
225 |
|
|
case 0: return 1;
|
226 |
|
|
case 1: return 3;
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
return 0;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233 |
|
|
// PUBLIC API
|
234 |
eff371f4
|
Leszek Koltunski
|
|
235 |
5043d5d0
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
|
236 |
bbc6471c
|
Leszek Koltunski
|
{
|
237 |
5043d5d0
|
Leszek Koltunski
|
if( num==0 )
|
238 |
eff371f4
|
Leszek Koltunski
|
{
|
239 |
e50d4668
|
Leszek Koltunski
|
mCurrState = 0;
|
240 |
|
|
mUseX = true;
|
241 |
|
|
mUseY = true;
|
242 |
|
|
mUseZ = true;
|
243 |
eff371f4
|
Leszek Koltunski
|
}
|
244 |
|
|
|
245 |
e50d4668
|
Leszek Koltunski
|
int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ);
|
246 |
|
|
int random= rnd.nextInt(total);
|
247 |
|
|
int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ);
|
248 |
eff371f4
|
Leszek Koltunski
|
|
249 |
e50d4668
|
Leszek Koltunski
|
scramble[num][0] = info[0];
|
250 |
|
|
scramble[num][1] = info[1];
|
251 |
|
|
scramble[num][2] = info[2];
|
252 |
|
|
|
253 |
|
|
mCurrState = info[3];
|
254 |
eff371f4
|
Leszek Koltunski
|
|
255 |
e50d4668
|
Leszek Koltunski
|
switch(info[0])
|
256 |
5043d5d0
|
Leszek Koltunski
|
{
|
257 |
e50d4668
|
Leszek Koltunski
|
case 0: mUseX = false; mUseY = true ; mUseZ = true ; break;
|
258 |
|
|
case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
|
259 |
|
|
case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
|
260 |
5043d5d0
|
Leszek Koltunski
|
}
|
261 |
eff371f4
|
Leszek Koltunski
|
}
|
262 |
|
|
|
263 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264 |
538ee7a6
|
Leszek Koltunski
|
|
265 |
|
|
public int getObjectName(int numLayers)
|
266 |
|
|
{
|
267 |
|
|
return R.string.bandaged_3plate;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
|
|
|
272 |
|
|
public int getInventor(int numLayers)
|
273 |
|
|
{
|
274 |
|
|
return R.string.bandaged_3plate_inventor;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
|
279 |
|
|
public int getComplexity(int numLayers)
|
280 |
|
|
{
|
281 |
|
|
return 8;
|
282 |
|
|
}
|
283 |
|
|
}
|