1 |
f0336037
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
bb62ca3f
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
f0336037
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.solvers;
|
11 |
|
|
|
12 |
|
|
import android.content.res.Resources;
|
13 |
|
|
|
14 |
e4733ed7
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectSignatures;
|
15 |
3f7a4363
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
16 |
|
|
|
17 |
f0336037
|
Leszek Koltunski
|
import org.distorted.main.R;
|
18 |
fcd5b990
|
Leszek Koltunski
|
import org.distorted.screens.ScreenList;
|
19 |
|
|
import org.distorted.screens.RubikScreenSolver;
|
20 |
f0336037
|
Leszek Koltunski
|
|
21 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
22 |
|
|
|
23 |
a304ee64
|
Leszek Koltunski
|
public class SolverMain implements Runnable
|
24 |
f0336037
|
Leszek Koltunski
|
{
|
25 |
c494476f
|
Leszek Koltunski
|
private final Resources mRes;
|
26 |
7e4f3e04
|
Leszek Koltunski
|
private final long mSignature;
|
27 |
420eb96d
|
Leszek Koltunski
|
private final TwistyObject mObject;
|
28 |
f0336037
|
Leszek Koltunski
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
ecf3f149
|
Leszek Koltunski
|
public SolverMain(Resources res, TwistyObject object)
|
32 |
f0336037
|
Leszek Koltunski
|
{
|
33 |
7e4f3e04
|
Leszek Koltunski
|
mRes = res;
|
34 |
|
|
mObject = object;
|
35 |
7ed91391
|
Leszek Koltunski
|
long[] sig = object.getSignature().getArray();
|
36 |
|
|
mSignature = sig[sig.length-1];
|
37 |
f0336037
|
Leszek Koltunski
|
}
|
38 |
|
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
46a961fd
|
Leszek Koltunski
|
// certain objects have certain cubits locked - for example, the Cube3's centers of
|
41 |
|
|
// sides always have the same color.
|
42 |
|
|
// If a certain cubit is locked, return the color (index into it's FACE_COLORS array) it
|
43 |
|
|
// must have. Otherwise return -1.
|
44 |
|
|
|
45 |
d433b50e
|
Leszek Koltunski
|
public static int cubitIsLocked(int object, int cubit)
|
46 |
46a961fd
|
Leszek Koltunski
|
{
|
47 |
e4733ed7
|
Leszek Koltunski
|
if( object == ObjectSignatures.CUBE_3 )
|
48 |
46a961fd
|
Leszek Koltunski
|
{
|
49 |
09b2bd31
|
Leszek Koltunski
|
if( cubit==20 ) return 0; // center of the right face
|
50 |
|
|
if( cubit==21 ) return 1; // center of the left face
|
51 |
|
|
if( cubit==22 ) return 2; // center of the up face
|
52 |
|
|
if( cubit==23 ) return 3; // center of the bottom face
|
53 |
|
|
if( cubit==24 ) return 4; // center of the front face
|
54 |
|
|
if( cubit==25 ) return 5; // center of the back face
|
55 |
46a961fd
|
Leszek Koltunski
|
}
|
56 |
|
|
|
57 |
|
|
return -1;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
373fa45f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
|
|
|
62 |
|
|
public void start()
|
63 |
|
|
{
|
64 |
|
|
Thread thr = new Thread(this);
|
65 |
|
|
thr.start();
|
66 |
|
|
}
|
67 |
|
|
|
68 |
f0336037
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
public void run()
|
71 |
|
|
{
|
72 |
420eb96d
|
Leszek Koltunski
|
RubikScreenSolver screen = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
|
73 |
f0336037
|
Leszek Koltunski
|
|
74 |
fcbf34af
|
Leszek Koltunski
|
if( mSignature==ObjectSignatures.CUBE_3 )
|
75 |
f0336037
|
Leszek Koltunski
|
{
|
76 |
420eb96d
|
Leszek Koltunski
|
SolverCube3 solver = new SolverCube3(mRes,mObject);
|
77 |
|
|
solver.solve(screen);
|
78 |
|
|
}
|
79 |
5da7a80b
|
Leszek Koltunski
|
else if( mSignature==ObjectSignatures.PDUO_2 )
|
80 |
420eb96d
|
Leszek Koltunski
|
{
|
81 |
|
|
SolverTablebase solver = new SolverPyraminxDuo(mRes,mObject);
|
82 |
|
|
solver.solve(screen);
|
83 |
f0336037
|
Leszek Koltunski
|
}
|
84 |
3eedf418
|
Leszek Koltunski
|
else if( mSignature==ObjectSignatures.IVY_2 )
|
85 |
|
|
{
|
86 |
|
|
SolverTablebase solver = new SolverIvyCube(mRes,mObject);
|
87 |
|
|
solver.solve(screen);
|
88 |
|
|
}
|
89 |
f0336037
|
Leszek Koltunski
|
else
|
90 |
|
|
{
|
91 |
ca278d11
|
Leszek Koltunski
|
screen.displayErrorDialog(mRes.getString(R.string.solver_generic_not_implemented));
|
92 |
f0336037
|
Leszek Koltunski
|
}
|
93 |
|
|
}
|
94 |
|
|
}
|