Revision 277401c0
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/screens/RubikScreenSolution.java | ||
|---|---|---|
| 262 | 262 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 266 |
|
|
| 267 |
void setupMoves(final RubikActivity act, int[][] moves) |
|
| 268 |
{
|
|
| 269 |
mCanRotate= true; |
|
| 270 |
mCurrMove = 0; |
|
| 271 |
mNumMoves = moves==null ? 0 : moves.length; |
|
| 272 |
mMoves = moves; |
|
| 273 |
|
|
| 274 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
| 275 |
} |
|
| 276 |
|
|
| 265 | 277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 266 | 278 |
|
| 267 | 279 |
public void savePreferences(SharedPreferences.Editor editor) |
| src/main/java/org/distorted/screens/RubikScreenSolver.java | ||
|---|---|---|
| 348 | 348 |
} |
| 349 | 349 |
} |
| 350 | 350 |
|
| 351 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 352 |
|
|
| 353 |
public void setSolved(final int[][] moves) |
|
| 354 |
{
|
|
| 355 |
mSolving = false; |
|
| 356 |
final RubikActivity act = mWeakAct.get(); |
|
| 357 |
|
|
| 358 |
if( act!=null ) |
|
| 359 |
{
|
|
| 360 |
act.runOnUiThread(new Runnable() |
|
| 361 |
{
|
|
| 362 |
@Override |
|
| 363 |
public void run() |
|
| 364 |
{
|
|
| 365 |
ScreenList.switchScreen(act, ScreenList.SOLU); |
|
| 366 |
RubikScreenSolution solution = (RubikScreenSolution) ScreenList.SOLU.getScreenClass(); |
|
| 367 |
solution.setupMoves(act, moves); |
|
| 368 |
} |
|
| 369 |
}); |
|
| 370 |
} |
|
| 371 |
} |
|
| 372 |
|
|
| 351 | 373 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 352 | 374 |
|
| 353 | 375 |
public void displayErrorDialog(String message) |
| src/main/java/org/distorted/solvers/SolverPyraminxDuo.java | ||
|---|---|---|
| 34 | 34 |
|
| 35 | 35 |
private static final int ERROR_CORNERS_CANNOT = -11; |
| 36 | 36 |
|
| 37 |
|
|
| 38 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 38 |
|
| 40 | 39 |
private boolean cornerEqual(int[] corner, int c1, int c2, int c3) |
| ... | ... | |
| 281 | 280 |
|
| 282 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 283 | 282 |
|
| 284 |
public String solution(int index, Resources res)
|
|
| 283 |
public int[][] solution(int index, Resources res)
|
|
| 285 | 284 |
{
|
| 286 | 285 |
TablebasesPyraminxDuo tb = new TablebasesPyraminxDuo(); |
| 287 | 286 |
tb.createTablebase(); |
| 288 |
|
|
| 289 |
return ""; |
|
| 287 |
return tb.solution(index); |
|
| 290 | 288 |
} |
| 291 | 289 |
} |
| 292 | 290 |
|
| src/main/java/org/distorted/solvers/SolverTablebase.java | ||
|---|---|---|
| 25 | 25 |
|
| 26 | 26 |
public abstract int tablebaseIndex(TwistyObject object); |
| 27 | 27 |
public abstract String error(int index, Resources res); |
| 28 |
public abstract String solution(int index, Resources res);
|
|
| 28 |
public abstract int[][] solution(int index, Resources res);
|
|
| 29 | 29 |
|
| 30 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | 31 |
// PUBLIC API |
| ... | ... | |
| 39 | 39 |
|
| 40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 41 | 41 |
|
| 42 |
public void solve(RubikScreenSolver solver)
|
|
| 42 |
public void solve(RubikScreenSolver screen)
|
|
| 43 | 43 |
{
|
| 44 |
String result; |
|
| 45 |
|
|
| 46 | 44 |
int index = tablebaseIndex(mObject); |
| 47 | 45 |
|
| 48 | 46 |
if( index>=0 ) |
| 49 | 47 |
{
|
| 50 |
result = solution(index,mRes);
|
|
| 51 |
solver.setSolved(result);
|
|
| 48 |
int[][] moves = solution(index,mRes);
|
|
| 49 |
screen.setSolved(moves);
|
|
| 52 | 50 |
} |
| 53 | 51 |
else |
| 54 | 52 |
{
|
| 55 | 53 |
String error = error(index,mRes); |
| 56 |
solver.displayErrorDialog(error);
|
|
| 54 |
screen.displayErrorDialog(error);
|
|
| 57 | 55 |
} |
| 58 | 56 |
} |
| 59 | 57 |
} |
Also available in: Unified diff
Pyraminx Duo solver: solutions (coming from unpacked DB recreated each time) seem to be working.