Revision 026120ee
Added by Leszek Koltunski 9 months ago
src/main/java/org/distorted/objectlib/algsolvers/MitmTable.java | ||
---|---|---|
160 | 160 |
|
161 | 161 |
while( move!=null ) |
162 | 162 |
{ |
163 |
for(int m : move) object.makeMove(m);
|
|
163 |
object.makeMoves(move);
|
|
164 | 164 |
buildRecursive(object,provider,mv,depth-1); |
165 |
for(int m : move) object.backMove(m);
|
|
165 |
object.backMoves(move);
|
|
166 | 166 |
mv = provider.nextPointer(previousMove); |
167 | 167 |
move = provider.getCurrent(); |
168 | 168 |
} |
... | ... | |
227 | 227 |
|
228 | 228 |
while( move!=null ) |
229 | 229 |
{ |
230 |
for(int m : move) object.backMove(m);
|
|
230 |
object.backMoves(move);
|
|
231 | 231 |
byte[] reached = tryReachingRecursive(object,provider,len-1,ret); |
232 |
for(int m : move) object.makeMove(m);
|
|
232 |
object.makeMoves(move);
|
|
233 | 233 |
|
234 | 234 |
if( reached!=null ) |
235 | 235 |
{ |
... | ... | |
263 | 263 |
|
264 | 264 |
while( move!=null ) |
265 | 265 |
{ |
266 |
for(int m : move) object.makeMove(m);
|
|
266 |
object.makeMoves(move);
|
|
267 | 267 |
int numMoves = reachForwardRecursive(object,provider,quats,ret,1,len-1); |
268 |
for(int m : move) object.backMove(m);
|
|
268 |
object.backMoves(move);
|
|
269 | 269 |
|
270 | 270 |
if( numMoves>=0 ) |
271 | 271 |
{ |
... | ... | |
300 | 300 |
|
301 | 301 |
while( move!=null ) |
302 | 302 |
{ |
303 |
for(int m : move) object.makeMove(m);
|
|
303 |
object.makeMoves(move);
|
|
304 | 304 |
int numMoves = reachForwardRecursive(object,provider,quats,ret,index+1,len-1); |
305 |
for(int m : move) object.backMove(m);
|
|
305 |
object.backMoves(move);
|
|
306 | 306 |
|
307 | 307 |
if( numMoves>=0 ) |
308 | 308 |
{ |
src/main/java/org/distorted/objectlib/algsolvers/MoveProvider.java | ||
---|---|---|
35 | 35 |
abstract int firstPointer(int previousMove); |
36 | 36 |
abstract int nextPointer(int previousMove); |
37 | 37 |
abstract int[] getCurrent(); |
38 |
abstract int[] substitute(int[] moves); |
|
38 | 39 |
} |
src/main/java/org/distorted/objectlib/algsolvers/MoveProviderAlgs.java | ||
---|---|---|
23 | 23 |
mAlgorithms = algorithms; |
24 | 24 |
} |
25 | 25 |
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
int[] substitute(int[] moves) |
|
29 |
{ |
|
30 |
int len = 0; |
|
31 |
int mvl = moves.length; |
|
32 |
for(int m=1; m<mvl; m++) len += mAlgorithms[moves[m]].length; |
|
33 |
int[] ret = new int[1+len]; |
|
34 |
ret[0] = len; |
|
35 |
int index = 1; |
|
36 |
|
|
37 |
for(int m=1; m<mvl; m++) |
|
38 |
for( int a : mAlgorithms[moves[m]] ) |
|
39 |
ret[index++] = a; |
|
40 |
|
|
41 |
return ret; |
|
42 |
} |
|
43 |
|
|
26 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 45 |
|
28 | 46 |
int firstPointer(int previousMove) |
src/main/java/org/distorted/objectlib/algsolvers/MoveProviderAll.java | ||
---|---|---|
23 | 23 |
mMoveTable = moveTable; |
24 | 24 |
} |
25 | 25 |
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
int[] substitute(int[] moves) |
|
29 |
{ |
|
30 |
return moves; |
|
31 |
} |
|
32 |
|
|
26 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 34 |
// moves clash iff they are both along the same axis and the same row |
28 | 35 |
|
src/main/java/org/distorted/objectlib/algsolvers/Phase.java | ||
---|---|---|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
mTargetQuats = new TargetQuats(target); |
79 |
|
|
80 |
android.util.Log.e("D", "target quats: "+mTargetQuats.debug() ); |
|
79 | 81 |
} |
80 | 82 |
|
81 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/algsolvers/PhaseMitm.java | ||
---|---|---|
94 | 94 |
mForwardDepth = computeForwardDepth(bytesPerEntry,branchingFactor); |
95 | 95 |
mBackwardDepth = computeBackwardDepth(branchingFactor); |
96 | 96 |
|
97 |
android.util.Log.e("D", "forward depth: "+mForwardDepth+" backward depth: "+mBackwardDepth); |
|
98 |
|
|
97 | 99 |
return mForwardDepth+mBackwardDepth; |
98 | 100 |
} |
99 | 101 |
|
... | ... | |
147 | 149 |
|
148 | 150 |
if( solution!=null ) |
149 | 151 |
{ |
150 |
int[] simplified = removeRedundantMoves(solution); |
|
152 |
android.util.Log.e("D", "PHASE SOLVED"); |
|
153 |
android.util.Log.e("D", "sol: "+MitmTable.getQuatString(solution) ); |
|
154 |
|
|
155 |
int[] substituted= mMoveProvider.substitute(solution); |
|
156 |
|
|
157 |
android.util.Log.e("D", "sub: "+MitmTable.getQuatString(substituted) ); |
|
158 |
|
|
159 |
int[] simplified = removeRedundantMoves(substituted); |
|
151 | 160 |
int len = simplified.length; |
152 | 161 |
for(int m=1; m<len; m++) object.makeMove(simplified[m]); |
153 | 162 |
return simplified; |
src/main/java/org/distorted/objectlib/algsolvers/SolvedObject.java | ||
---|---|---|
65 | 65 |
int invertMove(int moveIndex) { return mMoveInterts[moveIndex]; } |
66 | 66 |
Static4D[] getQuats() { return mQuats; } |
67 | 67 |
float[][] getCubitPositions() { return mOrigPos; } |
68 |
//int getBranchingFactor() { return mBranchingFactor; } |
|
69 | 68 |
int getMultQuat(int index1, int index2) { return mQuatMult[index1][index2]; } |
70 | 69 |
int[][] getBasicAngles() { return mBasicAngles; } |
71 | 70 |
|
... | ... | |
74 | 73 |
void setUpStartingQuats(int[] quats) { mCubits.setUpQuats(quats); } |
75 | 74 |
void makeMove(int moveIndex) { mCubits.makeMove(moveIndex); } |
76 | 75 |
void backMove(int moveIndex) { mCubits.backMove(moveIndex); } |
76 |
void makeMoves(int[] moves) { mCubits.makeMoves(moves); } |
|
77 |
void backMoves(int[] moves) { mCubits.backMoves(moves); } |
|
77 | 78 |
int[] getCubitQuats() { return mCubits.getRotQuats(); } |
78 | 79 |
String debug(int cubit) { return mCubits.debug(cubit); } |
79 | 80 |
|
src/main/java/org/distorted/objectlib/algsolvers/SolvedObjectCubit.java | ||
---|---|---|
138 | 138 |
rotateAllCubits(axisIndex,row,quatIndex); |
139 | 139 |
} |
140 | 140 |
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
void makeMoves(int[] moves) |
|
144 |
{ |
|
145 |
int len = moves.length; |
|
146 |
for(int m=0; m<len; m++) makeMove(moves[m]); |
|
147 |
} |
|
148 |
|
|
149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 |
|
|
151 |
void backMoves(int[] moves) |
|
152 |
{ |
|
153 |
int len = moves.length; |
|
154 |
for(int m=len-1; m>=0; m--) backMove(moves[m]); |
|
155 |
} |
|
156 |
|
|
141 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 158 |
|
143 | 159 |
void setUpQuats(int[] quats) |
src/main/java/org/distorted/objectlib/algsolvers/TargetProviderOrie.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.algsolvers; |
11 | 11 |
|
12 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
13 |
|
|
14 | 12 |
import org.distorted.library.helpers.QuatHelper; |
15 | 13 |
import org.distorted.library.type.Static4D; |
16 | 14 |
|
15 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
16 |
|
|
17 | 17 |
public class TargetProviderOrie extends TargetProvider |
18 | 18 |
{ |
19 | 19 |
private final int[][] mSubgroups; |
20 |
private final Static4D[] mObjectQuats; |
|
21 |
private final float[][] mPositions; |
|
20 |
private final int mNumCubitsInThisPhase; |
|
21 |
private final int mCyclicQuat; |
|
22 |
private final SolvedObject mObject; |
|
22 | 23 |
|
23 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
24 | 25 |
|
25 | 26 |
public TargetProviderOrie(SolvedObject object, int cubit, int quat) |
26 | 27 |
{ |
28 |
mObject = object; |
|
27 | 29 |
Static4D[] objectQuats = object.getQuats(); |
28 | 30 |
Static4D q = objectQuats[quat]; |
29 | 31 |
double alpha = 2*Math.acos(q.get3()); |
30 | 32 |
double numTurns = 2*Math.PI / alpha; |
31 |
int numCubits = (int)(numTurns+0.5f); |
|
33 |
mNumCubitsInThisPhase = (int)(numTurns+0.5f); |
|
34 |
mCyclicQuat = quat; |
|
32 | 35 |
|
33 |
mSubgroups = new int[1][numCubits]; |
|
34 |
mObjectQuats = objectQuats; |
|
36 |
mSubgroups = new int[1][mNumCubitsInThisPhase]; |
|
35 | 37 |
|
36 |
mPositions = object.getCubitPositions();
|
|
37 |
float[] pos = mPositions[cubit];
|
|
38 |
float[][] positions = object.getCubitPositions();
|
|
39 |
float[] pos = positions[cubit];
|
|
38 | 40 |
float x = pos[0]; |
39 | 41 |
float y = pos[1]; |
40 | 42 |
float z = pos[2]; |
... | ... | |
43 | 45 |
|
44 | 46 |
mSubgroups[0][0] = cubit; |
45 | 47 |
|
46 |
for(int c=1; c<numCubits; c++)
|
|
48 |
for(int c=1; c<mNumCubitsInThisPhase; c++)
|
|
47 | 49 |
{ |
48 | 50 |
QuatHelper.rotateVectorByQuat(tmp,x,y,z,1,q); |
49 | 51 |
x = tmp[0]; |
50 | 52 |
y = tmp[1]; |
51 | 53 |
z = tmp[2]; |
52 | 54 |
|
53 |
mSubgroups[0][c] = whichPosIsThis(mPositions,tmp);
|
|
55 |
mSubgroups[0][c] = whichPosIsThis(positions,tmp);
|
|
54 | 56 |
} |
55 | 57 |
} |
56 | 58 |
|
... | ... | |
65 | 67 |
|
66 | 68 |
int[] provideTarget(int cubit) |
67 | 69 |
{ |
68 |
float[] thisPos = mPositions[cubit]; |
|
69 |
int numQuats = mObjectQuats.length; |
|
70 |
int numGoodQuats = 0; |
|
71 |
int[] tmpQuats = new int[numQuats]; |
|
72 |
float[] tmp = new float[4]; |
|
73 |
float x = thisPos[0]; |
|
74 |
float y = thisPos[1]; |
|
75 |
float z = thisPos[2]; |
|
76 |
final float MAX_ERROR = 0.01f; |
|
70 |
int[] retQuats = new int[mNumCubitsInThisPhase]; |
|
71 |
retQuats[0] = 0; |
|
72 |
retQuats[1] = mCyclicQuat; |
|
77 | 73 |
|
78 |
for(int q=0; q<numQuats; q++)
|
|
74 |
for(int i=2; i<mNumCubitsInThisPhase; i++)
|
|
79 | 75 |
{ |
80 |
QuatHelper.rotateVectorByQuat(tmp,x,y,z,1,mObjectQuats[q]); |
|
81 |
|
|
82 |
float dx = tmp[0] - x; |
|
83 |
float dy = tmp[1] - y; |
|
84 |
float dz = tmp[2] - z; |
|
85 |
float err = dx*dx + dy*dy + dz*dz; |
|
86 |
|
|
87 |
if( err < MAX_ERROR ) |
|
88 |
{ |
|
89 |
numGoodQuats++; |
|
90 |
tmpQuats[q] = 1; |
|
91 |
} |
|
76 |
retQuats[i] = mObject.getMultQuat(mCyclicQuat,retQuats[i-1]); |
|
92 | 77 |
} |
93 | 78 |
|
94 |
int[] ret = new int[numGoodQuats]; |
|
95 |
int index = 0; |
|
96 |
|
|
97 |
for(int q=0; q<numQuats; q++) |
|
98 |
if( tmpQuats[q]==1 ) ret[index++] = q; |
|
99 |
|
|
100 |
return ret; |
|
79 |
return retQuats; |
|
101 | 80 |
} |
102 | 81 |
|
103 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/algsolvers/TargetProviderPerm.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.algsolvers; |
11 | 11 |
|
12 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
13 |
|
|
12 | 14 |
import org.distorted.library.helpers.QuatHelper; |
13 | 15 |
import org.distorted.library.type.Static4D; |
14 | 16 |
|
15 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
16 |
|
|
17 | 17 |
public class TargetProviderPerm extends TargetProvider |
18 | 18 |
{ |
19 | 19 |
private final int[][] mSubgroups; |
20 |
private final int mNumCubitsInThisPhase; |
|
21 |
private final int mCyclicQuat; |
|
22 |
private final SolvedObject mObject; |
|
20 |
private final Static4D[] mObjectQuats; |
|
21 |
private final float[][] mPositions; |
|
23 | 22 |
|
24 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 24 |
|
26 | 25 |
public TargetProviderPerm(SolvedObject object, int cubit, int quat) |
27 | 26 |
{ |
28 |
mObject = object; |
|
29 | 27 |
Static4D[] objectQuats = object.getQuats(); |
30 | 28 |
Static4D q = objectQuats[quat]; |
31 | 29 |
double alpha = 2*Math.acos(q.get3()); |
32 | 30 |
double numTurns = 2*Math.PI / alpha; |
33 |
mNumCubitsInThisPhase = (int)(numTurns+0.5f); |
|
34 |
mCyclicQuat = quat; |
|
31 |
int numCubits = (int)(numTurns+0.5f); |
|
35 | 32 |
|
36 |
mSubgroups = new int[1][mNumCubitsInThisPhase]; |
|
33 |
mSubgroups = new int[1][numCubits]; |
|
34 |
mObjectQuats = objectQuats; |
|
37 | 35 |
|
38 |
float[][] positions = object.getCubitPositions();
|
|
39 |
float[] pos = positions[cubit];
|
|
36 |
mPositions = object.getCubitPositions();
|
|
37 |
float[] pos = mPositions[cubit];
|
|
40 | 38 |
float x = pos[0]; |
41 | 39 |
float y = pos[1]; |
42 | 40 |
float z = pos[2]; |
... | ... | |
45 | 43 |
|
46 | 44 |
mSubgroups[0][0] = cubit; |
47 | 45 |
|
48 |
for(int c=1; c<mNumCubitsInThisPhase; c++)
|
|
46 |
for(int c=1; c<numCubits; c++)
|
|
49 | 47 |
{ |
50 | 48 |
QuatHelper.rotateVectorByQuat(tmp,x,y,z,1,q); |
51 | 49 |
x = tmp[0]; |
52 | 50 |
y = tmp[1]; |
53 | 51 |
z = tmp[2]; |
54 | 52 |
|
55 |
mSubgroups[0][c] = whichPosIsThis(positions,tmp);
|
|
53 |
mSubgroups[0][c] = whichPosIsThis(mPositions,tmp);
|
|
56 | 54 |
} |
57 | 55 |
} |
58 | 56 |
|
... | ... | |
67 | 65 |
|
68 | 66 |
int[] provideTarget(int cubit) |
69 | 67 |
{ |
70 |
int[] retQuats = new int[mNumCubitsInThisPhase]; |
|
71 |
retQuats[0] = 0; |
|
72 |
retQuats[1] = mCyclicQuat; |
|
68 |
float[] thisPos = mPositions[cubit]; |
|
69 |
int numQuats = mObjectQuats.length; |
|
70 |
int numGoodQuats = 0; |
|
71 |
int[] tmpQuats = new int[numQuats]; |
|
72 |
float[] tmp = new float[4]; |
|
73 |
float x = thisPos[0]; |
|
74 |
float y = thisPos[1]; |
|
75 |
float z = thisPos[2]; |
|
76 |
final float MAX_ERROR = 0.01f; |
|
73 | 77 |
|
74 |
for(int i=2; i<mNumCubitsInThisPhase; i++)
|
|
78 |
for(int q=0; q<numQuats; q++)
|
|
75 | 79 |
{ |
76 |
retQuats[i] = mObject.getMultQuat(mCyclicQuat,retQuats[i-1]); |
|
80 |
QuatHelper.rotateVectorByQuat(tmp,x,y,z,1,mObjectQuats[q]); |
|
81 |
|
|
82 |
float dx = tmp[0] - x; |
|
83 |
float dy = tmp[1] - y; |
|
84 |
float dz = tmp[2] - z; |
|
85 |
float err = dx*dx + dy*dy + dz*dz; |
|
86 |
|
|
87 |
if( err < MAX_ERROR ) |
|
88 |
{ |
|
89 |
numGoodQuats++; |
|
90 |
tmpQuats[q] = 1; |
|
91 |
} |
|
77 | 92 |
} |
78 | 93 |
|
79 |
return retQuats; |
|
94 |
int[] ret = new int[numGoodQuats]; |
|
95 |
int index = 0; |
|
96 |
|
|
97 |
for(int q=0; q<numQuats; q++) |
|
98 |
if( tmpQuats[q]==1 ) ret[index++] = q; |
|
99 |
|
|
100 |
return ret; |
|
80 | 101 |
} |
81 | 102 |
|
82 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/algsolvers/TargetQuats.java | ||
---|---|---|
133 | 133 |
for(int i=mIndices.length-1; i>=0; i--) |
134 | 134 |
{ |
135 | 135 |
int[] q = mEndQuats[i]; |
136 |
int len = q!=null ? q.length-1 : 0; |
|
137 | 136 |
|
138 |
if( mIndices[i]<len )
|
|
137 |
if( mIndices[i] < (q!=null ? q.length-1 : 0) )
|
|
139 | 138 |
{ |
140 | 139 |
mIndices[i]++; |
141 | 140 |
return true; |
142 | 141 |
} |
142 |
else mIndices[i]=0; |
|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
return false; |
Also available in: Unified diff
Fixes. OLL (edges) works now, PLL (edges) still does not.