21 |
21 |
import androidx.preference.PreferenceManager;
|
22 |
22 |
|
23 |
23 |
import org.distorted.library.main.DistortedLibrary;
|
24 |
|
import org.distorted.library.type.Static3D;
|
25 |
|
import org.distorted.objectlib.algsolvers.PhaseMitm;
|
26 |
24 |
import org.distorted.objectlib.algsolvers.*;
|
|
25 |
import org.distorted.objectlib.algsolvers.implemented.Solver3x3Beginner;
|
27 |
26 |
import org.distorted.objectlib.main.InitAssets;
|
28 |
27 |
import org.distorted.objectlib.main.ObjectControl;
|
29 |
28 |
import org.distorted.objectlib.main.TwistyObject;
|
... | ... | |
39 |
38 |
private SolverLowerPane mLowerPane;
|
40 |
39 |
private TextView mText;
|
41 |
40 |
private SolvedObject mObject;
|
42 |
|
private int[][] mMoveTable;
|
43 |
|
private int[][] mBasicAngles;
|
44 |
41 |
private String mMoves;
|
45 |
42 |
private int mNumMoves;
|
|
43 |
private Solver3x3Beginner mBeginner;
|
46 |
44 |
|
47 |
45 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
46 |
|
... | ... | |
60 |
58 |
mText = findViewById(R.id.solverMoves);
|
61 |
59 |
mMoves = "";
|
62 |
60 |
mNumMoves = 0;
|
|
61 |
|
|
62 |
mBeginner = new Solver3x3Beginner();
|
|
63 |
mObject = mBeginner.getObject();
|
63 |
64 |
}
|
64 |
65 |
|
65 |
66 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
133 |
134 |
|
134 |
135 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
136 |
|
136 |
|
private void solve(SolverPhased ps, int[] quats)
|
|
137 |
private void solve(int[] quats)
|
137 |
138 |
{
|
138 |
|
int[][] sol = ps.solution(quats);
|
|
139 |
int[][] sol = mBeginner.solution(quats);
|
139 |
140 |
int numPhases = sol.length;
|
140 |
141 |
int totalLength = 0;
|
141 |
142 |
|
... | ... | |
163 |
164 |
for(int m=1; m<=numMoves; m++)
|
164 |
165 |
{
|
165 |
166 |
int mi = s[m];
|
166 |
|
moves[index++] = mMoveTable[mi];
|
167 |
|
// android.util.Log.e("D","move "+m+" : "+mMoveTable[mi][0]+" "+mMoveTable[mi][1]+" "+mMoveTable[mi][2]);
|
|
167 |
moves[index++] = mObject.findMove(mi);
|
168 |
168 |
}
|
169 |
169 |
}
|
170 |
170 |
|
171 |
171 |
mLowerPane.setMoves(this,moves);
|
172 |
172 |
}
|
173 |
173 |
|
174 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175 |
|
|
176 |
|
private void createObject()
|
177 |
|
{
|
178 |
|
TwistyObject object = getControl().getObject();
|
179 |
|
|
180 |
|
int[] numL = object.getNumLayers();
|
181 |
|
float[][] pos = object.getCubitPositions(numL);
|
182 |
|
Static3D[] axis = object.getRotationAxis();
|
183 |
|
int[][] angles = object.getBasicAngles();
|
184 |
|
float[][] cuts = object.getCuts(numL);
|
185 |
|
|
186 |
|
boolean[] r = {true,false,true};
|
187 |
|
boolean[][] rot = {r,r,r};//object.getLayerRotatable(numL);
|
188 |
|
|
189 |
|
mObject = new SolvedObject(pos,axis,angles,cuts,rot);
|
190 |
|
mMoveTable = mObject.getMoveTable();
|
191 |
|
mBasicAngles = angles;
|
192 |
|
}
|
193 |
|
|
194 |
174 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195 |
175 |
|
196 |
176 |
public void Solve(View v)
|
197 |
177 |
{
|
198 |
|
if( mObject==null ) createObject();
|
199 |
|
int[][] moveTable = mObject.getMoveTable();
|
200 |
|
|
201 |
178 |
TwistyObject object = getControl().getObject();
|
202 |
|
int[] numL = object.getNumLayers();
|
203 |
|
float[][] pos = object.getCubitPositions(numL);
|
204 |
|
int numCubits = pos.length;
|
|
179 |
int numCubits = 26;
|
205 |
180 |
int[] qi = new int[numCubits];
|
206 |
181 |
for(int i=0; i<numCubits; i++) qi[i] = object.getCubitQuatIndex(i);
|
207 |
182 |
|
208 |
|
int[][] whiteCross = new int[][]{ {12,13,16,17} };
|
209 |
|
int[][] whiteCorners = new int[][]{ {0},{1},{2},{3} };
|
210 |
|
int[][] secondLayer = new int[][]{ {8},{9},{10},{11} };
|
211 |
|
|
212 |
|
String a1 = "(3){-1,0,1,2}(6,3,8,3,15,5,17)";
|
213 |
|
String a2 = "(3){-1,0,1,2}(15,5,17,5,6,3,8)";
|
214 |
|
String a3 = "(3){-1,0,1,2}(12,3,14,3,8,5,6)";
|
215 |
|
String a4 = "(3){-1,0,1,2}(8,5,6,5,12,3,14)";
|
216 |
|
String a5 = "(3){-1,0,1,2}(11,3,9,3,14,5,12)";
|
217 |
|
String a6 = "(3){-1,0,1,2}(14,5,12,5,11,3,9)";
|
218 |
|
String a7 = "(3){-1,0,1,2}(17,3,15,3,9,5,11)";
|
219 |
|
String a8 = "(3){-1,0,1,2}(9,5,11,5,17,3,15)";
|
220 |
|
|
221 |
|
MoveProviderAll all = new MoveProviderAll(moveTable);
|
222 |
|
MoveProviderAlgs asl = new MoveProviderAlgs(mObject, "["+a1+";"+a2+";"+a3+";"+a4+";"+a5+";"+a6+";"+a7+";"+a8+"]");
|
223 |
|
MoveProviderAlgs aeO = new MoveProviderAlgs(mObject, "(3){-1,0,1,2}(11,17,5,15,3,9)");
|
224 |
|
MoveProviderAlgs aeP = new MoveProviderAlgs(mObject, "(3){-1,0,1,2}(6,5,8,5,6,4,8){0,1}");
|
225 |
|
MoveProviderAlgs acP = new MoveProviderAlgs(mObject, "(3){-1,0,1,2}(5,6,3,9,5,8,3,11){0,1}");
|
226 |
|
MoveProviderAlgs acO = new MoveProviderAlgs(mObject, "(3){-1,0,1,2}(15,2,17,0){-2,0,2}");
|
227 |
|
|
228 |
|
TargetProvider wcr = new TargetProviderAll(whiteCross);
|
229 |
|
TargetProvider wco = new TargetProviderAll(whiteCorners);
|
230 |
|
TargetProvider sla = new TargetProviderAll(secondLayer);
|
231 |
|
TargetProvider oll = new TargetProviderOrie(mObject,14,1);
|
232 |
|
TargetProvider pll = new TargetProviderPerm(mObject,14,1);
|
233 |
|
TargetProvider pcl = new TargetProviderPerm(mObject, 4,1);
|
234 |
|
TargetProvider ocl = new TargetProviderOrie(mObject, 4,1);
|
235 |
|
|
236 |
|
Phase[] phases =
|
237 |
|
{
|
238 |
|
new PhaseMitm( mObject, all, wcr),
|
239 |
|
new PhaseMitm( mObject, all, wco),
|
240 |
|
new PhaseMitm( mObject, asl, sla),
|
241 |
|
new PhaseMitm( mObject, aeO, oll),
|
242 |
|
new PhaseMitm( mObject, aeP, pll),
|
243 |
|
new PhaseMitm( mObject, acP, pcl),
|
244 |
|
new PhaseMitm( mObject, acO, ocl),
|
245 |
|
};
|
246 |
|
|
247 |
|
SolverPhased ps = new SolverPhased(mObject,phases);
|
248 |
|
|
249 |
183 |
runOnUiThread(new Runnable()
|
250 |
184 |
{
|
251 |
185 |
@Override
|
252 |
186 |
public void run()
|
253 |
187 |
{
|
254 |
|
solve(ps,qi);
|
|
188 |
solve(qi);
|
255 |
189 |
}
|
256 |
190 |
});
|
257 |
191 |
}
|
... | ... | |
269 |
203 |
mText.setText(mMoves);
|
270 |
204 |
}
|
271 |
205 |
|
272 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
273 |
|
|
274 |
|
int findMove(int ax, int row, int angle)
|
275 |
|
{
|
276 |
|
int num = mMoveTable.length;
|
277 |
|
int basicAngle = mBasicAngles[ax][row];
|
278 |
|
|
279 |
|
for( int m=0; m<num; m++)
|
280 |
|
{
|
281 |
|
int[] move = mMoveTable[m];
|
282 |
|
if( ax==move[0] && row==move[1] && ((angle-move[2])%basicAngle)==0 ) return m;
|
283 |
|
}
|
284 |
|
|
285 |
|
return -1;
|
286 |
|
}
|
287 |
|
|
288 |
206 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
289 |
207 |
|
290 |
208 |
void addMove(int axis, int row, int angle)
|
291 |
209 |
{
|
292 |
|
if( mObject==null ) createObject();
|
293 |
|
int move = findMove(axis,row,angle);
|
|
210 |
int move = mObject.findMove(axis,row,angle);
|
294 |
211 |
mMoves += (" "+move);
|
295 |
212 |
mNumMoves++;
|
296 |
213 |
|
297 |
214 |
if( mNumMoves>10 )
|
298 |
215 |
{
|
299 |
216 |
int space = mMoves.indexOf(' ');
|
300 |
|
mMoves = mMoves.substring(space+2);
|
|
217 |
mMoves = mMoves.substring(space+1);
|
301 |
218 |
mNumMoves--;
|
302 |
219 |
}
|
303 |
220 |
|
Abstract out Solver3x3Beginner - the first implemented Phased Solver.