246 |
246 |
int numInserted;
|
247 |
247 |
byte insertingLevel = 0;
|
248 |
248 |
|
|
249 |
android.util.Log.e("D", "creating tablebase of size "+mSize);
|
|
250 |
|
249 |
251 |
do
|
250 |
252 |
{
|
251 |
253 |
numInserted = 0;
|
... | ... | |
262 |
264 |
}
|
263 |
265 |
while( numInserted>0 );
|
264 |
266 |
|
|
267 |
android.util.Log.e("D", "packing...");
|
265 |
268 |
mTablebase.pack();
|
|
269 |
android.util.Log.e("D", "all done");
|
|
270 |
}
|
|
271 |
|
|
272 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
273 |
|
|
274 |
public byte[] getPacked()
|
|
275 |
{
|
|
276 |
return mTablebase.getPacked();
|
266 |
277 |
}
|
267 |
278 |
|
268 |
279 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
277 |
288 |
moves.add(move);
|
278 |
289 |
}
|
279 |
290 |
|
|
291 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
292 |
|
|
293 |
private void addMove(int[] moves, int axis, int layer, int angle)
|
|
294 |
{
|
|
295 |
int maxAngle = mAngles[axis][layer];
|
|
296 |
angle = maxAngle-angle;
|
|
297 |
if( angle> 0.5f*maxAngle ) angle -= maxAngle;
|
|
298 |
|
|
299 |
moves[0] = axis;
|
|
300 |
moves[1] = (1<<layer);
|
|
301 |
moves[2] = angle;
|
|
302 |
}
|
|
303 |
|
280 |
304 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281 |
305 |
|
282 |
306 |
private int[][] convertMoves(ArrayList<int[]> moves)
|
... | ... | |
365 |
389 |
|
366 |
390 |
return convertMoves(moves);
|
367 |
391 |
}
|
|
392 |
|
|
393 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
394 |
// not working yet
|
|
395 |
|
|
396 |
public int[][] scramble(int depth)
|
|
397 |
{
|
|
398 |
int[][] moves = new int[depth][3];
|
|
399 |
int quatBasis = 0;
|
|
400 |
int level=0;
|
|
401 |
int[] quats = getQuats(0);
|
|
402 |
int numQuats = quats.length;
|
|
403 |
int[] tmpQuats = new int[numQuats];
|
|
404 |
boolean[] belongs = new boolean[mNumCubits];
|
|
405 |
|
|
406 |
while(level<depth)
|
|
407 |
{
|
|
408 |
boolean found = false;
|
|
409 |
|
|
410 |
for(int ax=0; ax<mNumAxis; ax++)
|
|
411 |
{
|
|
412 |
int numLayers = mNumLayers[ax];
|
|
413 |
int[] angles = mAngles[ax];
|
|
414 |
|
|
415 |
for(int layer=0; layer<numLayers; layer++)
|
|
416 |
{
|
|
417 |
if( !mRotatable[ax][layer] ) continue;
|
|
418 |
int bitLayer = (1<<layer);
|
|
419 |
|
|
420 |
for(int cubit=0; cubit<mNumCubits; cubit++)
|
|
421 |
{
|
|
422 |
mRotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
|
|
423 |
belongs[cubit] = belongsToMove(cubit,ax,bitLayer);
|
|
424 |
}
|
|
425 |
|
|
426 |
int maxAngle = angles[layer];
|
|
427 |
|
|
428 |
for(int angle=1; angle<maxAngle; angle++ )
|
|
429 |
{
|
|
430 |
System.arraycopy(quats, 0, tmpQuats, 0, numQuats);
|
|
431 |
int quat = quatBasis + angle;
|
|
432 |
|
|
433 |
for(int cubit=0; cubit<mNumCubits; cubit++)
|
|
434 |
if( belongs[cubit] )
|
|
435 |
{
|
|
436 |
int currQuat = tmpQuats[cubit];
|
|
437 |
int newQuat = getMultQuat(quat,currQuat);
|
|
438 |
tmpQuats[cubit] = newQuat;
|
|
439 |
}
|
|
440 |
|
|
441 |
int childIndex = getIndex(tmpQuats);
|
|
442 |
byte newLevel = mTablebase.retrievePacked(childIndex);
|
|
443 |
|
|
444 |
if( ((newLevel-level-1)%3) == 0 )
|
|
445 |
{
|
|
446 |
addMove(moves[level],ax,layer,angle);
|
|
447 |
angle=maxAngle;
|
|
448 |
layer=numLayers;
|
|
449 |
ax=mNumAxis;
|
|
450 |
quatBasis = 0;
|
|
451 |
quats = getQuats(childIndex);
|
|
452 |
level++;
|
|
453 |
found = true;
|
|
454 |
}
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
quatBasis += (angles[0]-1);
|
|
459 |
}
|
|
460 |
|
|
461 |
if( !found )
|
|
462 |
{
|
|
463 |
// error, no move found which would move us 1 step further
|
|
464 |
return null;
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
return moves;
|
|
469 |
}
|
368 |
470 |
}
|
add ability to create tablebases.