Revision 39d97e73
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandaged3x3.java | ||
---|---|---|
196 | 196 |
ArrayList<ScrambleStateBandaged3x3> graph = new ArrayList<>(); |
197 | 197 |
graph.add(bsg); |
198 | 198 |
|
199 |
long t1 = System.currentTimeMillis(); |
|
200 |
|
|
199 | 201 |
insertChildren(graph,id); |
202 |
|
|
203 |
long t2 = System.currentTimeMillis(); |
|
204 |
android.util.Log.e("D", "inserting children: "+(t2-t1)); |
|
205 |
|
|
200 | 206 |
pruneGraph(graph,id,false); |
207 |
|
|
208 |
long t3 = System.currentTimeMillis(); |
|
209 |
android.util.Log.e("D", "pruning graph: "+(t3-t2)); |
|
210 |
|
|
201 | 211 |
computeDistance(graph,id,0); |
212 |
|
|
213 |
long t4 = System.currentTimeMillis(); |
|
214 |
android.util.Log.e("D", "computing distance: "+(t4-t3)); |
|
215 |
|
|
202 | 216 |
removeDisconnectedParts(graph); |
217 |
|
|
218 |
long t5 = System.currentTimeMillis(); |
|
219 |
android.util.Log.e("D", "removing disconnected parts: "+(t5-t4)); |
|
220 |
|
|
203 | 221 |
remapGraph(graph); |
204 | 222 |
|
223 |
long t6 = System.currentTimeMillis(); |
|
224 |
android.util.Log.e("D", "remapping graph: "+(t6-t5)); |
|
225 |
|
|
205 | 226 |
int num = graph.size(); |
206 | 227 |
ScrambleState[] ret = new ScrambleState[num]; |
207 | 228 |
|
... | ... | |
211 | 232 |
ret[i] = ssb.produceScrambleState(); |
212 | 233 |
} |
213 | 234 |
|
235 |
long t7 = System.currentTimeMillis(); |
|
236 |
android.util.Log.e("D", "producing scramble states: "+(t7-t6)+" graph size: "+graph.size() ); |
|
237 |
|
|
214 | 238 |
return ret; |
215 | 239 |
} |
216 | 240 |
|
... | ... | |
253 | 277 |
private static void pruneGraph(ArrayList<ScrambleStateBandaged3x3> list, long id, boolean startingPrunedAlready) |
254 | 278 |
{ |
255 | 279 |
int num = list.size(); |
256 |
boolean pruned = false; |
|
257 |
ScrambleStateBandaged3x3 bsg; |
|
258 | 280 |
|
259 |
for(int i=0; i<num; i++)
|
|
281 |
if( num>1 ) // do not prune moves of an only node leading to itself. Case in point: bandaged 3x3 locked along 2 of its axis.
|
|
260 | 282 |
{ |
261 |
bsg = list.get(i); |
|
283 |
boolean pruned = false; |
|
284 |
ScrambleStateBandaged3x3 bsg; |
|
262 | 285 |
|
263 |
if( bsg.numAxis()<2 )
|
|
286 |
for(int i=0; i<num; i++)
|
|
264 | 287 |
{ |
265 |
long prunedID = bsg.getID(); |
|
266 |
if( id!=prunedID || !startingPrunedAlready ) |
|
267 |
{ |
|
268 |
startingPrunedAlready = true; |
|
269 |
remapID(list,prunedID,INVALID_MOVE); |
|
270 |
} |
|
288 |
bsg = list.get(i); |
|
271 | 289 |
|
272 |
// do not remove the starting point, even if it does have only 1 axis |
|
273 |
if( id!=prunedID ) |
|
290 |
if( bsg.numAxis()<2 ) |
|
274 | 291 |
{ |
275 |
list.remove(i); |
|
276 |
pruned = true; |
|
277 |
break; |
|
292 |
long prunedID = bsg.getID(); |
|
293 |
if( id!=prunedID || !startingPrunedAlready ) |
|
294 |
{ |
|
295 |
startingPrunedAlready = true; |
|
296 |
remapID(list,prunedID,INVALID_MOVE); |
|
297 |
} |
|
298 |
|
|
299 |
// do not remove the starting point, even if it does have only 1 axis |
|
300 |
if( id!=prunedID ) |
|
301 |
{ |
|
302 |
list.remove(i); |
|
303 |
pruned = true; |
|
304 |
break; |
|
305 |
} |
|
278 | 306 |
} |
279 | 307 |
} |
280 |
} |
|
281 | 308 |
|
282 |
if( pruned ) pruneGraph(list,id,startingPrunedAlready); |
|
309 |
if( pruned ) pruneGraph(list,id,startingPrunedAlready); |
|
310 |
} |
|
283 | 311 |
} |
284 | 312 |
|
285 | 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
312 | 340 |
|
313 | 341 |
for(int j=0; j<NUM_MOVES; j++) |
314 | 342 |
{ |
315 |
if( bsg.getMove(j)==id ) bsg.setMove(j,newId);
|
|
343 |
if( bsg.mMoves[j]==id ) bsg.mMoves[j]=newId;
|
|
316 | 344 |
} |
317 | 345 |
} |
318 | 346 |
} |
... | ... | |
583 | 611 |
|
584 | 612 |
return id; |
585 | 613 |
} |
586 |
/* |
|
614 |
|
|
587 | 615 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
588 | 616 |
|
589 | 617 |
private void printMoves() |
... | ... | |
628 | 656 |
|
629 | 657 |
for(int i=0; i<num; i++) |
630 | 658 |
{ |
631 |
bsg = graph.get(i); |
|
659 |
ScrambleStateBandaged3x3 bsg = graph.get(i);
|
|
632 | 660 |
android.util.Log.e("D", bsg.formatMoves()); |
633 | 661 |
} |
634 | 662 |
} |
635 |
*/ |
|
636 | 663 |
} |
Also available in: Unified diff
Bandaged 3x3: fix the case of a cube that has two of its axis permanently locked.
Introduce some debugging to figure out how to speed up creation of the graph.