1 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
0c52af30
|
Leszek Koltunski
|
// //
|
6 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
0c52af30
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
0c52af30
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.objects;
|
21 |
0c52af30
|
Leszek Koltunski
|
|
22 |
ccf9fec5
|
Leszek Koltunski
|
import android.content.res.Resources;
|
23 |
0c52af30
|
Leszek Koltunski
|
import android.graphics.Canvas;
|
24 |
|
|
import android.graphics.Paint;
|
25 |
|
|
|
26 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
27 |
|
|
import org.distorted.helpers.FactorySticker;
|
28 |
0c52af30
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
29 |
|
|
import org.distorted.library.main.DistortedTexture;
|
30 |
b32444ee
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
31 |
efa8aa48
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshSquare;
|
32 |
0c52af30
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
33 |
|
|
import org.distorted.library.type.Static4D;
|
34 |
6fd4a72c
|
Leszek Koltunski
|
import org.distorted.main.R;
|
35 |
0c52af30
|
Leszek Koltunski
|
|
36 |
7c969a6d
|
Leszek Koltunski
|
import java.util.Random;
|
37 |
|
|
|
38 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
9c2f0c91
|
Leszek Koltunski
|
class TwistyCube extends TwistyObject
|
41 |
0c52af30
|
Leszek Koltunski
|
{
|
42 |
e844c116
|
Leszek Koltunski
|
// the three rotation axis of a RubikCube. Must be normalized.
|
43 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
44 |
efef689c
|
Leszek Koltunski
|
{
|
45 |
|
|
new Static3D(1,0,0),
|
46 |
|
|
new Static3D(0,1,0),
|
47 |
|
|
new Static3D(0,0,1)
|
48 |
|
|
};
|
49 |
|
|
|
50 |
925ed78f
|
Leszek Koltunski
|
private static final int[] BASIC_ANGLE = new int[] { 4,4,4 };
|
51 |
|
|
|
52 |
37a25788
|
Leszek Koltunski
|
private static final int[] FACE_COLORS = new int[]
|
53 |
efef689c
|
Leszek Koltunski
|
{
|
54 |
ece1b58d
|
Leszek Koltunski
|
COLOR_YELLOW, COLOR_WHITE,
|
55 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
56 |
323b217c
|
Leszek Koltunski
|
COLOR_RED , COLOR_ORANGE
|
57 |
efef689c
|
Leszek Koltunski
|
};
|
58 |
|
|
|
59 |
10585385
|
Leszek Koltunski
|
// All legal rotation quats of a RubikCube of any size.
|
60 |
efef689c
|
Leszek Koltunski
|
// Here's how to compute this:
|
61 |
|
|
// 1) compute how many rotations there are (RubikCube of any size = 24)
|
62 |
|
|
// 2) take the AXIS, angles of rotation (90 in RubikCube's case) compute the basic quaternions
|
63 |
|
|
// (i.e. rotations of 1 basic angle along each of the axis) and from there start semi-randomly
|
64 |
|
|
// multiplying them and eventually you'll find all (24) legal rotations.
|
65 |
9f4c44fe
|
Leszek Koltunski
|
// Example program in C, res/raw/compute_quats.c , is included.
|
66 |
10585385
|
Leszek Koltunski
|
private static final Static4D[] QUATS = new Static4D[]
|
67 |
efef689c
|
Leszek Koltunski
|
{
|
68 |
10585385
|
Leszek Koltunski
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
69 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f),
|
70 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f),
|
71 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f),
|
72 |
|
|
|
73 |
|
|
new Static4D( SQ2/2, SQ2/2, 0.0f , 0.0f),
|
74 |
|
|
new Static4D( SQ2/2, -SQ2/2, 0.0f , 0.0f),
|
75 |
|
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f),
|
76 |
|
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f),
|
77 |
|
|
new Static4D( SQ2/2, 0.0f, 0.0f, SQ2/2),
|
78 |
|
|
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2),
|
79 |
|
|
new Static4D( 0.0f, SQ2/2, SQ2/2, 0.0f),
|
80 |
|
|
new Static4D( 0.0f, SQ2/2, -SQ2/2, 0.0f),
|
81 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2),
|
82 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2),
|
83 |
|
|
new Static4D( 0.0f, 0.0f, SQ2/2, SQ2/2),
|
84 |
|
|
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2),
|
85 |
|
|
|
86 |
|
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f),
|
87 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f),
|
88 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f),
|
89 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f),
|
90 |
|
|
new Static4D( -0.5f, -0.5f, -0.5f, 0.5f),
|
91 |
|
|
new Static4D( -0.5f, 0.5f, -0.5f, -0.5f),
|
92 |
|
|
new Static4D( -0.5f, 0.5f, 0.5f, -0.5f),
|
93 |
|
|
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f)
|
94 |
efef689c
|
Leszek Koltunski
|
};
|
95 |
411c6285
|
Leszek Koltunski
|
|
96 |
b1f2ccf5
|
Leszek Koltunski
|
private static final double[][] VERTICES = new double[][]
|
97 |
|
|
{
|
98 |
|
|
{ 0.5, 0.5, 0.5 },
|
99 |
|
|
{ 0.5, 0.5,-0.5 },
|
100 |
|
|
{ 0.5,-0.5, 0.5 },
|
101 |
|
|
{ 0.5,-0.5,-0.5 },
|
102 |
|
|
{-0.5, 0.5, 0.5 },
|
103 |
|
|
{-0.5, 0.5,-0.5 },
|
104 |
|
|
{-0.5,-0.5, 0.5 },
|
105 |
|
|
{-0.5,-0.5,-0.5 },
|
106 |
|
|
};
|
107 |
|
|
|
108 |
|
|
private static final int[][] VERT_INDEXES = new int[][]
|
109 |
|
|
{
|
110 |
|
|
{2,3,1,0}, // counterclockwise!
|
111 |
|
|
{7,6,4,5},
|
112 |
|
|
{4,0,1,5},
|
113 |
|
|
{7,3,2,6},
|
114 |
|
|
{6,2,0,4},
|
115 |
|
|
{3,7,5,1}
|
116 |
|
|
};
|
117 |
|
|
|
118 |
|
|
private static final float[][] STICKERS = new float[][]
|
119 |
|
|
{
|
120 |
|
|
{ -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f }
|
121 |
|
|
};
|
122 |
|
|
|
123 |
fbca0033
|
Leszek Koltunski
|
private static MeshBase[] mMeshes;
|
124 |
40ab026e
|
Leszek Koltunski
|
|
125 |
411c6285
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126 |
|
|
|
127 |
9c2f0c91
|
Leszek Koltunski
|
TwistyCube(int size, Static4D quat, DistortedTexture texture,
|
128 |
|
|
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
129 |
411c6285
|
Leszek Koltunski
|
{
|
130 |
db875721
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.CUBE, res, scrWidth);
|
131 |
411c6285
|
Leszek Koltunski
|
}
|
132 |
|
|
|
133 |
ac940e24
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
136 |
ac940e24
|
Leszek Koltunski
|
{
|
137 |
|
|
if( mMeshes==null )
|
138 |
|
|
{
|
139 |
b1f2ccf5
|
Leszek Koltunski
|
FactoryCubit factory = FactoryCubit.getInstance();
|
140 |
|
|
factory.clear();
|
141 |
ac940e24
|
Leszek Koltunski
|
mMeshes = new MeshBase[ObjectList.CUBE.getNumVariants()];
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
int ordinal= ObjectList.CUBE.ordinal();
|
145 |
d99f3a48
|
Leszek Koltunski
|
int index = ObjectList.getSizeIndex(ordinal,getNumLayers());
|
146 |
ac940e24
|
Leszek Koltunski
|
|
147 |
|
|
if( mMeshes[index]==null )
|
148 |
|
|
{
|
149 |
b1f2ccf5
|
Leszek Koltunski
|
int extraI, extraV, num;
|
150 |
67b2d57b
|
Leszek Koltunski
|
float height;
|
151 |
b1f2ccf5
|
Leszek Koltunski
|
|
152 |
|
|
switch(numLayers)
|
153 |
|
|
{
|
154 |
67b2d57b
|
Leszek Koltunski
|
case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
|
155 |
|
|
case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
|
156 |
|
|
case 4 : num = 5; extraI = 1; extraV = 1; height = 0.045f; break;
|
157 |
|
|
default: num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
|
158 |
b1f2ccf5
|
Leszek Koltunski
|
}
|
159 |
|
|
|
160 |
67b2d57b
|
Leszek Koltunski
|
float[][] bands = new float[][] { {height,35,0.5f,0.7f,num,extraI,extraV} };
|
161 |
b1f2ccf5
|
Leszek Koltunski
|
int[] bandIndexes = new int[] { 0,0,0,0,0,0};
|
162 |
|
|
float[][] corners = new float[][] { {0.036f,0.12f} };
|
163 |
|
|
int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
164 |
b3c9061a
|
Leszek Koltunski
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
165 |
|
|
int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
166 |
b1f2ccf5
|
Leszek Koltunski
|
|
167 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
168 |
|
|
|
169 |
|
|
factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
|
170 |
|
|
mMeshes[index] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
|
171 |
|
|
bands, bandIndexes,
|
172 |
|
|
corners, cornerIndexes,
|
173 |
b3c9061a
|
Leszek Koltunski
|
centers, centerIndexes,
|
174 |
b1f2ccf5
|
Leszek Koltunski
|
getNumCubitFaces() );
|
175 |
ac940e24
|
Leszek Koltunski
|
}
|
176 |
|
|
|
177 |
|
|
return mMeshes[index].copy(true);
|
178 |
|
|
}
|
179 |
|
|
|
180 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181 |
|
|
|
182 |
ae755eda
|
Leszek Koltunski
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
183 |
7289fd6c
|
Leszek Koltunski
|
{
|
184 |
76c2bd07
|
Leszek Koltunski
|
float R = 0.10f;
|
185 |
2fcfce81
|
Leszek Koltunski
|
float S = 0.08f;
|
186 |
7289fd6c
|
Leszek Koltunski
|
|
187 |
b89898c5
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
188 |
b1f2ccf5
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
189 |
7289fd6c
|
Leszek Koltunski
|
}
|
190 |
|
|
|
191 |
411c6285
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192 |
|
|
|
193 |
b1f2ccf5
|
Leszek Koltunski
|
float[][] getCubitPositions(int numLayers)
|
194 |
a10ada2a
|
Leszek Koltunski
|
{
|
195 |
b1f2ccf5
|
Leszek Koltunski
|
int numCubits = numLayers>1 ? 6*numLayers*numLayers - 12*numLayers + 8 : 1;
|
196 |
e6cf7283
|
Leszek Koltunski
|
float[][] tmp = new float[numCubits][];
|
197 |
beb325a0
|
Leszek Koltunski
|
|
198 |
b1f2ccf5
|
Leszek Koltunski
|
float diff = 0.5f*(numLayers-1);
|
199 |
a10ada2a
|
Leszek Koltunski
|
int currentPosition = 0;
|
200 |
beb325a0
|
Leszek Koltunski
|
|
201 |
b1f2ccf5
|
Leszek Koltunski
|
for(int x = 0; x<numLayers; x++)
|
202 |
|
|
for(int y = 0; y<numLayers; y++)
|
203 |
|
|
for(int z = 0; z<numLayers; z++)
|
204 |
|
|
if( x==0 || x==numLayers-1 || y==0 || y==numLayers-1 || z==0 || z==numLayers-1 )
|
205 |
beb325a0
|
Leszek Koltunski
|
{
|
206 |
e6cf7283
|
Leszek Koltunski
|
tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
|
207 |
a10ada2a
|
Leszek Koltunski
|
}
|
208 |
47ba5ddc
|
Leszek Koltunski
|
|
209 |
a10ada2a
|
Leszek Koltunski
|
return tmp;
|
210 |
|
|
}
|
211 |
47ba5ddc
|
Leszek Koltunski
|
|
212 |
beb325a0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
|
214 |
10585385
|
Leszek Koltunski
|
Static4D[] getQuats()
|
215 |
a10ada2a
|
Leszek Koltunski
|
{
|
216 |
10585385
|
Leszek Koltunski
|
return QUATS;
|
217 |
a10ada2a
|
Leszek Koltunski
|
}
|
218 |
47ba5ddc
|
Leszek Koltunski
|
|
219 |
eaee1ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220 |
|
|
|
221 |
|
|
boolean shouldResetTextureMaps()
|
222 |
|
|
{
|
223 |
|
|
return false;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
47ba5ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227 |
|
|
|
228 |
411c6285
|
Leszek Koltunski
|
int getNumFaces()
|
229 |
a10ada2a
|
Leszek Koltunski
|
{
|
230 |
411c6285
|
Leszek Koltunski
|
return FACE_COLORS.length;
|
231 |
8f53e513
|
Leszek Koltunski
|
}
|
232 |
|
|
|
233 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234 |
|
|
|
235 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int numLayers)
|
236 |
7403cdfa
|
Leszek Koltunski
|
{
|
237 |
e6734aa9
|
Leszek Koltunski
|
float[][] cuts = new float[3][numLayers-1];
|
238 |
a97e02b7
|
Leszek Koltunski
|
|
239 |
a64e07d0
|
Leszek Koltunski
|
for(int i=0; i<numLayers-1; i++)
|
240 |
a97e02b7
|
Leszek Koltunski
|
{
|
241 |
e6734aa9
|
Leszek Koltunski
|
float cut = (2-numLayers)*0.5f + i;
|
242 |
|
|
cuts[0][i] = cut;
|
243 |
|
|
cuts[1][i] = cut;
|
244 |
|
|
cuts[2][i] = cut;
|
245 |
a97e02b7
|
Leszek Koltunski
|
}
|
246 |
|
|
|
247 |
|
|
return cuts;
|
248 |
7403cdfa
|
Leszek Koltunski
|
}
|
249 |
|
|
|
250 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251 |
|
|
|
252 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
253 |
eab9d8f8
|
Leszek Koltunski
|
{
|
254 |
b1f2ccf5
|
Leszek Koltunski
|
return STICKERS.length;
|
255 |
eab9d8f8
|
Leszek Koltunski
|
}
|
256 |
|
|
|
257 |
8f53e513
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
258 |
|
|
|
259 |
|
|
int getNumCubitFaces()
|
260 |
|
|
{
|
261 |
|
|
return FACE_COLORS.length;
|
262 |
411c6285
|
Leszek Koltunski
|
}
|
263 |
47ba5ddc
|
Leszek Koltunski
|
|
264 |
f0fa83ae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
265 |
|
|
|
266 |
|
|
float getScreenRatio()
|
267 |
|
|
{
|
268 |
|
|
return 0.5f;
|
269 |
|
|
}
|
270 |
|
|
|
271 |
f6d06256
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
272 |
|
|
|
273 |
|
|
int getFaceColor(int cubit, int cubitface, int size)
|
274 |
|
|
{
|
275 |
2ef489e2
|
Leszek Koltunski
|
return CUBITS[cubit].mRotationRow[cubitface/2] == (cubitface%2==0 ? (1<<(size-1)):1) ? cubitface : NUM_FACES;
|
276 |
f6d06256
|
Leszek Koltunski
|
}
|
277 |
|
|
|
278 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
|
280 |
|
|
float returnMultiplier()
|
281 |
|
|
{
|
282 |
d99f3a48
|
Leszek Koltunski
|
return getNumLayers();
|
283 |
fb377dae
|
Leszek Koltunski
|
}
|
284 |
|
|
|
285 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
286 |
|
|
// PUBLIC API
|
287 |
|
|
|
288 |
12ad3fca
|
Leszek Koltunski
|
public Static3D[] getRotationAxis()
|
289 |
|
|
{
|
290 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
291 |
12ad3fca
|
Leszek Koltunski
|
}
|
292 |
|
|
|
293 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
294 |
|
|
|
295 |
925ed78f
|
Leszek Koltunski
|
public int[] getBasicAngle()
|
296 |
e844c116
|
Leszek Koltunski
|
{
|
297 |
925ed78f
|
Leszek Koltunski
|
return BASIC_ANGLE;
|
298 |
e844c116
|
Leszek Koltunski
|
}
|
299 |
39e74052
|
Leszek Koltunski
|
|
300 |
7c969a6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
301 |
|
|
|
302 |
9f171eba
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
303 |
7c969a6d
|
Leszek Koltunski
|
{
|
304 |
9f171eba
|
Leszek Koltunski
|
if( curr==0 )
|
305 |
5cf34c5f
|
Leszek Koltunski
|
{
|
306 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
307 |
7c969a6d
|
Leszek Koltunski
|
}
|
308 |
|
|
else
|
309 |
|
|
{
|
310 |
8e6dc249
|
Leszek Koltunski
|
int newVector = rnd.nextInt(NUM_AXIS-1);
|
311 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
|
312 |
8e6dc249
|
Leszek Koltunski
|
|
313 |
|
|
// All three axis must be present among every four consecutive rotations.
|
314 |
|
|
// Otherwise in case of odd-sized cubes we can get four consecutive rotations
|
315 |
|
|
// that collapse to a NOP
|
316 |
|
|
// (X,midLayer,180)->(Y,midLayer,180)->(X,midLayer,180)->(Y,midLayer,180) = NOP
|
317 |
|
|
if( curr>=3 && scramble[curr-1][0]==scramble[curr-3][0] )
|
318 |
|
|
{
|
319 |
|
|
for( int ax=0; ax<NUM_AXIS; ax++)
|
320 |
|
|
{
|
321 |
|
|
if( scramble[curr-1][0]!=ax && scramble[curr-2][0]!=ax )
|
322 |
|
|
{
|
323 |
|
|
scramble[curr][0] = ax;
|
324 |
|
|
break;
|
325 |
|
|
}
|
326 |
|
|
}
|
327 |
|
|
}
|
328 |
5cf34c5f
|
Leszek Koltunski
|
}
|
329 |
|
|
|
330 |
7c969a6d
|
Leszek Koltunski
|
float rowFloat = rnd.nextFloat();
|
331 |
0203be88
|
Leszek Koltunski
|
int numLayers = getNumLayers();
|
332 |
7c969a6d
|
Leszek Koltunski
|
|
333 |
0203be88
|
Leszek Koltunski
|
for(int row=0; row<numLayers; row++)
|
334 |
7c969a6d
|
Leszek Koltunski
|
{
|
335 |
0203be88
|
Leszek Koltunski
|
if( rowFloat*numLayers <= row+1 )
|
336 |
bbc6471c
|
Leszek Koltunski
|
{
|
337 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][1] = row;
|
338 |
bbc6471c
|
Leszek Koltunski
|
break;
|
339 |
|
|
}
|
340 |
7c969a6d
|
Leszek Koltunski
|
}
|
341 |
|
|
|
342 |
5043d5d0
|
Leszek Koltunski
|
switch( rnd.nextInt(4) )
|
343 |
|
|
{
|
344 |
9f171eba
|
Leszek Koltunski
|
case 0: scramble[curr][2] = -2; break;
|
345 |
|
|
case 1: scramble[curr][2] = -1; break;
|
346 |
|
|
case 2: scramble[curr][2] = 1; break;
|
347 |
|
|
case 3: scramble[curr][2] = 2; break;
|
348 |
5043d5d0
|
Leszek Koltunski
|
}
|
349 |
e46e17fb
|
Leszek Koltunski
|
}
|
350 |
f0336037
|
Leszek Koltunski
|
|
351 |
6b6504fe
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352 |
|
|
|
353 |
|
|
public boolean isSolved()
|
354 |
|
|
{
|
355 |
|
|
int index = CUBITS[0].mQuatIndex;
|
356 |
|
|
|
357 |
|
|
for(int i=1; i<NUM_CUBITS; i++)
|
358 |
|
|
{
|
359 |
722b2512
|
Leszek Koltunski
|
if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
|
360 |
6b6504fe
|
Leszek Koltunski
|
}
|
361 |
|
|
|
362 |
|
|
return true;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
f0336037
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366 |
a304ee64
|
Leszek Koltunski
|
// order: Up --> Right --> Front --> Down --> Left --> Back
|
367 |
|
|
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)
|
368 |
|
|
//
|
369 |
fa0f7a56
|
Leszek Koltunski
|
// Solved 3x3x3 Cube maps to "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"
|
370 |
a304ee64
|
Leszek Koltunski
|
//
|
371 |
fa0f7a56
|
Leszek Koltunski
|
// s : size of the cube; let index = a*s + b (i.e. a,b = row,column)
|
372 |
|
|
//
|
373 |
|
|
// Up : index --> b<s-1 ? (s-1)*(s+4b)+a : 6*s*s -13*s +8 +a
|
374 |
a304ee64
|
Leszek Koltunski
|
// Right : index --> 6*s*s - 12*s + 7 - index
|
375 |
fa0f7a56
|
Leszek Koltunski
|
// Front : index --> if b==0 : s*s - 1 - index
|
376 |
|
|
// if b==s-1: 6*s*s -11*s +6 - index
|
377 |
|
|
// else
|
378 |
|
|
// a==0: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-2) + s
|
379 |
|
|
// else: s*s + s-1 + 4*(b-1)*(s-1) + 2*(s-1-a)
|
380 |
|
|
// Down : index --> b==0 ? (s-1-a) : s*s + s-1 + 4*(b-1)*(s-1) - a
|
381 |
|
|
// Left : index --> (s-1-a)*s + b
|
382 |
|
|
// Back : index --> if b==s-1: s*(s-1-a)
|
383 |
|
|
// if b==0 : 5*s*s -12*s + 8 + (s-1-a)*s
|
384 |
|
|
// else
|
385 |
|
|
// if a==s-1: s*s + 4*(s-2-b)*(s-1)
|
386 |
|
|
// else : s*s + 4*(s-2-b)*(s-1) + s + (s-2-a)*2
|
387 |
f0336037
|
Leszek Koltunski
|
|
388 |
20931cf6
|
Leszek Koltunski
|
public String retObjectString()
|
389 |
f0336037
|
Leszek Koltunski
|
{
|
390 |
fa0f7a56
|
Leszek Koltunski
|
StringBuilder objectString = new StringBuilder();
|
391 |
d99f3a48
|
Leszek Koltunski
|
int layers = getNumLayers();
|
392 |
|
|
int len = layers*layers;
|
393 |
ac940e24
|
Leszek Koltunski
|
int cubitIndex, row, col, color,face;
|
394 |
fa0f7a56
|
Leszek Koltunski
|
|
395 |
|
|
final int RIGHT= 0;
|
396 |
|
|
final int LEFT = 1;
|
397 |
|
|
final int UP = 2;
|
398 |
|
|
final int DOWN = 3;
|
399 |
|
|
final int FRONT= 4;
|
400 |
|
|
final int BACK = 5;
|
401 |
|
|
|
402 |
fb52fae9
|
Leszek Koltunski
|
// 'I' - interior, theoretically can happen
|
403 |
|
|
final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B', 'I'};
|
404 |
49595e4b
|
Leszek Koltunski
|
|
405 |
|
|
face = UP;
|
406 |
|
|
|
407 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
408 |
|
|
{
|
409 |
d99f3a48
|
Leszek Koltunski
|
row = i/layers;
|
410 |
|
|
col = i%layers;
|
411 |
fa0f7a56
|
Leszek Koltunski
|
|
412 |
d99f3a48
|
Leszek Koltunski
|
cubitIndex = col<layers-1 ? (layers-1)*(layers+4*col) + row : 6*layers*layers - 13*layers + 8 + row;
|
413 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
414 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
415 |
|
|
}
|
416 |
|
|
|
417 |
49595e4b
|
Leszek Koltunski
|
face = RIGHT;
|
418 |
|
|
|
419 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
420 |
|
|
{
|
421 |
d99f3a48
|
Leszek Koltunski
|
cubitIndex = 6*layers*layers - 12*layers +7 - i;
|
422 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
423 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
424 |
|
|
}
|
425 |
|
|
|
426 |
064ccc31
|
Leszek Koltunski
|
face = FRONT;
|
427 |
49595e4b
|
Leszek Koltunski
|
|
428 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
429 |
|
|
{
|
430 |
d99f3a48
|
Leszek Koltunski
|
row = i/layers;
|
431 |
|
|
col = i%layers;
|
432 |
fa0f7a56
|
Leszek Koltunski
|
|
433 |
d99f3a48
|
Leszek Koltunski
|
if( col==layers-1 ) cubitIndex = 6*layers*layers - 11*layers + 6 -i;
|
434 |
|
|
else if( col==0 ) cubitIndex = layers*layers - 1 - i;
|
435 |
fa0f7a56
|
Leszek Koltunski
|
else
|
436 |
|
|
{
|
437 |
d99f3a48
|
Leszek Koltunski
|
if( row==0 ) cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-2) + layers;
|
438 |
|
|
else cubitIndex = layers*layers + layers-1 + 4*(col-1)*(layers-1) + 2*(layers-1-row);
|
439 |
fa0f7a56
|
Leszek Koltunski
|
}
|
440 |
|
|
|
441 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
442 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
443 |
|
|
}
|
444 |
|
|
|
445 |
49595e4b
|
Leszek Koltunski
|
face = DOWN;
|
446 |
|
|
|
447 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
448 |
|
|
{
|
449 |
d99f3a48
|
Leszek Koltunski
|
row = i/layers;
|
450 |
|
|
col = i%layers;
|
451 |
fa0f7a56
|
Leszek Koltunski
|
|
452 |
d99f3a48
|
Leszek Koltunski
|
cubitIndex = col==0 ? layers-1-row : layers*layers + layers-1 + 4*(col-1)*(layers-1) - row;
|
453 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
454 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
455 |
|
|
}
|
456 |
|
|
|
457 |
49595e4b
|
Leszek Koltunski
|
face = LEFT;
|
458 |
|
|
|
459 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
460 |
|
|
{
|
461 |
d99f3a48
|
Leszek Koltunski
|
row = i/layers;
|
462 |
|
|
col = i%layers;
|
463 |
fa0f7a56
|
Leszek Koltunski
|
|
464 |
d99f3a48
|
Leszek Koltunski
|
cubitIndex = (layers-1-row)*layers + col;
|
465 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
466 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
467 |
|
|
}
|
468 |
|
|
|
469 |
49595e4b
|
Leszek Koltunski
|
face = BACK;
|
470 |
|
|
|
471 |
fa0f7a56
|
Leszek Koltunski
|
for(int i=0; i<len; i++)
|
472 |
|
|
{
|
473 |
d99f3a48
|
Leszek Koltunski
|
row = i/layers;
|
474 |
|
|
col = i%layers;
|
475 |
fa0f7a56
|
Leszek Koltunski
|
|
476 |
d99f3a48
|
Leszek Koltunski
|
if( col==layers-1 ) cubitIndex = layers*(layers-1-row);
|
477 |
|
|
else if( col==0 ) cubitIndex = 5*layers*layers - 12*layers + 8 + (layers-1-row)*layers;
|
478 |
fa0f7a56
|
Leszek Koltunski
|
else
|
479 |
|
|
{
|
480 |
d99f3a48
|
Leszek Koltunski
|
if( row==layers-1 ) cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1);
|
481 |
|
|
else cubitIndex = layers*layers + 4*(layers-2-col)*(layers-1) + layers + 2*(layers-2-row);
|
482 |
fa0f7a56
|
Leszek Koltunski
|
}
|
483 |
|
|
|
484 |
49595e4b
|
Leszek Koltunski
|
color = getCubitFaceColorIndex(cubitIndex,face);
|
485 |
fa0f7a56
|
Leszek Koltunski
|
objectString.append(FACE_NAMES[color]);
|
486 |
|
|
}
|
487 |
|
|
|
488 |
|
|
return objectString.toString();
|
489 |
f0336037
|
Leszek Koltunski
|
}
|
490 |
6fd4a72c
|
Leszek Koltunski
|
|
491 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
492 |
|
|
|
493 |
|
|
public int getObjectName(int numLayers)
|
494 |
|
|
{
|
495 |
|
|
switch(numLayers)
|
496 |
|
|
{
|
497 |
|
|
case 2: return R.string.cube2;
|
498 |
|
|
case 3: return R.string.cube3;
|
499 |
|
|
case 4: return R.string.cube4;
|
500 |
|
|
case 5: return R.string.cube5;
|
501 |
|
|
}
|
502 |
|
|
return R.string.cube3;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506 |
|
|
|
507 |
|
|
public int getInventor(int numLayers)
|
508 |
|
|
{
|
509 |
|
|
switch(numLayers)
|
510 |
|
|
{
|
511 |
|
|
case 2: return R.string.cube2_inventor;
|
512 |
|
|
case 3: return R.string.cube3_inventor;
|
513 |
|
|
case 4: return R.string.cube4_inventor;
|
514 |
|
|
case 5: return R.string.cube5_inventor;
|
515 |
|
|
}
|
516 |
|
|
return R.string.cube3_inventor;
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
520 |
|
|
|
521 |
|
|
public int getComplexity(int numLayers)
|
522 |
|
|
{
|
523 |
|
|
switch(numLayers)
|
524 |
|
|
{
|
525 |
|
|
case 2: return 4;
|
526 |
|
|
case 3: return 6;
|
527 |
|
|
case 4: return 8;
|
528 |
|
|
case 5: return 10;
|
529 |
|
|
}
|
530 |
|
|
return 6;
|
531 |
|
|
}
|
532 |
0c52af30
|
Leszek Koltunski
|
}
|