Revision 74cc695a
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.tablebases; |
11 | 11 |
|
12 |
import java.util.Random; |
|
13 |
|
|
12 | 14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
13 | 15 |
|
14 | 16 |
public class TablebaseHelpers |
15 | 17 |
{ |
18 |
|
|
19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
20 |
|
|
21 |
private static String print(int[][] move) |
|
22 |
{ |
|
23 |
StringBuilder sb = new StringBuilder(); |
|
24 |
|
|
25 |
if( move==null ) |
|
26 |
{ |
|
27 |
return ("move NULL!!"); |
|
28 |
} |
|
29 |
|
|
30 |
for (int[] ints : move) |
|
31 |
{ |
|
32 |
sb.append(' '); |
|
33 |
sb.append('('); |
|
34 |
sb.append(ints[0]); |
|
35 |
sb.append(' '); |
|
36 |
sb.append(ints[1]); |
|
37 |
sb.append(' '); |
|
38 |
sb.append(ints[2]); |
|
39 |
sb.append(')'); |
|
40 |
} |
|
41 |
|
|
42 |
return sb.toString(); |
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
public static void test(TablebasesAbstract tb) |
|
48 |
{ |
|
49 |
int size = tb.getSize(); |
|
50 |
|
|
51 |
for(int i=0; i<size; i++) |
|
52 |
{ |
|
53 |
boolean success = tb.test(i); |
|
54 |
|
|
55 |
if( (!success && i>0) || (success && i==0) ) |
|
56 |
{ |
|
57 |
android.util.Log.e("D", "--------> FAILED: "+i); |
|
58 |
break; |
|
59 |
} |
|
60 |
|
|
61 |
if( (i%1000)==0 ) android.util.Log.e("D", "trying "+i); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public static void test2(TablebasesAbstract tb, int num) |
|
68 |
{ |
|
69 |
Random rnd = new Random(); |
|
70 |
int size = tb.getSize(); |
|
71 |
|
|
72 |
for(int i=0; i<num; i++) |
|
73 |
{ |
|
74 |
int next = rnd.nextInt(size-1); |
|
75 |
int[][] moves = tb.solution(next); |
|
76 |
String moveSeq = print(moves); |
|
77 |
android.util.Log.e("D", (moves==null ? 0 : moves.length)+" Trying "+next+" : "+moveSeq); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
16 | 83 |
private static int swaps(int val, int[] buffer, int len) |
17 | 84 |
{ |
18 | 85 |
int ret = 0; |
src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java | ||
---|---|---|
436 | 436 |
|
437 | 437 |
if( !found ) |
438 | 438 |
{ |
439 |
android.util.Log.e("D", "solution error: no move found!"); |
|
439 |
android.util.Log.e("D", "----> solution error: no move found!");
|
|
440 | 440 |
return null; |
441 | 441 |
} |
442 | 442 |
} |
... | ... | |
517 | 517 |
|
518 | 518 |
return moves; |
519 | 519 |
} |
520 |
|
|
521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
522 |
|
|
523 |
public boolean test(int index) |
|
524 |
{ |
|
525 |
if( !mInitialized ) return false; |
|
526 |
|
|
527 |
int[] data = new int[4]; |
|
528 |
byte level = mTablebase.retrievePacked(index); |
|
529 |
int[] quats = getQuats(index); |
|
530 |
int numQuats = quats.length; |
|
531 |
int[] tmpQuats = new int[numQuats]; |
|
532 |
|
|
533 |
data[0]=0; |
|
534 |
data[1]=0; |
|
535 |
data[2]=1; |
|
536 |
data[3]=1; |
|
537 |
|
|
538 |
for(int ax=0; ax<mNumAxis; ax++) |
|
539 |
for(int cubit=0; cubit<mNumCubits; cubit++) |
|
540 |
mRotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax); |
|
541 |
|
|
542 |
for(int s=0; s<mScalingFactor; s++) |
|
543 |
{ |
|
544 |
int ax = data[0]; |
|
545 |
int layer = data[1]; |
|
546 |
int quat = data[3]; |
|
547 |
|
|
548 |
if( mRotatable[ax][layer] ) |
|
549 |
{ |
|
550 |
int bitLayer = (1<<layer); |
|
551 |
System.arraycopy(quats, 0, tmpQuats, 0, numQuats); |
|
552 |
|
|
553 |
for(int cubit=0; cubit<mNumCubits; cubit++) |
|
554 |
if( mRotRow[cubit][ax]==bitLayer ) |
|
555 |
{ |
|
556 |
int currQuat = tmpQuats[cubit]; |
|
557 |
int newQuat = getMultQuat(quat,currQuat); |
|
558 |
tmpQuats[cubit] = newQuat; |
|
559 |
} |
|
560 |
|
|
561 |
int childIndex = getIndex(tmpQuats); |
|
562 |
byte newLevel = mTablebase.retrievePacked(childIndex); |
|
563 |
|
|
564 |
if( ((newLevel-level+1)%3) == 0 ) return true; |
|
565 |
} |
|
566 |
|
|
567 |
getNextAxisLayerAngleQuat(data); |
|
568 |
} |
|
569 |
|
|
570 |
return false; |
|
571 |
} |
|
520 | 572 |
} |
src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java | ||
---|---|---|
15 | 15 |
import android.content.res.Resources; |
16 | 16 |
|
17 | 17 |
import org.distorted.library.type.Static3D; |
18 |
import org.distorted.objectlib.R; |
|
18 | 19 |
import org.distorted.objectlib.objects.TwistyPyraminx; |
19 | 20 |
|
20 | 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
42 | 43 |
|
43 | 44 |
public TablebasesPyraminx(Resources res) |
44 | 45 |
{ |
45 |
super(res,org.distorted.objectlib.R.raw.pduo_2_tablebase);
|
|
46 |
super(res, R.raw.pyra_3_tablebase);
|
|
46 | 47 |
} |
47 | 48 |
|
48 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
71 | 72 |
{-0.5f, SQ2/4, 0.0f}, |
72 | 73 |
{ 0.5f, SQ2/4, 0.0f}, |
73 | 74 |
|
75 |
{ 0.0f,-SQ2/2, 0.0f}, // index=0 has the quats already set up so that |
|
76 |
{ 0.0f,-SQ2/2, 0.0f}, // all the edges fall into right spots, so here |
|
77 |
{ 0.0f,-SQ2/2, 0.0f}, // they need to be all in one place |
|
74 | 78 |
{ 0.0f,-SQ2/2, 0.0f}, |
75 | 79 |
{ 0.0f,-SQ2/2, 0.0f}, |
76 | 80 |
{ 0.0f,-SQ2/2, 0.0f}, |
77 |
{ 0.0f,-SQ2/2, 0.0f}, |
|
78 |
{ 0.0f,-SQ2/2, 0.0f}, |
|
79 |
{ 0.0f,-SQ2/2, 0.0f}, |
|
80 |
|
|
81 |
/* |
|
82 |
{ 0.5f, 0.0f,-0.5f}, |
|
83 |
{ 0.5f, 0.0f, 0.5f}, |
|
84 |
{-0.5f, 0.0f,-0.5f}, |
|
85 |
{-0.5f, 0.0f, 0.5f}, |
|
86 |
{ 0.0f, SQ2/2, 0.0f}, |
|
87 |
*/ |
|
88 | 81 |
}; |
89 | 82 |
} |
90 | 83 |
|
Also available in: Unified diff
Pyraminx solver: tablebase working now (tipless, tips to be added in the SolverPyraminx class)