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; |
Also available in: Unified diff
Pyraminx solver: tablebase working now (tipless, tips to be added in the SolverPyraminx class)