15 |
15 |
import android.content.SharedPreferences;
|
16 |
16 |
import android.os.Bundle;
|
17 |
17 |
import android.view.View;
|
|
18 |
import android.widget.TextView;
|
18 |
19 |
import android.widget.Toast;
|
19 |
20 |
|
20 |
21 |
import androidx.preference.PreferenceManager;
|
... | ... | |
40 |
41 |
private InitAssets mAsset;
|
41 |
42 |
private SharedPreferences mPreferences;
|
42 |
43 |
private SolverLowerPane mLowerPane;
|
43 |
|
|
|
44 |
private TextView mText;
|
|
45 |
private SolvedObject mObject;
|
|
46 |
private int[][] mMoveTable;
|
|
47 |
private String mMoves;
|
44 |
48 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
49 |
|
46 |
50 |
@Override
|
... | ... | |
54 |
58 |
OSInterface os = view.getInterface();
|
55 |
59 |
mAsset = new InitAssets(null, null, os);
|
56 |
60 |
mLowerPane = new SolverLowerPane(this);
|
|
61 |
mText = findViewById(R.id.solverMoves);
|
|
62 |
mMoves = "";
|
57 |
63 |
}
|
58 |
64 |
|
59 |
65 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
127 |
133 |
|
128 |
134 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
135 |
|
130 |
|
private void solve(PhasedSolver ps, int[] quats, int[][] moveTable)
|
|
136 |
private void solve(PhasedSolver ps, int[] quats)
|
131 |
137 |
{
|
132 |
138 |
int[][] sol = ps.solution(quats);
|
133 |
139 |
int numPhases = sol.length;
|
... | ... | |
157 |
163 |
for(int m=1; m<=numMoves; m++)
|
158 |
164 |
{
|
159 |
165 |
int mi = s[m];
|
160 |
|
moves[index++] = moveTable[mi];
|
161 |
|
android.util.Log.e("D","move "+m+" : "+moveTable[mi][0]+" "+moveTable[mi][1]+" "+moveTable[mi][2]);
|
|
166 |
moves[index++] = mMoveTable[mi];
|
|
167 |
android.util.Log.e("D","move "+m+" : "+mMoveTable[mi][0]+" "+mMoveTable[mi][1]+" "+mMoveTable[mi][2]);
|
162 |
168 |
}
|
163 |
169 |
}
|
164 |
170 |
|
... | ... | |
167 |
173 |
|
168 |
174 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169 |
175 |
|
170 |
|
public void Solve(View v)
|
|
176 |
private void createObject()
|
171 |
177 |
{
|
172 |
178 |
TwistyObject object = getControl().getObject();
|
173 |
179 |
|
... | ... | |
180 |
186 |
boolean[] r = {true,false,true};
|
181 |
187 |
boolean[][] rot = {r,r,r};//object.getLayerRotatable(numL);
|
182 |
188 |
|
183 |
|
SolvedObject so = new SolvedObject(pos,axis,angles,cuts,rot);
|
|
189 |
mObject = new SolvedObject(pos,axis,angles,cuts,rot);
|
|
190 |
mMoveTable = mObject.getMoveTable();
|
|
191 |
}
|
|
192 |
|
|
193 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
194 |
|
|
195 |
public void Solve(View v)
|
|
196 |
{
|
|
197 |
if( mObject==null ) createObject();
|
|
198 |
|
|
199 |
TwistyObject object = getControl().getObject();
|
|
200 |
int[] numL = object.getNumLayers();
|
|
201 |
float[][] pos = object.getCubitPositions(numL);
|
|
202 |
|
184 |
203 |
int numCubits = pos.length;
|
185 |
204 |
int[] qi = new int[numCubits];
|
186 |
205 |
for(int i=0; i<numCubits; i++) qi[i] = object.getCubitQuatIndex(i);
|
187 |
206 |
|
188 |
|
int[][] moves = so.getMoveTable();
|
189 |
|
|
190 |
207 |
int[][] whiteCross = new int[][]{ {12,13,16,17} };
|
191 |
208 |
int[][] whiteCorners = new int[][]{ {0},{1},{2},{3} };
|
192 |
209 |
int[][] secondLayer = new int[][]{ {8},{9},{10},{11} };
|
... | ... | |
203 |
220 |
|
204 |
221 |
Phase[] phases =
|
205 |
222 |
{
|
206 |
|
new PhaseNotCyclic( so, whiteCross),
|
207 |
|
new PhaseNotCyclic( so, whiteCorners),
|
208 |
|
new PhaseNotCyclic( so, secondLayer),
|
209 |
|
new PhaseCyclicOrie1( so, yellowCrossCubit , yellowCrossQuat ),
|
210 |
|
new PhaseCyclicPerm2( so, yellowCrossCubit , yellowCrossQuat ),
|
211 |
|
new PhaseRegex( so, regex, yellowCorners ),
|
|
223 |
new PhaseNotCyclic( mObject, whiteCross),
|
|
224 |
new PhaseNotCyclic( mObject, whiteCorners),
|
|
225 |
new PhaseNotCyclic( mObject, secondLayer),
|
|
226 |
new PhaseCyclicOrie1( mObject, yellowCrossCubit , yellowCrossQuat ),
|
|
227 |
new PhaseCyclicPerm2( mObject, yellowCrossCubit , yellowCrossQuat ),
|
|
228 |
new PhaseRegex( mObject, regex, yellowCorners ),
|
212 |
229 |
};
|
213 |
230 |
|
214 |
|
PhasedSolver ps = new PhasedSolver(so,phases);
|
|
231 |
PhasedSolver ps = new PhasedSolver(mObject,phases);
|
215 |
232 |
|
216 |
233 |
runOnUiThread(new Runnable()
|
217 |
234 |
{
|
218 |
235 |
@Override
|
219 |
236 |
public void run()
|
220 |
237 |
{
|
221 |
|
solve(ps,qi,moves);
|
|
238 |
solve(ps,qi);
|
222 |
239 |
}
|
223 |
240 |
});
|
224 |
241 |
}
|
... | ... | |
230 |
247 |
ObjectControl control = getControl();
|
231 |
248 |
control.solveObject();
|
232 |
249 |
mLowerPane.clearMoves(this);
|
|
250 |
|
|
251 |
mMoves = "";
|
|
252 |
mText.setText(mMoves);
|
|
253 |
}
|
|
254 |
|
|
255 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
256 |
|
|
257 |
int findMove(int ax, int row, int angle)
|
|
258 |
{
|
|
259 |
int num = mMoveTable.length;
|
|
260 |
|
|
261 |
for( int m=0; m<num; m++)
|
|
262 |
{
|
|
263 |
int[] move = mMoveTable[m];
|
|
264 |
if( ax==move[0] && row==move[1] && angle==move[2] ) return m;
|
|
265 |
}
|
|
266 |
|
|
267 |
return -1;
|
|
268 |
}
|
|
269 |
|
|
270 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
271 |
|
|
272 |
void addMove(int axis, int row, int angle)
|
|
273 |
{
|
|
274 |
if( mObject==null ) createObject();
|
|
275 |
int move = findMove(axis,row,angle);
|
|
276 |
mMoves += (" "+move);
|
|
277 |
mText.setText(mMoves);
|
233 |
278 |
}
|
234 |
279 |
|
235 |
280 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Phased Solver app: show the moveIndex