Revision c0254421
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/bandaged/BandagedState.java | ||
---|---|---|
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.bandaged; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class BandagedState |
|
25 |
{ |
|
26 |
private final int mNumX, mNumY, mNumZ; |
|
27 |
private final int[] mInfo; |
|
28 |
private final int[] mTmp; |
|
29 |
private final int LEN = 4; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public BandagedState(int[] x, int[] y, int[] z) |
|
34 |
{ |
|
35 |
mTmp = new int[LEN]; |
|
36 |
|
|
37 |
mNumX = x==null ? 0 : x.length/(LEN-1); |
|
38 |
mNumY = y==null ? 0 : y.length/(LEN-1); |
|
39 |
mNumZ = z==null ? 0 : z.length/(LEN-1); |
|
40 |
|
|
41 |
mInfo = new int[LEN*(mNumX+mNumY+mNumZ)]; |
|
42 |
int start = 0; |
|
43 |
|
|
44 |
for(int i=0; i<mNumX; i++) |
|
45 |
{ |
|
46 |
mInfo[LEN*i + start] = 0; |
|
47 |
mInfo[LEN*i+1 + start] = x[(LEN-1)*i ]; |
|
48 |
mInfo[LEN*i+2 + start] = x[(LEN-1)*i+1]; |
|
49 |
mInfo[LEN*i+3 + start] = x[(LEN-1)*i+2]; |
|
50 |
} |
|
51 |
|
|
52 |
start = LEN*mNumX; |
|
53 |
|
|
54 |
for(int i=0; i<mNumY; i++) |
|
55 |
{ |
|
56 |
mInfo[LEN*i + start] = 1; |
|
57 |
mInfo[LEN*i+1 + start] = y[(LEN-1)*i ]; |
|
58 |
mInfo[LEN*i+2 + start] = y[(LEN-1)*i+1]; |
|
59 |
mInfo[LEN*i+3 + start] = y[(LEN-1)*i+2]; |
|
60 |
} |
|
61 |
|
|
62 |
start = LEN*(mNumX+mNumY); |
|
63 |
|
|
64 |
for(int i=0; i<mNumZ; i++) |
|
65 |
{ |
|
66 |
mInfo[LEN*i + start] = 2; |
|
67 |
mInfo[LEN*i+1 + start] = z[(LEN-1)*i ]; |
|
68 |
mInfo[LEN*i+2 + start] = z[(LEN-1)*i+1]; |
|
69 |
mInfo[LEN*i+3 + start] = z[(LEN-1)*i+2]; |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
private int getIndex(int num, boolean useX, boolean useY, boolean useZ) |
|
76 |
{ |
|
77 |
int current= -1, total= mNumX + mNumY + mNumZ; |
|
78 |
|
|
79 |
for(int i=0; i<total; i++) |
|
80 |
{ |
|
81 |
if( (mInfo[LEN*i]==0 && useX) || (mInfo[LEN*i]==1 && useY) || (mInfo[LEN*i]==2 && useZ) ) |
|
82 |
{ |
|
83 |
if( ++current==num ) return i; |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
return -1; |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public int getTotal(boolean useX, boolean useY, boolean useZ) |
|
93 |
{ |
|
94 |
int total = 0; |
|
95 |
|
|
96 |
if( useX ) total += mNumX; |
|
97 |
if( useY ) total += mNumY; |
|
98 |
if( useZ ) total += mNumZ; |
|
99 |
|
|
100 |
return total; |
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public int[] getInfo(int num, boolean useX, boolean useY, boolean useZ) |
|
106 |
{ |
|
107 |
int index = getIndex(num,useX,useY,useZ); |
|
108 |
|
|
109 |
mTmp[0] = mInfo[LEN*index ]; // axis |
|
110 |
mTmp[1] = mInfo[LEN*index+1]; // row |
|
111 |
mTmp[2] = mInfo[LEN*index+2]; // angle |
|
112 |
mTmp[3] = mInfo[LEN*index+3]; // next state |
|
113 |
|
|
114 |
return mTmp; |
|
115 |
} |
|
116 |
} |
src/main/java/org/distorted/bandaged/BandagedStateGraph.java | ||
---|---|---|
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.bandaged; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
|
|
26 |
public class BandagedStateGraph |
|
27 |
{ |
|
28 |
private static final int CORNER_S = 0; |
|
29 |
private static final int CORNER_X = 1; |
|
30 |
private static final int CORNER_Y = 2; |
|
31 |
private static final int CORNER_Z = 3; |
|
32 |
|
|
33 |
private static final int CENTER_0 = 0; |
|
34 |
private static final int CENTER_1 = 1; |
|
35 |
private static final int CENTER_2 = 2; |
|
36 |
private static final int CENTER_3 = 3; |
|
37 |
|
|
38 |
private int mID; |
|
39 |
private final int[] mMoves; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public BandagedStateGraph(int id) |
|
44 |
{ |
|
45 |
mID = id; |
|
46 |
mMoves = createMoves(mID); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public static void computeGraph() |
|
52 |
{ |
|
53 |
ArrayList<BandagedStateGraph> graph; |
|
54 |
|
|
55 |
int id = 0; |
|
56 |
int id1 = setCenter(id , CENTER_2, 0); |
|
57 |
int id2 = setCenter(id1 , CENTER_2, 1); |
|
58 |
int id3 = setCenter(id2 , CENTER_3, 2); |
|
59 |
int id4 = setCenter(id3 , CENTER_2, 3); |
|
60 |
|
|
61 |
int id5 = setCorner(id4 , CORNER_X, 0); |
|
62 |
int id6 = setCorner(id5 , CORNER_Y, 1); |
|
63 |
int id7 = setCorner(id6 , CORNER_X, 2); |
|
64 |
int id8 = setCorner(id7 , CORNER_Z, 3); |
|
65 |
int id9 = setCorner(id8 , CORNER_Y, 4); |
|
66 |
int id10= setCorner(id9 , CORNER_Y, 5); |
|
67 |
int id11= setCorner(id10, CORNER_S, 6); |
|
68 |
int id12= setCorner(id11, CORNER_Z, 7); |
|
69 |
|
|
70 |
BandagedStateGraph bsg = new BandagedStateGraph(id12); |
|
71 |
graph = new ArrayList<>(); |
|
72 |
graph.add(bsg); |
|
73 |
|
|
74 |
insertChildren(graph,id12); |
|
75 |
pruneGraph(graph); |
|
76 |
remapGraph(graph); |
|
77 |
|
|
78 |
int num = graph.size(); |
|
79 |
android.util.Log.e("D", "\n"+num+" states\n"); |
|
80 |
|
|
81 |
for(int i=0; i<num; i++) |
|
82 |
{ |
|
83 |
bsg = graph.get(i); |
|
84 |
android.util.Log.e("D", formatMoves(bsg)); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
private static void insertChildren(ArrayList<BandagedStateGraph> list, int id) |
|
91 |
{ |
|
92 |
BandagedStateGraph bsg = findState(list,id); |
|
93 |
|
|
94 |
if( bsg==null ) |
|
95 |
{ |
|
96 |
android.util.Log.e("D", "error: "+id+" doesn't exist"); |
|
97 |
return; |
|
98 |
} |
|
99 |
|
|
100 |
for(int i=0; i<12; i++) |
|
101 |
{ |
|
102 |
int move = bsg.getMove(i); |
|
103 |
|
|
104 |
if( move!=0 ) |
|
105 |
{ |
|
106 |
BandagedStateGraph tmp = findState(list,move); |
|
107 |
|
|
108 |
if( tmp==null ) |
|
109 |
{ |
|
110 |
tmp = new BandagedStateGraph(move); |
|
111 |
list.add(tmp); |
|
112 |
insertChildren(list,move); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
private static void pruneGraph(ArrayList<BandagedStateGraph> list) |
|
121 |
{ |
|
122 |
int num = list.size(), numAxis; |
|
123 |
boolean pruned = false; |
|
124 |
BandagedStateGraph bsg; |
|
125 |
|
|
126 |
for(int i=0; i<num; i++) |
|
127 |
{ |
|
128 |
bsg = list.get(i); |
|
129 |
numAxis = bsg.numAxis(); |
|
130 |
|
|
131 |
if( numAxis<2 ) |
|
132 |
{ |
|
133 |
list.remove(i); |
|
134 |
int id = bsg.getID(); |
|
135 |
pruned = true; |
|
136 |
remapID(list,id,0); |
|
137 |
break; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
if( pruned ) pruneGraph(list); |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
private static void remapGraph(ArrayList<BandagedStateGraph> list) |
|
147 |
{ |
|
148 |
int id, num = list.size(); |
|
149 |
BandagedStateGraph bsg; |
|
150 |
|
|
151 |
for(int i=0; i<num; i++ ) |
|
152 |
{ |
|
153 |
bsg = list.get(i); |
|
154 |
id = bsg.getID(); |
|
155 |
bsg.setID(i); |
|
156 |
remapID(list,id,i); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
161 |
|
|
162 |
private static void remapID(ArrayList<BandagedStateGraph> list, int id, int newId) |
|
163 |
{ |
|
164 |
BandagedStateGraph bsg; |
|
165 |
int size = list.size(); |
|
166 |
|
|
167 |
for(int i=0; i<size; i++) |
|
168 |
{ |
|
169 |
bsg = list.get(i); |
|
170 |
|
|
171 |
for(int j=0; j<12; j++) |
|
172 |
{ |
|
173 |
if( bsg.getMove(j)==id ) bsg.setMove(j,newId); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
private static BandagedStateGraph findState(ArrayList<BandagedStateGraph> list, int id) |
|
181 |
{ |
|
182 |
BandagedStateGraph bsg; |
|
183 |
int num = list.size(); |
|
184 |
|
|
185 |
for(int i=0; i<num; i++) |
|
186 |
{ |
|
187 |
bsg= list.get(i); |
|
188 |
if( bsg.getID() == id ) return bsg; |
|
189 |
} |
|
190 |
|
|
191 |
return null; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
private static String formatMoves(BandagedStateGraph bsg) |
|
197 |
{ |
|
198 |
String x = getTable(bsg,0); |
|
199 |
String y = getTable(bsg,3); |
|
200 |
String z = getTable(bsg,6); |
|
201 |
|
|
202 |
return " new BandagedState( "+x+", "+y+", "+z+" ),"; |
|
203 |
} |
|
204 |
|
|
205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 |
|
|
207 |
private static String getTable(BandagedStateGraph sc, int index) |
|
208 |
{ |
|
209 |
String ret = ""; |
|
210 |
|
|
211 |
if( index==0 || index==3 ) |
|
212 |
{ |
|
213 |
int m0 = sc.getMove(index ); |
|
214 |
int m1 = sc.getMove(index+1); |
|
215 |
int m2 = sc.getMove(index+2); |
|
216 |
|
|
217 |
if( m0==0 && m1==0 && m2==0 ) return formatL("null"); |
|
218 |
|
|
219 |
if( m0!=0 ) ret += formatRet(ret,2, 1,m0); |
|
220 |
if( m1!=0 ) ret += formatRet(ret,2, 2,m1); |
|
221 |
if( m2!=0 ) ret += formatRet(ret,2,-1,m2); |
|
222 |
} |
|
223 |
else |
|
224 |
{ |
|
225 |
int m0 = sc.getMove(index ); |
|
226 |
int m1 = sc.getMove(index+1); |
|
227 |
int m2 = sc.getMove(index+2); |
|
228 |
int m3 = sc.getMove(index+3); |
|
229 |
int m4 = sc.getMove(index+4); |
|
230 |
int m5 = sc.getMove(index+5); |
|
231 |
|
|
232 |
if( m0==0 && m1==0 && m2==0 && m3==0 && m4==0 && m5==0 ) |
|
233 |
{ |
|
234 |
return formatL("null"); |
|
235 |
} |
|
236 |
|
|
237 |
if( m0!=0 ) ret += formatRet(ret,0, 1,m0); |
|
238 |
if( m1!=0 ) ret += formatRet(ret,0, 2,m1); |
|
239 |
if( m2!=0 ) ret += formatRet(ret,0,-1,m2); |
|
240 |
if( m3!=0 ) ret += formatRet(ret,2, 1,m3); |
|
241 |
if( m4!=0 ) ret += formatRet(ret,2, 2,m4); |
|
242 |
if( m5!=0 ) ret += formatRet(ret,2,-1,m5); |
|
243 |
} |
|
244 |
|
|
245 |
return formatL("new int[] {" + ret + "}"); |
|
246 |
} |
|
247 |
|
|
248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
249 |
|
|
250 |
private static String formatRet(String str, int row, int angle, int id) |
|
251 |
{ |
|
252 |
String ret = str.length()!=0 ? ",":""; |
|
253 |
|
|
254 |
ret += row; |
|
255 |
ret += angle<0 ? "," : ", "; |
|
256 |
ret += angle; |
|
257 |
|
|
258 |
if( id< 10 ) ret += (", "+id); |
|
259 |
else if( id<100 ) ret += (", " +id); |
|
260 |
else ret += ("," +id); |
|
261 |
|
|
262 |
return ret; |
|
263 |
} |
|
264 |
|
|
265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
266 |
|
|
267 |
private static final int LENGTH = 38; |
|
268 |
|
|
269 |
private static String formatL(String input) |
|
270 |
{ |
|
271 |
int len = input.length(); |
|
272 |
String ret = input; |
|
273 |
for(int i=0 ;i<LENGTH-len; i++) ret += " "; |
|
274 |
return ret; |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
|
|
279 |
private int getID() |
|
280 |
{ |
|
281 |
return mID; |
|
282 |
} |
|
283 |
|
|
284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
285 |
|
|
286 |
private void setID(int id) |
|
287 |
{ |
|
288 |
mID = id; |
|
289 |
} |
|
290 |
|
|
291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
292 |
|
|
293 |
private int getMove(int index) |
|
294 |
{ |
|
295 |
return (index>=0 && index<12) ? mMoves[index] : -1; |
|
296 |
} |
|
297 |
|
|
298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
299 |
|
|
300 |
private int numAxis() |
|
301 |
{ |
|
302 |
int num = 0; |
|
303 |
|
|
304 |
if( mMoves[ 0]!=0 || mMoves[ 1]!=0 || mMoves[ 2]!=0 ) num++; |
|
305 |
if( mMoves[ 3]!=0 || mMoves[ 4]!=0 || mMoves[ 5]!=0 ) num++; |
|
306 |
if( mMoves[ 6]!=0 || mMoves[ 7]!=0 || mMoves[ 8]!=0 ) num++; |
|
307 |
if( mMoves[ 9]!=0 || mMoves[10]!=0 || mMoves[11]!=0 ) num++; |
|
308 |
|
|
309 |
return num; |
|
310 |
} |
|
311 |
|
|
312 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
313 |
|
|
314 |
private void setMove(int index, int newMove) |
|
315 |
{ |
|
316 |
if( index>=0 && index<12 ) mMoves[index] = newMove; |
|
317 |
} |
|
318 |
|
|
319 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
320 |
|
|
321 |
private static String debug(int id) |
|
322 |
{ |
|
323 |
int ce0 = getCenter(id,0); |
|
324 |
int ce1 = getCenter(id,1); |
|
325 |
int ce2 = getCenter(id,2); |
|
326 |
int ce3 = getCenter(id,3); |
|
327 |
|
|
328 |
int co0 = getCorner(id,0); |
|
329 |
int co1 = getCorner(id,1); |
|
330 |
int co2 = getCorner(id,2); |
|
331 |
int co3 = getCorner(id,3); |
|
332 |
int co4 = getCorner(id,4); |
|
333 |
int co5 = getCorner(id,5); |
|
334 |
int co6 = getCorner(id,6); |
|
335 |
int co7 = getCorner(id,7); |
|
336 |
|
|
337 |
String center = centerString(ce0) + centerString(ce1) + centerString(ce2) + centerString(ce3); |
|
338 |
String corner = cornerString(co0) + cornerString(co1) + cornerString(co2) + cornerString(co3) + |
|
339 |
cornerString(co4) + cornerString(co5) + cornerString(co6) + cornerString(co7); |
|
340 |
|
|
341 |
return center + " -" + corner; |
|
342 |
} |
|
343 |
|
|
344 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
345 |
|
|
346 |
private static String centerString(int center) |
|
347 |
{ |
|
348 |
return " "+center; |
|
349 |
} |
|
350 |
|
|
351 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
352 |
|
|
353 |
private static String cornerString(int corner) |
|
354 |
{ |
|
355 |
switch(corner) |
|
356 |
{ |
|
357 |
case CORNER_S: return " S"; |
|
358 |
case CORNER_X: return " X"; |
|
359 |
case CORNER_Y: return " Y"; |
|
360 |
case CORNER_Z: return " Z"; |
|
361 |
} |
|
362 |
|
|
363 |
return "?"; |
|
364 |
} |
|
365 |
|
|
366 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
367 |
|
|
368 |
private static int[] createMoves(int id) |
|
369 |
{ |
|
370 |
int[] ret = new int[12]; |
|
371 |
|
|
372 |
boolean moveX = xPossible(id); |
|
373 |
boolean moveY = yPossible(id); |
|
374 |
boolean moveZ0 = z0Possible(id); |
|
375 |
boolean moveZ2 = z2Possible(id); |
|
376 |
|
|
377 |
if( moveX ) createXmoves(id,ret); |
|
378 |
else { ret[ 0] = 0; ret[ 1] = 0; ret[ 2] = 0; } |
|
379 |
if( moveY ) createYmoves(id,ret); |
|
380 |
else { ret[ 3] = 0; ret[ 4] = 0; ret[ 5] = 0; } |
|
381 |
if( moveZ0) createZ0moves(id,ret); |
|
382 |
else { ret[ 6] = 0; ret[ 7] = 0; ret[ 8] = 0; } |
|
383 |
if( moveZ2) createZ2moves(id,ret); |
|
384 |
else { ret[ 9] = 0; ret[10] = 0; ret[11] = 0; } |
|
385 |
|
|
386 |
return ret; |
|
387 |
} |
|
388 |
|
|
389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
390 |
|
|
391 |
private static boolean xPossible(int id) |
|
392 |
{ |
|
393 |
if( getCorner(id,4)==CORNER_X ) return false; |
|
394 |
if( getCorner(id,5)==CORNER_X ) return false; |
|
395 |
if( getCorner(id,6)==CORNER_X ) return false; |
|
396 |
if( getCorner(id,7)==CORNER_X ) return false; |
|
397 |
|
|
398 |
if( getCenter(id,1)==CENTER_1 ) return false; |
|
399 |
if( getCenter(id,2)==CENTER_1 ) return false; |
|
400 |
if( getCenter(id,3)==CENTER_1 ) return false; |
|
401 |
|
|
402 |
return true; |
|
403 |
} |
|
404 |
|
|
405 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
406 |
|
|
407 |
private static boolean yPossible(int id) |
|
408 |
{ |
|
409 |
if( getCorner(id,2)==CORNER_Y ) return false; |
|
410 |
if( getCorner(id,3)==CORNER_Y ) return false; |
|
411 |
if( getCorner(id,6)==CORNER_Y ) return false; |
|
412 |
if( getCorner(id,7)==CORNER_Y ) return false; |
|
413 |
|
|
414 |
if( getCenter(id,0)==CENTER_0 ) return false; |
|
415 |
if( getCenter(id,2)==CENTER_0 ) return false; |
|
416 |
if( getCenter(id,3)==CENTER_0 ) return false; |
|
417 |
|
|
418 |
return true; |
|
419 |
} |
|
420 |
|
|
421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
422 |
|
|
423 |
private static boolean z0Possible(int id) |
|
424 |
{ |
|
425 |
if( getCorner(id,0)==CORNER_Z ) return false; |
|
426 |
if( getCorner(id,2)==CORNER_Z ) return false; |
|
427 |
if( getCorner(id,4)==CORNER_Z ) return false; |
|
428 |
if( getCorner(id,6)==CORNER_Z ) return false; |
|
429 |
|
|
430 |
if( getCenter(id,0)==CENTER_1 ) return false; |
|
431 |
if( getCenter(id,1)==CENTER_0 ) return false; |
|
432 |
|
|
433 |
return true; |
|
434 |
} |
|
435 |
|
|
436 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
437 |
|
|
438 |
private static boolean z2Possible(int id) |
|
439 |
{ |
|
440 |
if( getCorner(id,1)==CORNER_Z ) return false; |
|
441 |
if( getCorner(id,3)==CORNER_Z ) return false; |
|
442 |
if( getCorner(id,5)==CORNER_Z ) return false; |
|
443 |
if( getCorner(id,7)==CORNER_Z ) return false; |
|
444 |
|
|
445 |
if( getCenter(id,0)==CENTER_3 ) return false; |
|
446 |
if( getCenter(id,1)==CENTER_2 ) return false; |
|
447 |
|
|
448 |
return true; |
|
449 |
} |
|
450 |
|
|
451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
452 |
|
|
453 |
private static int getCorner(int id, int index) |
|
454 |
{ |
|
455 |
return (id>>(14-2*index))&3; |
|
456 |
} |
|
457 |
|
|
458 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
459 |
|
|
460 |
private static int getCenter(int id, int index) |
|
461 |
{ |
|
462 |
return (id>>(22-2*index))&3; |
|
463 |
} |
|
464 |
|
|
465 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
466 |
|
|
467 |
private static int setCorner(int id, int corner, int index) |
|
468 |
{ |
|
469 |
return id + ((corner-getCorner(id,index))<<(14-2*index)); |
|
470 |
} |
|
471 |
|
|
472 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
473 |
|
|
474 |
private static int setCenter(int id, int center, int index) |
|
475 |
{ |
|
476 |
return id + ((center-getCenter(id,index))<<(22-2*index)); |
|
477 |
} |
|
478 |
|
|
479 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
480 |
|
|
481 |
private static void createXmoves(int id, int[] moves) |
|
482 |
{ |
|
483 |
int id1 = rotateX(id); |
|
484 |
moves[0] = id1; |
|
485 |
int id2 = rotateX(id1); |
|
486 |
moves[1] = id2; |
|
487 |
int id3 = rotateX(id2); |
|
488 |
moves[2] = id3; |
|
489 |
} |
|
490 |
|
|
491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
492 |
|
|
493 |
private static void createYmoves(int id, int[] moves) |
|
494 |
{ |
|
495 |
int id1 = rotateY(id); |
|
496 |
moves[3] = id1; |
|
497 |
int id2 = rotateY(id1); |
|
498 |
moves[4] = id2; |
|
499 |
int id3 = rotateY(id2); |
|
500 |
moves[5] = id3; |
|
501 |
} |
|
502 |
|
|
503 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
504 |
|
|
505 |
private static void createZ0moves(int id, int[] moves) |
|
506 |
{ |
|
507 |
int id1 = rotateZ0(id); |
|
508 |
moves[6] = id1; |
|
509 |
int id2 = rotateZ0(id1); |
|
510 |
moves[7] = id2; |
|
511 |
int id3 = rotateZ0(id2); |
|
512 |
moves[8] = id3; |
|
513 |
} |
|
514 |
|
|
515 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
516 |
|
|
517 |
private static void createZ2moves(int id, int[] moves) |
|
518 |
{ |
|
519 |
int id1 = rotateZ2(id); |
|
520 |
moves[ 9] = id1; |
|
521 |
int id2 = rotateZ2(id1); |
|
522 |
moves[10] = id2; |
|
523 |
int id3 = rotateZ2(id2); |
|
524 |
moves[11] = id3; |
|
525 |
} |
|
526 |
|
|
527 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
528 |
|
|
529 |
private static int rotateX(int id) |
|
530 |
{ |
|
531 |
int newCorner4 = rotCornerX(getCorner(id,5)); |
|
532 |
int newCorner5 = rotCornerX(getCorner(id,7)); |
|
533 |
int newCorner6 = rotCornerX(getCorner(id,4)); |
|
534 |
int newCorner7 = rotCornerX(getCorner(id,6)); |
|
535 |
int newCenter = rotCenter (getCenter(id,0)); |
|
536 |
|
|
537 |
int id1 = setCorner(id ,newCorner4,4); |
|
538 |
int id2 = setCorner(id1,newCorner5,5); |
|
539 |
int id3 = setCorner(id2,newCorner6,6); |
|
540 |
int id4 = setCorner(id3,newCorner7,7); |
|
541 |
int id5 = setCenter(id4,newCenter ,0); |
|
542 |
|
|
543 |
return id5; |
|
544 |
} |
|
545 |
|
|
546 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
547 |
|
|
548 |
private static int rotateY(int id) |
|
549 |
{ |
|
550 |
int newCorner2 = rotCornerY(getCorner(id,6)); |
|
551 |
int newCorner3 = rotCornerY(getCorner(id,2)); |
|
552 |
int newCorner6 = rotCornerY(getCorner(id,7)); |
|
553 |
int newCorner7 = rotCornerY(getCorner(id,3)); |
|
554 |
int newCenter = rotCenter (getCenter(id,1)); |
|
555 |
|
|
556 |
int id1 = setCorner(id ,newCorner2,2); |
|
557 |
int id2 = setCorner(id1,newCorner3,3); |
|
558 |
int id3 = setCorner(id2,newCorner6,6); |
|
559 |
int id4 = setCorner(id3,newCorner7,7); |
|
560 |
int id5 = setCenter(id4,newCenter ,1); |
|
561 |
|
|
562 |
return id5; |
|
563 |
} |
|
564 |
|
|
565 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
566 |
|
|
567 |
private static int rotateZ0(int id) |
|
568 |
{ |
|
569 |
int newCorner0 = rotCornerZ(getCorner(id,2)); |
|
570 |
int newCorner2 = rotCornerZ(getCorner(id,6)); |
|
571 |
int newCorner4 = rotCornerZ(getCorner(id,0)); |
|
572 |
int newCorner6 = rotCornerZ(getCorner(id,4)); |
|
573 |
int newCenter = rotCenter (getCenter(id,2)); |
|
574 |
|
|
575 |
int id1 = setCorner(id ,newCorner0,0); |
|
576 |
int id2 = setCorner(id1,newCorner2,2); |
|
577 |
int id3 = setCorner(id2,newCorner4,4); |
|
578 |
int id4 = setCorner(id3,newCorner6,6); |
|
579 |
int id5 = setCenter(id4,newCenter ,2); |
|
580 |
|
|
581 |
return id5; |
|
582 |
} |
|
583 |
|
|
584 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
585 |
|
|
586 |
private static int rotateZ2(int id) |
|
587 |
{ |
|
588 |
int newCorner1 = rotCornerZ(getCorner(id,3)); |
|
589 |
int newCorner3 = rotCornerZ(getCorner(id,7)); |
|
590 |
int newCorner5 = rotCornerZ(getCorner(id,1)); |
|
591 |
int newCorner7 = rotCornerZ(getCorner(id,5)); |
|
592 |
int newCenter = rotCenter (getCenter(id,3)); |
|
593 |
|
|
594 |
int id1 = setCorner(id ,newCorner1,1); |
|
595 |
int id2 = setCorner(id1,newCorner3,3); |
|
596 |
int id3 = setCorner(id2,newCorner5,5); |
|
597 |
int id4 = setCorner(id3,newCorner7,7); |
|
598 |
int id5 = setCenter(id4,newCenter ,3); |
|
599 |
|
|
600 |
return id5; |
|
601 |
} |
|
602 |
|
|
603 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
604 |
|
|
605 |
private static int rotCornerX(int corner) |
|
606 |
{ |
|
607 |
switch(corner) |
|
608 |
{ |
|
609 |
case CORNER_S: return CORNER_S; |
|
610 |
case CORNER_X: android.util.Log.e("DIST", "rotateX: ERROR"); |
|
611 |
return CORNER_S; |
|
612 |
case CORNER_Y: return CORNER_Z; |
|
613 |
case CORNER_Z: return CORNER_Y; |
|
614 |
} |
|
615 |
|
|
616 |
return CORNER_S; |
|
617 |
} |
|
618 |
|
|
619 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
620 |
|
|
621 |
private static int rotCornerY(int corner) |
|
622 |
{ |
|
623 |
switch(corner) |
|
624 |
{ |
|
625 |
case CORNER_S: return CORNER_S; |
|
626 |
case CORNER_X: return CORNER_Z; |
|
627 |
case CORNER_Y: android.util.Log.e("DIST", "rotateY: ERROR"); |
|
628 |
return CORNER_S; |
|
629 |
case CORNER_Z: return CORNER_X; |
|
630 |
} |
|
631 |
|
|
632 |
return CORNER_S; |
|
633 |
} |
|
634 |
|
|
635 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
636 |
|
|
637 |
private static int rotCornerZ(int corner) |
|
638 |
{ |
|
639 |
switch(corner) |
|
640 |
{ |
|
641 |
case CORNER_S: return CORNER_S; |
|
642 |
case CORNER_X: return CORNER_Y; |
|
643 |
case CORNER_Y: return CORNER_X; |
|
644 |
case CORNER_Z: android.util.Log.e("DIST", "rotateZ: ERROR"); |
|
645 |
return CORNER_S; |
|
646 |
} |
|
647 |
|
|
648 |
return CORNER_S; |
|
649 |
} |
|
650 |
|
|
651 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
652 |
|
|
653 |
private static int rotCenter(int center) |
|
654 |
{ |
|
655 |
switch(center) |
|
656 |
{ |
|
657 |
case CENTER_0: return CENTER_3; |
|
658 |
case CENTER_1: return CENTER_0; |
|
659 |
case CENTER_2: return CENTER_1; |
|
660 |
case CENTER_3: return CENTER_2; |
|
661 |
} |
|
662 |
|
|
663 |
return CENTER_0; |
|
664 |
} |
|
665 |
} |
src/main/java/org/distorted/objects/TwistyBandaged3Plate.java | ||
---|---|---|
25 | 25 |
import org.distorted.library.main.DistortedTexture; |
26 | 26 |
import org.distorted.library.mesh.MeshSquare; |
27 | 27 |
import org.distorted.library.type.Static4D; |
28 |
import org.distorted.bandaged.BandagedState; |
|
28 | 29 |
import org.distorted.main.R; |
29 | 30 |
|
30 | 31 |
import java.util.Random; |
... | ... | |
38 | 39 |
private boolean mUseY; |
39 | 40 |
private boolean mUseZ; |
40 | 41 |
|
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 | 42 |
// The 16 'significant' states of the 3Plate bandaged cube. |
128 | 43 |
// One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which |
129 | 44 |
// rotations of the Cube are possible. |
... | ... | |
137 | 52 |
// then we will land in state 10. If we make move (2,2), we will land in state 13. There are no other |
138 | 53 |
// 'x' moves that lead to a 'significant' state. |
139 | 54 |
|
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 |
};
|
|
55 |
private final BandagedState[] mStates = new BandagedState[]
|
|
56 |
{ |
|
57 |
new BandagedState( new int[] { 2,-1, 1, 2, 1, 6 }, new int[] { 0,-1, 5, 0, 1, 3 }, new int[] { 2,-1, 2, 2, 1, 4 } ),
|
|
58 |
new BandagedState( new int[] { 2, 1, 0 }, null , new int[] { 2, 1,10, 2, 2, 7 } ),
|
|
59 |
new BandagedState( null , new int[] { 0,-1,11, 0, 2, 8 }, new int[] { 2, 1, 0 } ),
|
|
60 |
new BandagedState( new int[] { 2, 1,12, 2, 2, 9 }, new int[] { 0,-1, 0 }, null ),
|
|
61 |
new BandagedState( new int[] { 2,-1,10, 2, 2,13 }, null , new int[] { 2,-1, 0 } ),
|
|
62 |
new BandagedState( null , new int[] { 0, 1, 0 }, new int[] { 2,-1,11, 2, 2,14 } ),
|
|
63 |
new BandagedState( new int[] { 2,-1, 0 }, new int[] { 0, 1,12, 0, 2,15 }, null ),
|
|
64 |
new BandagedState( null , new int[] { 2,-2, 7, 2,-1, 7, 2, 1, 7, 2, 2, 7}, new int[] { 2,-1,10, 2, 2, 1 } ),
|
|
65 |
new BandagedState( new int[] { 0,-2, 8, 0,-1, 8, 0, 1, 8, 0, 2, 8}, new int[] { 0, 1,11, 0, 2, 2 }, null ),
|
|
66 |
new BandagedState( new int[] { 2,-1,12, 2, 2, 3 }, null , new int[] { 0,-2, 9, 0,-1, 9, 0, 1, 9, 0, 2, 9} ),
|
|
67 |
new BandagedState( 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 } ),
|
|
68 |
new BandagedState( 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 } ),
|
|
69 |
new BandagedState( 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} ),
|
|
70 |
new BandagedState( new int[] { 2, 1,10, 2, 2, 4 }, new int[] { 2,-2,13, 2,-1,13, 2, 1,13, 2, 2,13}, null ),
|
|
71 |
new BandagedState( new int[] { 0,-2,14, 0,-1,14, 0, 1,14, 0, 2,14}, null , new int[] { 2, 1,11, 2, 2, 5 } ),
|
|
72 |
new BandagedState( null , new int[] { 0,-1,12, 0, 2, 6 }, new int[] { 0,-2,15, 0,-1,15, 0, 1,15, 0, 2,15} )
|
|
73 |
}; |
|
159 | 74 |
|
160 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
161 | 76 |
|
src/main/java/org/distorted/objects/TwistyBandagedEvil.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.res.Resources; |
23 | 23 |
|
24 |
import org.distorted.bandaged.BandagedState; |
|
24 | 25 |
import org.distorted.library.main.DistortedEffects; |
25 | 26 |
import org.distorted.library.main.DistortedTexture; |
26 | 27 |
import org.distorted.library.mesh.MeshSquare; |
... | ... | |
33 | 34 |
|
34 | 35 |
class TwistyBandagedEvil extends TwistyBandagedAbstract |
35 | 36 |
{ |
37 |
private int mCurrState; |
|
38 |
private boolean mUseX; |
|
39 |
private boolean mUseY; |
|
40 |
private boolean mUseZ; |
|
41 |
|
|
42 |
// The list of all 'significant' states of the Evil Cube, just like in the 3Plate Cube class. |
|
43 |
// This time the list got computed automatically - by the BandagedStateGraph.computeGraph(). |
|
44 |
|
|
45 |
private final BandagedState[] mStates = new BandagedState[] |
|
46 |
{ |
|
47 |
new BandagedState( new int[] {2, 1, 1,2,-1, 2} , new int[] {2, 2,142,2,-1, 28} , new int[] {0, 1,114} ), |
|
48 |
new BandagedState( new int[] {2, 2, 2} , new int[] {2,-1,143} , null ), |
|
49 |
new BandagedState( new int[] {2, 2, 1} , null , new int[] {0, 1, 3,0, 2, 47} ), |
|
50 |
new BandagedState( new int[] {2, 1, 4} , new int[] {2, 1,132,2,-1,131} , new int[] {0, 1, 47,0,-1, 2} ), |
|
51 |
new BandagedState( new int[] {2,-1, 3} , new int[] {2, 1, 5,2,-1, 6} , null ), |
|
52 |
new BandagedState( null , new int[] {2, 2, 6,2,-1, 4} , new int[] {0, 1, 51} ), |
|
53 |
new BandagedState( null , new int[] {2, 1, 4,2, 2, 5} , new int[] {2, 2, 7,2,-1, 80} ), |
|
54 |
new BandagedState( new int[] {2, 2, 8} , null , new int[] {2, 1, 80,2, 2, 6} ), |
|
55 |
new BandagedState( new int[] {2, 2, 7} , null , new int[] {0,-1, 9} ), |
|
56 |
new BandagedState( new int[] {2, 1, 10,2, 2, 11,2,-1, 12}, null , new int[] {0, 1, 8} ), |
|
57 |
new BandagedState( new int[] {2, 1, 11,2, 2, 12,2,-1, 9}, null , new int[] {0,-1,118} ), |
|
58 |
new BandagedState( new int[] {2, 1, 12,2, 2, 9,2,-1, 10}, null , new int[] {2, 1, 77} ), |
|
59 |
new BandagedState( new int[] {2, 1, 9,2, 2, 10,2,-1, 11}, null , new int[] {2, 1, 13,2, 2,143} ), |
|
60 |
new BandagedState( new int[] {2, 1, 14,2, 2, 15,2,-1, 16}, new int[] {2, 1, 57,2,-1, 58} , new int[] {2, 1,143,2,-1, 12} ), |
|
61 |
new BandagedState( new int[] {2, 1, 15,2, 2, 16,2,-1, 13}, null , new int[] {2, 1, 41} ), |
|
62 |
new BandagedState( new int[] {2, 1, 16,2, 2, 13,2,-1, 14}, null , new int[] {0, 1, 82} ), |
|
63 |
new BandagedState( new int[] {2, 1, 13,2, 2, 14,2,-1, 15}, new int[] {2, 1, 17,2,-1, 18} , new int[] {0, 1,111,0,-1,115} ), |
|
64 |
new BandagedState( null , new int[] {2, 2, 18,2,-1, 16} , new int[] {0,-1,139} ), |
|
65 |
new BandagedState( new int[] {2, 1, 19,2,-1, 20} , new int[] {2, 1, 16,2, 2, 17} , new int[] {2, 1,142} ), |
|
66 |
new BandagedState( new int[] {2, 2, 20,2,-1, 18} , null , new int[] {2, 1, 39,2, 2,140} ), |
|
67 |
new BandagedState( new int[] {2, 1, 18,2, 2, 19} , new int[] {2, 1, 21} , null ), |
|
68 |
new BandagedState( null , new int[] {2,-1, 20} , new int[] {0,-1, 22} ), |
|
69 |
new BandagedState( new int[] {2, 2, 23,2,-1, 24} , null , new int[] {0, 1, 21} ), |
|
70 |
new BandagedState( new int[] {2, 1, 24,2, 2, 22} , null , new int[] {2, 1, 92} ), |
|
71 |
new BandagedState( new int[] {2, 1, 22,2,-1, 23} , null , new int[] {0, 1, 25} ), |
|
72 |
new BandagedState( new int[] {2, 1, 26,2, 2, 27} , null , new int[] {0,-1, 24} ), |
|
73 |
new BandagedState( new int[] {2, 1, 27,2,-1, 25} , new int[] {2, 1, 74} , null ), |
|
74 |
new BandagedState( new int[] {2, 2, 25,2,-1, 26} , null , new int[] {2, 1, 28,2, 2,124} ), |
|
75 |
new BandagedState( new int[] {2, 1, 29,2, 2, 30,2,-1, 31}, new int[] {2,-1,142} , new int[] {2, 1,124,2,-1, 27} ), |
|
76 |
new BandagedState( new int[] {2, 1, 30,2, 2, 31,2,-1, 28}, null , new int[] {2, 1,141} ), |
|
77 |
new BandagedState( new int[] {2, 1, 31,2, 2, 28,2,-1, 29}, null , new int[] {0, 1,130} ), |
|
78 |
new BandagedState( new int[] {2, 1, 28,2, 2, 29,2,-1, 30}, new int[] {2, 1, 32,2,-1, 33} , new int[] {0, 1, 89,0,-1, 90} ), |
|
79 |
new BandagedState( null , new int[] {2, 2, 33,2,-1, 31} , new int[] {0,-1,137} ), |
|
80 |
new BandagedState( new int[] {2, 1, 34} , new int[] {2, 1, 31,2, 2, 32} , null ), |
|
81 |
new BandagedState( new int[] {2,-1, 33} , null , new int[] {2, 1, 35} ), |
|
82 |
new BandagedState( null , new int[] {2,-1, 36} , new int[] {2,-1, 34} ), |
|
83 |
new BandagedState( null , new int[] {2, 1, 35} , new int[] {2,-1, 37} ), |
|
84 |
new BandagedState( null , new int[] {2, 1, 38,2, 2, 93} , new int[] {2, 1, 36} ), |
|
85 |
new BandagedState( new int[] {2, 1, 39} , new int[] {2, 1, 93,2,-1, 37} , null ), |
|
86 |
new BandagedState( new int[] {2,-1, 38} , new int[] {2, 1, 40,2,-1, 64} , new int[] {2, 1,140,2,-1, 19} ), |
|
87 |
new BandagedState( new int[] {2, 1, 41,2,-1, 42} , new int[] {2, 2, 64,2,-1, 39} , null ), |
|
88 |
new BandagedState( new int[] {2, 2, 42,2,-1, 40} , null , new int[] {2,-1, 14} ), |
|
89 |
new BandagedState( new int[] {2, 1, 40,2, 2, 41} , null , new int[] {0, 1, 43,0, 2,128} ), |
|
90 |
new BandagedState( new int[] {2, 1, 44,2,-1, 45} , new int[] {2, 1,114,2, 2,113,2,-1, 86}, new int[] {0, 1,128,0,-1, 42} ), |
|
91 |
new BandagedState( new int[] {2, 2, 45,2,-1, 43} , new int[] {2, 1, 48,2,-1,108} , new int[] {2,-1, 81} ), |
|
92 |
new BandagedState( new int[] {2, 1, 43,2, 2, 44} , null , new int[] {0, 1, 46} ), |
|
93 |
new BandagedState( null , new int[] {2, 1, 47} , new int[] {0,-1, 45} ), |
|
94 |
new BandagedState( null , new int[] {2,-1, 46} , new int[] {0, 2, 2,0,-1, 3} ), |
|
95 |
new BandagedState( new int[] {2,-1, 49} , new int[] {2, 2,108,2,-1, 44} , null ), |
|
96 |
new BandagedState( new int[] {2, 1, 48} , null , new int[] {0, 1, 50} ), |
|
97 |
new BandagedState( null , new int[] {2, 1, 51,2, 2, 52} , new int[] {0,-1, 49} ), |
|
98 |
new BandagedState( null , new int[] {2, 1, 52,2,-1, 50} , new int[] {0,-1, 5} ), |
|
99 |
new BandagedState( null , new int[] {2, 2, 50,2,-1, 51} , new int[] {2,-1, 53} ), |
|
100 |
new BandagedState( null , new int[] {2, 1, 54,2, 2, 55} , new int[] {2, 1, 52} ), |
|
101 |
new BandagedState( null , new int[] {2, 1, 55,2,-1, 53} , new int[] {0,-1,104} ), |
|
102 |
new BandagedState( null , new int[] {2, 2, 53,2,-1, 54} , new int[] {0, 2, 56,0,-1, 65} ), |
|
103 |
new BandagedState( new int[] {2, 1, 57} , null , new int[] {0, 1, 65,0, 2, 55} ), |
|
104 |
new BandagedState( new int[] {2,-1, 56} , new int[] {2, 2, 58,2,-1, 13} , null ), |
|
105 |
new BandagedState( null , new int[] {2, 1, 13,2, 2, 57} , new int[] {2,-1, 59} ), |
|
106 |
new BandagedState( new int[] {2, 1, 60} , null , new int[] {2, 1, 58} ), |
|
107 |
new BandagedState( new int[] {2,-1, 59} , null , new int[] {2, 1, 61} ), |
|
108 |
new BandagedState( new int[] {2,-1, 62} , null , new int[] {2,-1, 60} ), |
|
109 |
new BandagedState( new int[] {2, 1, 61} , new int[] {2,-1, 63} , null ), |
|
110 |
new BandagedState( null , new int[] {2, 1, 62} , new int[] {2, 1, 64} ), |
|
111 |
new BandagedState( null , new int[] {2, 1, 39,2, 2, 40} , new int[] {2,-1, 63} ), |
|
112 |
new BandagedState( new int[] {2, 1, 66,2,-1, 67} , new int[] {2, 1, 78,2, 2, 79,2,-1, 80}, new int[] {0, 1, 55,0,-1, 56} ), |
|
113 |
new BandagedState( new int[] {2, 2, 67,2,-1, 65} , new int[] {2,-1,107} , null ), |
|
114 |
new BandagedState( new int[] {2, 1, 65,2, 2, 66} , null , new int[] {0, 1, 68} ), |
|
115 |
new BandagedState( null , new int[] {2, 1, 69} , new int[] {0,-1, 67} ), |
|
116 |
new BandagedState( null , new int[] {2,-1, 68} , new int[] {0,-1, 70} ), |
|
117 |
new BandagedState( null , new int[] {2,-1, 71} , new int[] {0, 1, 69} ), |
|
118 |
new BandagedState( new int[] {2,-1, 72} , new int[] {2, 1, 70} , null ), |
|
119 |
new BandagedState( new int[] {2, 1, 71} , null , new int[] {0,-1, 73} ), |
|
120 |
new BandagedState( new int[] {2, 1, 74,2, 2, 75} , null , new int[] {0, 1, 72} ), |
|
121 |
new BandagedState( new int[] {2, 1, 75,2,-1, 73} , new int[] {2,-1, 26} , new int[] {0, 1, 83,0,-1,138} ), |
|
122 |
new BandagedState( new int[] {2, 2, 73,2,-1, 74} , new int[] {2, 1, 76,2,-1, 77} , null ), |
|
123 |
new BandagedState( null , new int[] {2, 2, 77,2,-1, 75} , new int[] {0, 1, 78} ), |
|
124 |
new BandagedState( null , new int[] {2, 1, 75,2, 2, 76} , new int[] {2,-1, 11} ), |
|
125 |
new BandagedState( null , new int[] {2, 1, 79,2, 2, 80,2,-1, 65}, new int[] {0,-1, 76} ), |
|
126 |
new BandagedState( null , new int[] {2, 1, 80,2, 2, 65,2,-1, 78}, new int[] {2,-1,110} ), |
|
127 |
new BandagedState( new int[] {2, 1, 81,2,-1, 82} , new int[] {2, 1, 65,2, 2, 78,2,-1, 79}, new int[] {2, 1, 6,2,-1, 7} ), |
|
128 |
new BandagedState( new int[] {2, 2, 82,2,-1, 80} , null , new int[] {2, 1, 44} ), |
|
129 |
new BandagedState( new int[] {2, 1, 80,2, 2, 81} , new int[] {2, 1, 83,2,-1, 84} , new int[] {0,-1, 15} ), |
|
130 |
new BandagedState( null , new int[] {2, 2, 84,2,-1, 82} , new int[] {0, 2,138,0,-1, 74} ), |
|
131 |
new BandagedState( new int[] {2, 1, 85} , new int[] {2, 1, 82,2, 2, 83} , null ), |
|
132 |
new BandagedState( new int[] {2,-1, 84} , null , new int[] {2, 1, 86,2, 2,119} ), |
|
133 |
new BandagedState( new int[] {2, 1, 87,2,-1, 88} , new int[] {2, 1, 43,2, 2,114,2,-1,113}, new int[] {2, 1,119,2,-1, 85} ), |
|
134 |
new BandagedState( new int[] {2, 2, 88,2,-1, 86} , null , new int[] {2, 1, 94} ), |
|
135 |
new BandagedState( new int[] {2, 1, 86,2, 2, 87} , new int[] {2, 1, 89} , null ), |
|
136 |
new BandagedState( null , new int[] {2,-1, 88} , new int[] {0, 2, 90,0,-1, 31} ), |
|
137 |
new BandagedState( new int[] {2, 1, 91,2, 2, 92} , null , new int[] {0, 1, 31,0, 2, 89} ), |
|
138 |
new BandagedState( new int[] {2, 1, 92,2,-1, 90} , null , new int[] {0, 1, 93} ), |
|
139 |
new BandagedState( new int[] {2, 2, 90,2,-1, 91} , null , new int[] {2,-1, 23} ), |
|
140 |
new BandagedState( null , new int[] {2, 2, 37,2,-1, 38} , new int[] {0,-1, 91} ), |
|
141 |
new BandagedState( null , new int[] {2,-1, 95} , new int[] {2,-1, 87} ), |
|
142 |
new BandagedState( null , new int[] {2, 1, 94} , new int[] {2,-1, 96} ), |
|
143 |
new BandagedState( null , new int[] {2, 1, 97} , new int[] {2, 1, 95} ), |
|
144 |
new BandagedState( new int[] {2, 1, 98} , new int[] {2,-1, 96} , null ), |
|
145 |
new BandagedState( new int[] {2,-1, 97} , null , new int[] {2,-1, 99} ), |
|
146 |
new BandagedState( new int[] {2, 2,100,2,-1,101} , null , new int[] {2, 1, 98} ), |
|
147 |
new BandagedState( new int[] {2, 1,101,2, 2, 99} , new int[] {2, 1,111,2,-1,112} , null ), |
|
148 |
new BandagedState( new int[] {2, 1, 99,2,-1,100} , new int[] {2, 1,102} , new int[] {2, 1,108,2,-1,109} ), |
|
149 |
new BandagedState( new int[] {2, 1,103,2,-1,104} , new int[] {2,-1,101} , null ), |
|
150 |
new BandagedState( new int[] {2, 2,104,2,-1,102} , null , new int[] {2,-1,105} ), |
|
151 |
new BandagedState( new int[] {2, 1,102,2, 2,103} , null , new int[] {0, 1, 54} ), |
|
152 |
new BandagedState( new int[] {2,-1,106} , null , new int[] {2, 1,103} ), |
|
153 |
new BandagedState( new int[] {2, 1,105} , null , new int[] {2, 1,107} ), |
|
154 |
new BandagedState( null , new int[] {2, 1, 66} , new int[] {2,-1,106} ), |
|
155 |
new BandagedState( null , new int[] {2, 1, 44,2, 2, 48} , new int[] {2, 2,109,2,-1,101} ), |
|
156 |
new BandagedState( new int[] {2,-1,110} , null , new int[] {2, 1,101,2, 2,108} ), |
|
157 |
new BandagedState( new int[] {2, 1,109} , null , new int[] {2, 1, 79} ), |
|
158 |
new BandagedState( null , new int[] {2, 2,112,2,-1,100} , new int[] {0, 2,115,0,-1, 16} ), |
|
159 |
new BandagedState( null , new int[] {2, 1,100,2, 2,111} , new int[] {2, 1,113} ), |
|
160 |
new BandagedState( null , new int[] {2, 1, 86,2, 2, 43,2,-1,114}, new int[] {2,-1,112} ), |
|
161 |
new BandagedState( null , new int[] {2, 1,113,2, 2, 86,2,-1, 43}, null ), |
|
162 |
new BandagedState( new int[] {2, 2,116} , null , new int[] {0, 1, 16,0, 2,111} ), |
|
163 |
new BandagedState( new int[] {2, 2,115} , null , new int[] {2,-1,117} ), |
|
164 |
new BandagedState( new int[] {2, 1,118} , null , new int[] {2, 1,116} ), |
|
165 |
new BandagedState( new int[] {2,-1,117} , null , new int[] {0, 1, 10} ), |
|
166 |
new BandagedState( null , new int[] {2, 1,120,2, 2,121,2,-1,122}, new int[] {2, 2, 85,2,-1, 86} ), |
|
167 |
new BandagedState( null , new int[] {2, 1,121,2, 2,122,2,-1,119}, new int[] {2,-1,129} ), |
|
168 |
new BandagedState( null , new int[] {2, 1,122,2, 2,119,2,-1,120}, new int[] {0, 1,125} ), |
|
169 |
new BandagedState( null , new int[] {2, 1,119,2, 2,120,2,-1,121}, new int[] {0,-1,123} ), |
|
170 |
new BandagedState( null , new int[] {2, 2,124} , new int[] {0, 1,122} ), |
|
171 |
new BandagedState( null , new int[] {2, 2,123} , new int[] {2, 2, 27,2,-1, 28} ), |
|
172 |
new BandagedState( null , new int[] {2, 1,126} , new int[] {0,-1,121} ), |
|
173 |
new BandagedState( null , new int[] {2,-1,125} , new int[] {2,-1,127} ), |
|
174 |
new BandagedState( null , new int[] {2, 2,128} , new int[] {2, 1,126} ), |
|
175 |
new BandagedState( null , new int[] {2, 2,127} , new int[] {0, 2, 42,0,-1, 43} ), |
|
176 |
new BandagedState( new int[] {2, 2,130,2,-1,131} , null , new int[] {2, 1,120} ), |
|
177 |
new BandagedState( new int[] {2, 1,131,2, 2,129} , null , new int[] {0,-1, 30} ), |
|
178 |
new BandagedState( new int[] {2, 1,129,2,-1,130} , new int[] {2, 1, 3,2, 2,132} , null ), |
|
179 |
new BandagedState( null , new int[] {2, 2,131,2,-1, 3} , new int[] {0,-1,133} ), |
|
180 |
new BandagedState( null , new int[] {2,-1,134} , new int[] {0, 1,132} ), |
|
181 |
new BandagedState( new int[] {2,-1,135} , new int[] {2, 1,133} , null ), |
|
182 |
new BandagedState( new int[] {2, 1,134} , null , new int[] {0,-1,136} ), |
|
183 |
new BandagedState( new int[] {2, 1,137} , null , new int[] {0, 1,135} ), |
|
184 |
new BandagedState( new int[] {2,-1,136} , null , new int[] {0, 1, 32} ), |
|
185 |
new BandagedState( new int[] {2, 1,139} , null , new int[] {0, 1, 74,0, 2, 83} ), |
|
186 |
new BandagedState( new int[] {2,-1,138} , null , new int[] {0, 1, 17} ), |
|
187 |
new BandagedState( null , new int[] {2, 1,141} , new int[] {2, 2, 19,2,-1, 39} ), |
|
188 |
new BandagedState( null , new int[] {2,-1,140} , new int[] {2,-1, 29} ), |
|
189 |
new BandagedState( null , new int[] {2, 1, 28} , new int[] {2,-1, 18} ), |
|
190 |
new BandagedState( null , new int[] {2, 1, 1} , new int[] {2, 2, 12,2,-1, 13} ) |
|
191 |
}; |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
36 | 195 |
private static final float[][] POSITIONS = new float[][] |
37 | 196 |
{ |
38 | 197 |
{ 1.0f, 1.0f, -1.0f}, |
... | ... | |
77 | 236 |
|
78 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 | 238 |
// PUBLIC API |
80 |
// TODO |
|
81 | 239 |
|
82 | 240 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int num) |
83 | 241 |
{ |
84 | 242 |
if( num==0 ) |
85 | 243 |
{ |
86 |
scramble[num][0] = rnd.nextInt(ROTATION_AXIS.length); |
|
87 |
} |
|
88 |
else |
|
89 |
{ |
|
90 |
int newVector = rnd.nextInt(ROTATION_AXIS.length-1); |
|
91 |
scramble[num][0] = (newVector>=scramble[num-1][0] ? newVector+1 : newVector); |
|
244 |
mCurrState = 0; |
|
245 |
mUseX = true; |
|
246 |
mUseY = true; |
|
247 |
mUseZ = true; |
|
92 | 248 |
} |
93 | 249 |
|
94 |
float rowFloat = rnd.nextFloat(); |
|
250 |
int total = mStates[mCurrState].getTotal(mUseX,mUseY,mUseZ); |
|
251 |
int random= rnd.nextInt(total); |
|
252 |
int[] info= mStates[mCurrState].getInfo(random,mUseX,mUseY,mUseZ); |
|
95 | 253 |
|
96 |
for(int row=0; row<mRowChances.length; row++) |
|
97 |
{ |
|
98 |
if( rowFloat<=mRowChances[row] ) |
|
99 |
{ |
|
100 |
scramble[num][1] = row; |
|
101 |
break; |
|
102 |
} |
|
103 |
} |
|
254 |
scramble[num][0] = info[0]; |
|
255 |
scramble[num][1] = info[1]; |
|
256 |
scramble[num][2] = info[2]; |
|
104 | 257 |
|
105 |
switch( rnd.nextInt(4) ) |
|
258 |
mCurrState = info[3]; |
|
259 |
|
|
260 |
switch(info[0]) |
|
106 | 261 |
{ |
107 |
case 0: scramble[num][2] = -2; break; |
|
108 |
case 1: scramble[num][2] = -1; break; |
|
109 |
case 2: scramble[num][2] = 1; break; |
|
110 |
case 3: scramble[num][2] = 2; break; |
|
262 |
case 0: mUseX = false; mUseY = true ; mUseZ = true ; break; |
|
263 |
case 1: mUseX = true ; mUseY = false; mUseZ = true ; break; |
|
264 |
case 2: mUseX = true ; mUseY = true ; mUseZ = false; break; |
|
111 | 265 |
} |
266 |
|
|
267 |
//android.util.Log.e("D", (info[0]==0 ? "X" : (info[0]==1 ? "Y" : "Z")) + info[2] +" --> "+info[3]); |
|
112 | 268 |
} |
113 | 269 |
|
114 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Automatic scrambling of the Evil Cube works!