Revision 5b9d6595
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/objectlib/tablebases/TBDino6.java | ||
|---|---|---|
| 156 | 156 |
return new int[] { axis, (1<<layer), angle };
|
| 157 | 157 |
} |
| 158 | 158 |
|
| 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 160 |
// here we change back the mapping introduced by 'newMove()' |
|
| 161 |
|
|
| 162 |
@Override |
|
| 163 |
void convertMoves(int[][] moves) |
|
| 164 |
{
|
|
| 165 |
for(int[] move : moves ) |
|
| 166 |
{
|
|
| 167 |
int[] newMove = newMove(move[0],move[1],move[2]); |
|
| 168 |
|
|
| 169 |
move[0] = newMove[0]; |
|
| 170 |
move[1] = newMove[1]; |
|
| 171 |
move[2] = newMove[2]; |
|
| 172 |
} |
|
| 173 |
/* |
|
| 174 |
int len = moves.length; |
|
| 175 |
|
|
| 176 |
for(int i=0; i<len; i++) |
|
| 177 |
{
|
|
| 178 |
int[] move = moves[i]; |
|
| 179 |
if( move[1]==((1<<0)+(1<<1)) || move[1]==((1<<1)+(1<<2)) ) unrollMoves(moves,i); |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
*/ |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
|
|
| 187 |
private void unrollMoves(int[][] moves, int index) |
|
| 188 |
{
|
|
| 189 |
int caseUnroll=0; |
|
| 190 |
int[] move = moves[index]; |
|
| 191 |
|
|
| 192 |
if( move[1]==((1<<0)+(1<<1)) ) |
|
| 193 |
{
|
|
| 194 |
move[1] = (1<<2); |
|
| 195 |
move[2] = -move[2]; |
|
| 196 |
caseUnroll = move[2]>0 ? 0:1; |
|
| 197 |
} |
|
| 198 |
else if( move[1]==((1<<1)+(1<<2)) ) |
|
| 199 |
{
|
|
| 200 |
move[1] = (1<<0); |
|
| 201 |
move[2] = -move[2]; |
|
| 202 |
caseUnroll = move[2]>0 ? 2:3; |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
int len = moves.length; |
|
| 206 |
for(int i=index+1; i<len; i++) unrollMove(moves[i],caseUnroll); |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 210 |
|
|
| 211 |
private void unrollMove(int[] move, int caseUnroll) |
|
| 212 |
{
|
|
| 213 |
int ax = move[0]; |
|
| 214 |
int la = move[1]; |
|
| 215 |
|
|
| 216 |
switch(caseUnroll) |
|
| 217 |
{
|
|
| 218 |
case 0: android.util.Log.e("D", "case 0 ax "+ax);
|
|
| 219 |
switch(ax) |
|
| 220 |
{
|
|
| 221 |
case 0: break; |
|
| 222 |
case 1: move[0]=3; move[1]=negate(la); break; |
|
| 223 |
case 2: move[0]=1; break; |
|
| 224 |
case 3: move[0]=2; move[1]=negate(la); break; |
|
| 225 |
} |
|
| 226 |
break; |
|
| 227 |
case 1: android.util.Log.e("D", "case 1 ax "+ax);
|
|
| 228 |
switch(ax) |
|
| 229 |
{
|
|
| 230 |
case 0: break; |
|
| 231 |
case 1: move[0]=2; break; |
|
| 232 |
case 2: move[0]=3; move[1]=negate(la); break; |
|
| 233 |
case 3: move[0]=1; move[1]=negate(la); break; |
|
| 234 |
} |
|
| 235 |
break; |
|
| 236 |
case 2: android.util.Log.e("D", "case 2 ax "+ax);
|
|
| 237 |
switch(ax) |
|
| 238 |
{
|
|
| 239 |
case 0: move[0]=1; move[1]=negate(la); break; |
|
| 240 |
case 1: move[0]=2; break; |
|
| 241 |
case 2: move[0]=0; move[1]=negate(la); break; |
|
| 242 |
case 3: break; |
|
| 243 |
} |
|
| 244 |
break; |
|
| 245 |
case 3: android.util.Log.e("D", "case 3 ax "+ax);
|
|
| 246 |
switch(ax) |
|
| 247 |
{
|
|
| 248 |
case 0: move[0]=2; move[1]=negate(la); break; |
|
| 249 |
case 1: move[0]=0; move[1]=negate(la); break; |
|
| 250 |
case 2: move[0]=1; break; |
|
| 251 |
case 3: break; |
|
| 252 |
} |
|
| 253 |
break; |
|
| 254 |
} |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 258 |
|
|
| 259 |
private int negate(int layer) |
|
| 260 |
{
|
|
| 261 |
return 7-layer; |
|
| 262 |
} |
|
| 263 |
|
|
| 159 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 160 | 265 |
|
| 161 | 266 |
int getSize() |
| src/main/java/org/distorted/objectlib/tablebases/TablebasesPruning.java | ||
|---|---|---|
| 274 | 274 |
|
| 275 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 276 | 276 |
|
| 277 |
private boolean jumpMidZeroRecursive(int index, int jump, int depth, int lastA, int lastR, int[][] solution)
|
|
| 277 |
private boolean jumpMidSolvedRecursive(int index, int jump, int depth, int lastA, int lastR, int[][] solution)
|
|
| 278 | 278 |
{
|
| 279 | 279 |
int[] quats = getQuats(index); |
| 280 | 280 |
int numQuats = quats.length; |
| ... | ... | |
| 328 | 328 |
return true; |
| 329 | 329 |
} |
| 330 | 330 |
|
| 331 |
if( jump>1 && jumpMidZeroRecursive(childIndex, jump-1, depth+1, ax, layer, solution) )
|
|
| 331 |
if( jump>1 && jumpMidSolvedRecursive(childIndex, jump-1, depth+1, ax, layer, solution) )
|
|
| 332 | 332 |
{
|
| 333 | 333 |
return true; |
| 334 | 334 |
} |
| ... | ... | |
| 343 | 343 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 344 | 344 |
// ret: [0][] --> (new index,new depth,num moves,?) ; [1...N-1][] --> moves. |
| 345 | 345 |
|
| 346 |
private int[][] jumpToMidOrZero(int index, int maxJump, int lastA, int lastR)
|
|
| 346 |
private int[][] jumpToMidOrSolved(int index, int maxJump, int lastA, int lastR)
|
|
| 347 | 347 |
{
|
| 348 | 348 |
if( midTablesContain(index)>=0 ) return null; |
| 349 | 349 |
|
| 350 | 350 |
int[][] solution = new int[maxJump+1][4]; |
| 351 | 351 |
|
| 352 | 352 |
for(int i=1; i<=maxJump; i++) |
| 353 |
if( jumpMidZeroRecursive(index,i,1,lastA,lastR,solution) )
|
|
| 353 |
if( jumpMidSolvedRecursive(index,i,1,lastA,lastR,solution) )
|
|
| 354 | 354 |
{
|
| 355 | 355 |
solution[0][2] = i; |
| 356 | 356 |
return solution; |
| ... | ... | |
| 361 | 361 |
|
| 362 | 362 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 363 | 363 |
|
| 364 |
private boolean jumpZeroRecursive(int index, int jump, int depth, int lastA, int lastR, int[][] solution)
|
|
| 364 |
private boolean jumpToSolvedRecursive(int index, int jump, int depth, int lastA, int lastR, int[][] solution)
|
|
| 365 | 365 |
{
|
| 366 | 366 |
int[] quats = getQuats(index); |
| 367 | 367 |
int numQuats = quats.length; |
| ... | ... | |
| 398 | 398 |
} |
| 399 | 399 |
|
| 400 | 400 |
int childIndex = getIndex(tmp); |
| 401 |
if( childIndex==0 ) return true;
|
|
| 402 |
if( jump>1 && jumpZeroRecursive(childIndex, jump-1, depth+1, ax, layer, solution) ) return true;
|
|
| 401 |
if( isSolved(childIndex) ) return true;
|
|
| 402 |
if( jump>1 && jumpToSolvedRecursive(childIndex, jump-1, depth+1, ax, layer, solution) ) return true;
|
|
| 403 | 403 |
} |
| 404 | 404 |
|
| 405 | 405 |
getNextAxisLayerAngleQuat(move); |
| ... | ... | |
| 411 | 411 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 412 | 412 |
// ret: [0][] --> (numMoves,old depth,?,?) ; [1...N-1][] --> moves. |
| 413 | 413 |
|
| 414 |
private int[][] jumpToZero(int index, int maxJump, int lastA, int lastR)
|
|
| 414 |
private int[][] jumpToSolved(int index, int maxJump, int lastA, int lastR)
|
|
| 415 | 415 |
{
|
| 416 | 416 |
int[][] solution = new int[maxJump+1][4]; |
| 417 | 417 |
|
| 418 | 418 |
for(int i=1; i<=maxJump; i++) |
| 419 |
if( jumpZeroRecursive(index,i,1,lastA,lastR,solution) )
|
|
| 419 |
if( jumpToSolvedRecursive(index,i,1,lastA,lastR,solution) )
|
|
| 420 | 420 |
{
|
| 421 | 421 |
solution[0][0] = i; |
| 422 | 422 |
return solution; |
| ... | ... | |
| 464 | 464 |
} |
| 465 | 465 |
|
| 466 | 466 |
int maxJump = Math.max(mLowestHigh-1-mHighestMid,mLowestMid/2); |
| 467 |
int[][] jump1Moves = jumpToMidOrZero(index,maxJump,lastA,lastR);
|
|
| 467 |
int[][] jump1Moves = jumpToMidOrSolved(index,maxJump,lastA,lastR);
|
|
| 468 | 468 |
|
| 469 | 469 |
if( jump1Moves!=null ) |
| 470 | 470 |
{
|
| 471 |
if( jump1Moves[0][0]==0 )
|
|
| 471 |
if( isSolved(jump1Moves[0][0]) )
|
|
| 472 | 472 |
{
|
| 473 | 473 |
return concatenateMoves(null,jump1Moves,null,null); |
| 474 | 474 |
} |
| 475 | 475 |
if( jump1Moves[0][1]==mLowestMid ) |
| 476 | 476 |
{
|
| 477 |
int[][] jump2Moves = jumpToZero(index,mLowestMid-1,-1,0);
|
|
| 478 |
if( jump2Moves==null ) throw new RuntimeException("1 error jumping to 0");
|
|
| 477 |
int[][] jump2Moves = jumpToSolved(index,mLowestMid-1,-1,0);
|
|
| 478 |
if( jump2Moves==null ) throw new RuntimeException("1 error jumping to Solved");
|
|
| 479 | 479 |
return concatenateMoves(null,null,null,jump2Moves); |
| 480 | 480 |
} |
| 481 | 481 |
|
| ... | ... | |
| 495 | 495 |
} |
| 496 | 496 |
else throw new RuntimeException("error traversing mid Tables");
|
| 497 | 497 |
|
| 498 |
int[][] jump2Moves = jumpToZero(index,mLowestMid-1,lastA,lastR);
|
|
| 499 |
if( jump2Moves==null ) throw new RuntimeException("2 error jumping to 0");
|
|
| 498 |
int[][] jump2Moves = jumpToSolved(index,mLowestMid-1,lastA,lastR);
|
|
| 499 |
if( jump2Moves==null ) throw new RuntimeException("2 error jumping to Solved");
|
|
| 500 | 500 |
return concatenateMoves(highMoves,jump1Moves,midMoves,jump2Moves); |
| 501 | 501 |
} |
| 502 | 502 |
} |
Also available in: Unified diff
Dino6 solver: corrections to the pruning engine.