Revision d6e2cf37
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/tablebases/TBDino4.java | ||
---|---|---|
14 | 14 |
import android.content.res.Resources; |
15 | 15 |
|
16 | 16 |
import org.distorted.library.type.Static3D; |
17 |
import org.distorted.objectlib.R; |
|
17 | 18 |
|
18 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
|
20 | 21 |
public class TBDino4 extends TablebasesAbstract |
21 | 22 |
{ |
22 |
private static final int INDEX_INVERTED = 90000; // TODO |
|
23 |
private static final int[][] SAME = {{0,3,7},{1,2,5},{4,8,9},{6,10,11}}; |
|
24 |
private static final int SOLVED1 = 6237; // part 011021302233 |
|
25 |
private static final int SOLVED2 = 10837; // part 001102133223 |
|
23 | 26 |
private int[][] mAngles; |
24 | 27 |
|
25 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
33 | 36 |
|
34 | 37 |
public TBDino4(Resources res) |
35 | 38 |
{ |
36 |
super(res,0);
|
|
39 |
super(res, R.raw.din4_3_tablebase);
|
|
37 | 40 |
} |
38 | 41 |
|
39 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
108 | 111 |
@Override |
109 | 112 |
int[] getSolvedIndices() |
110 | 113 |
{ |
111 |
return new int[] {0,INDEX_INVERTED};
|
|
114 |
return new int[] {SOLVED1,SOLVED2};
|
|
112 | 115 |
} |
113 | 116 |
|
114 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
117 | 120 |
@Override |
118 | 121 |
boolean isSolved(int index) |
119 | 122 |
{ |
120 |
return index==0 || index==INDEX_INVERTED;
|
|
123 |
return index==SOLVED1 || index==SOLVED2;
|
|
121 | 124 |
} |
122 | 125 |
|
123 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
154 | 157 |
} |
155 | 158 |
|
156 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
157 |
// 15408 really (see https://www.jaapsch.net/puzzles/dinocube.htm) but we do not assign indices |
|
158 |
// tightly but do (11 over 2)*(9 over 3)*(6 over 3) = 92400. |
|
160 |
// 15408 really (see https://www.jaapsch.net/puzzles/dinocube.htm) |
|
161 |
// Here 15400 because we equal positions where colors are simply swapped (those are the same with |
|
162 |
// respect to distance to the 2 solved positions) so there are (11 choose 2)*(8 choose 2)*(5 choose 2) |
|
163 |
// = 55*28*10 = 15400 possibilities. |
|
164 |
// We do not pack those tightly, some positions in the same orbit (by Burnside lemma) have 3 different |
|
165 |
// indices. |
|
159 | 166 |
|
160 | 167 |
int getSize() |
161 | 168 |
{ |
162 |
return 92400;
|
|
169 |
return 15400;
|
|
163 | 170 |
} |
164 | 171 |
|
165 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
169 | 176 |
return 5; |
170 | 177 |
} |
171 | 178 |
|
179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
180 |
|
|
181 |
private static int computeIndex(int[] partition, int section, int size) |
|
182 |
{ |
|
183 |
int index0=0; |
|
184 |
|
|
185 |
for(;index0<12; index0++) |
|
186 |
if(partition[index0]==section ) break; |
|
187 |
|
|
188 |
int index1=index0+1; |
|
189 |
int D1 = 0; |
|
190 |
|
|
191 |
for(;index1<12; index1++) |
|
192 |
{ |
|
193 |
int val = partition[index1]; |
|
194 |
if(val >section ) D1++; |
|
195 |
if(val==section ) break; |
|
196 |
} |
|
197 |
|
|
198 |
int index2=index1+1; |
|
199 |
int D2 = 0; |
|
200 |
|
|
201 |
for(;index2<12; index2++) |
|
202 |
{ |
|
203 |
int val = partition[index2]; |
|
204 |
if(val >section ) D2++; |
|
205 |
if(val==section ) break; |
|
206 |
} |
|
207 |
|
|
208 |
return D1*size - (D1+1)*D1/2 + D2; |
|
209 |
} |
|
210 |
|
|
172 | 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
173 | 212 |
|
174 | 213 |
public static int indexFromPartition(int[] partition) |
175 | 214 |
{ |
176 |
return 0; |
|
215 |
int index0 = computeIndex(partition,0,11); |
|
216 |
int index1 = computeIndex(partition,1,8); |
|
217 |
int index2 = computeIndex(partition,2,5); |
|
218 |
|
|
219 |
return index0 + 55*(index1 + 28*index2); |
|
177 | 220 |
} |
178 | 221 |
|
179 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
180 | 223 |
|
181 |
private static int[] quatsFromPartition(int[] partition)
|
|
224 |
private static void fillPart(int[] part, int index, int section, int size)
|
|
182 | 225 |
{ |
183 |
return new int[] {0,0,0,0, 0,0,0,0, 0,0,0,0}; |
|
226 |
int index0=0; |
|
227 |
|
|
228 |
for(; index0<10; index0++) |
|
229 |
if( part[index0]<0 ) |
|
230 |
{ |
|
231 |
part[index0] = section; |
|
232 |
break; |
|
233 |
} |
|
234 |
|
|
235 |
int index1 = index0+1; |
|
236 |
int diff = size-1; |
|
237 |
|
|
238 |
for(; index1<11; index1++) |
|
239 |
if( part[index1]<0 ) |
|
240 |
{ |
|
241 |
if( index<diff ) |
|
242 |
{ |
|
243 |
part[index1] = section; |
|
244 |
break; |
|
245 |
} |
|
246 |
else { index-=diff; diff--; } |
|
247 |
} |
|
248 |
|
|
249 |
int index2 = index1+1; |
|
250 |
|
|
251 |
for(; index2<12; index2++) |
|
252 |
{ |
|
253 |
if( part[index2]<0 ) index--; |
|
254 |
if( index<0 ) |
|
255 |
{ |
|
256 |
part[index2] = section; |
|
257 |
break; |
|
258 |
} |
|
259 |
} |
|
184 | 260 |
} |
185 | 261 |
|
186 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
187 | 263 |
|
188 |
private static int[] partitionFromQuats(int[] quats)
|
|
264 |
private static int[] partitionFromIndex(int index)
|
|
189 | 265 |
{ |
190 |
int[] tmp = new int[12]; |
|
191 |
System.arraycopy(quats, 0, tmp, 0, 12); |
|
192 |
TBDino6.getPermFromQuats(tmp); |
|
266 |
int index0 = (index%55); |
|
267 |
index /= 55; |
|
268 |
int index1 = (index%28); |
|
269 |
int index2 = (index/28); |
|
270 |
|
|
271 |
int[] part = new int[12]; |
|
272 |
for(int i=0; i<12; i++) part[i] = -1; |
|
193 | 273 |
|
194 |
return tmp; |
|
274 |
fillPart(part,index0,0,11); |
|
275 |
fillPart(part,index1,1,8); |
|
276 |
fillPart(part,index2,2,5); |
|
277 |
|
|
278 |
for(int i=0; i<12; i++) |
|
279 |
if( part[i]<0 ) part[i] = 3; |
|
280 |
|
|
281 |
return part; |
|
195 | 282 |
} |
196 | 283 |
|
197 | 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
198 | 285 |
|
199 |
private static int[] partitionFromIndex(int index)
|
|
286 |
private static void fillPerm(int[] perm, int[] part, int section)
|
|
200 | 287 |
{ |
201 |
return null; |
|
288 |
int num=0; |
|
289 |
int[] same = SAME[section]; |
|
290 |
|
|
291 |
for(int i=0; i<12; i++) |
|
292 |
if( part[i]==section ) |
|
293 |
perm[same[num++]] = i; |
|
294 |
} |
|
295 |
|
|
296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
297 |
|
|
298 |
private static int[] quatsFromPartition(int[] partition) |
|
299 |
{ |
|
300 |
int[] perm = new int[12]; |
|
301 |
fillPerm(perm,partition,0); |
|
302 |
fillPerm(perm,partition,1); |
|
303 |
fillPerm(perm,partition,2); |
|
304 |
fillPerm(perm,partition,3); |
|
305 |
|
|
306 |
return TBDino6.getQuatsFromPerm(perm); |
|
307 |
} |
|
308 |
|
|
309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
310 |
|
|
311 |
private static int[] partitionFromQuats(int[] quats) |
|
312 |
{ |
|
313 |
int[] perm = new int[12]; |
|
314 |
System.arraycopy(quats, 0, perm, 0, 12); |
|
315 |
TBDino6.getPermFromQuats(perm); |
|
316 |
|
|
317 |
int[] part = new int[12]; |
|
318 |
|
|
319 |
for(int i=0; i<4; i++) |
|
320 |
{ |
|
321 |
int[] index = SAME[i]; |
|
322 |
part[perm[index[0]]] = part[perm[index[1]]] = part[perm[index[2]]] = (-i-1); |
|
323 |
} |
|
324 |
|
|
325 |
int newVal=0; |
|
326 |
|
|
327 |
for(int i=0; i<12; i++) |
|
328 |
{ |
|
329 |
int val = part[i]; |
|
330 |
|
|
331 |
if( val<0 ) |
|
332 |
{ |
|
333 |
for(int j=i; j<12; j++) |
|
334 |
if( part[j]==val ) part[j] = newVal; |
|
335 |
|
|
336 |
newVal++; |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
return part; |
|
202 | 341 |
} |
203 | 342 |
|
204 | 343 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Dino4 solver: code finished, but still doesn't work.