Revision a304ee64
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
418 | 418 |
return dx*dx + dy*dy + dz*dz; |
419 | 419 |
} |
420 | 420 |
|
421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
422 |
|
|
423 |
int getColorIndex(int face) |
|
424 |
{ |
|
425 |
Static4D texMap = mMesh.getTextureMap(face); |
|
426 |
return (int)(texMap.get0() / texMap.get2()); |
|
427 |
} |
|
428 |
|
|
421 | 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
422 | 430 |
|
423 | 431 |
MeshBase getMesh() |
src/main/java/org/distorted/objects/RubikCube.java | ||
---|---|---|
227 | 227 |
} |
228 | 228 |
|
229 | 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 |
// order: Up --> Right --> Front --> Down --> Left --> Back |
|
231 |
// (because the first implemented Solver - the two-phase Cube3 one - expects such order) |
|
232 |
// |
|
233 |
// s : size of the cube |
|
234 |
// |
|
235 |
// Left : index --> ((s-1) + index/s) * s + index%s |
|
236 |
// Right : index --> 6*s*s - 12*s + 7 - index |
|
237 |
// Bottom: index --> s|index ? (s-1 - index/s) : (s*s + s-1 + 4*(index%s -1)*(s-1) - index/s) |
|
238 |
// Top : index --> |
|
239 |
// Front : index --> |
|
240 |
// Back : index --> |
|
230 | 241 |
|
231 | 242 |
public String retObjectString() |
232 | 243 |
{ |
src/main/java/org/distorted/solvers/Solver.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.solvers; |
|
21 |
|
|
22 |
import android.content.res.Resources; |
|
23 |
|
|
24 |
import org.distorted.main.R; |
|
25 |
import org.distorted.objects.RubikObjectList; |
|
26 |
import org.distorted.states.RubikState; |
|
27 |
import org.distorted.states.RubikStateSolver; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
public class Solver implements Runnable |
|
32 |
{ |
|
33 |
private String mObjectPosition; |
|
34 |
private Resources mRes; |
|
35 |
private RubikObjectList mObject; |
|
36 |
private int mSize; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public Solver(Resources res, RubikObjectList object, int size, String position ) |
|
41 |
{ |
|
42 |
mRes = res; |
|
43 |
mObject = object; |
|
44 |
mSize = size; |
|
45 |
mObjectPosition = position; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
private void solveCube3(RubikStateSolver solver) |
|
51 |
{ |
|
52 |
String result; |
|
53 |
|
|
54 |
if( !org.distorted.solvers.cube3.Search.prepare(mRes) ) |
|
55 |
result= "Error 9"; |
|
56 |
else |
|
57 |
result = org.distorted.solvers.cube3.Search.solution(mObjectPosition, 24, 20); |
|
58 |
|
|
59 |
if (result.contains("Error")) |
|
60 |
{ |
|
61 |
switch (result.charAt(result.length() - 1)) |
|
62 |
{ |
|
63 |
case '1': result = mRes.getString(R.string.solver_cube3_error1); break; |
|
64 |
case '2': result = mRes.getString(R.string.solver_cube3_error2); break; |
|
65 |
case '3': result = mRes.getString(R.string.solver_cube3_error3); break; |
|
66 |
case '4': result = mRes.getString(R.string.solver_cube3_error4); break; |
|
67 |
case '5': result = mRes.getString(R.string.solver_cube3_error5); break; |
|
68 |
case '6': result = mRes.getString(R.string.solver_cube3_error6); break; |
|
69 |
case '7': result = mRes.getString(R.string.solver_cube3_error7); break; |
|
70 |
case '8': result = mRes.getString(R.string.solver_cube3_error8); break; |
|
71 |
case '9': result = mRes.getString(R.string.solver_cube3_error9); break; |
|
72 |
} |
|
73 |
|
|
74 |
solver.displayErrorDialog(result); |
|
75 |
} |
|
76 |
else |
|
77 |
{ |
|
78 |
solver.setSolved(result); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 |
|
|
84 |
private void interruptCube3() |
|
85 |
{ |
|
86 |
org.distorted.solvers.cube3.Search.interrupt(); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public void start() |
|
92 |
{ |
|
93 |
Thread thr = new Thread(this); |
|
94 |
thr.start(); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void run() |
|
100 |
{ |
|
101 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass(); |
|
102 |
|
|
103 |
if( mObject == RubikObjectList.CUBE && mSize == 3) |
|
104 |
{ |
|
105 |
solveCube3(solver); |
|
106 |
} |
|
107 |
else |
|
108 |
{ |
|
109 |
solver.displayErrorDialog(mRes.getString(R.string.solver_generic_error1)); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
src/main/java/org/distorted/solvers/SolverMain.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.solvers; |
|
21 |
|
|
22 |
import android.content.res.Resources; |
|
23 |
|
|
24 |
import org.distorted.main.R; |
|
25 |
import org.distorted.objects.RubikObjectList; |
|
26 |
import org.distorted.states.RubikState; |
|
27 |
import org.distorted.states.RubikStateSolver; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
public class SolverMain implements Runnable |
|
32 |
{ |
|
33 |
private String mObjectPosition; |
|
34 |
private Resources mRes; |
|
35 |
private RubikObjectList mObject; |
|
36 |
private int mSize; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public SolverMain(Resources res, RubikObjectList object, int size, String position ) |
|
41 |
{ |
|
42 |
mRes = res; |
|
43 |
mObject = object; |
|
44 |
mSize = size; |
|
45 |
mObjectPosition = position; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
private void solveCube3(RubikStateSolver solver) |
|
51 |
{ |
|
52 |
String result; |
|
53 |
|
|
54 |
if( !org.distorted.solvers.cube3.Search.prepare(mRes) ) |
|
55 |
result= "Error 9"; |
|
56 |
else |
|
57 |
result = org.distorted.solvers.cube3.Search.solution(mObjectPosition, 24, 20); |
|
58 |
|
|
59 |
if (result.contains("Error")) |
|
60 |
{ |
|
61 |
switch (result.charAt(result.length() - 1)) |
|
62 |
{ |
|
63 |
case '1': result = mRes.getString(R.string.solver_cube3_error1); break; |
|
64 |
case '2': result = mRes.getString(R.string.solver_cube3_error2); break; |
|
65 |
case '3': result = mRes.getString(R.string.solver_cube3_error3); break; |
|
66 |
case '4': result = mRes.getString(R.string.solver_cube3_error4); break; |
|
67 |
case '5': result = mRes.getString(R.string.solver_cube3_error5); break; |
|
68 |
case '6': result = mRes.getString(R.string.solver_cube3_error6); break; |
|
69 |
case '7': result = mRes.getString(R.string.solver_cube3_error7); break; |
|
70 |
case '8': result = mRes.getString(R.string.solver_cube3_error8); break; |
|
71 |
case '9': result = mRes.getString(R.string.solver_cube3_error9); break; |
|
72 |
} |
|
73 |
|
|
74 |
solver.displayErrorDialog(result); |
|
75 |
} |
|
76 |
else |
|
77 |
{ |
|
78 |
solver.setSolved(result); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 |
|
|
84 |
private void interruptCube3() |
|
85 |
{ |
|
86 |
org.distorted.solvers.cube3.Search.interrupt(); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public void start() |
|
92 |
{ |
|
93 |
Thread thr = new Thread(this); |
|
94 |
thr.start(); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void run() |
|
100 |
{ |
|
101 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass(); |
|
102 |
|
|
103 |
if( mObject == RubikObjectList.CUBE && mSize == 3) |
|
104 |
{ |
|
105 |
solveCube3(solver); |
|
106 |
} |
|
107 |
else |
|
108 |
{ |
|
109 |
solver.displayErrorDialog(mRes.getString(R.string.solver_generic_error1)); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
src/main/java/org/distorted/states/RubikStateSolver.java | ||
---|---|---|
40 | 40 |
import org.distorted.objects.RubikObject; |
41 | 41 |
import org.distorted.objects.RubikObjectList; |
42 | 42 |
import org.distorted.solvers.ImplementedSolversList; |
43 |
import org.distorted.solvers.Solver; |
|
43 |
import org.distorted.solvers.SolverMain;
|
|
44 | 44 |
|
45 | 45 |
import java.lang.ref.WeakReference; |
46 | 46 |
|
... | ... | |
199 | 199 |
mSolving = true; |
200 | 200 |
RubikObject object = act.getObject(); |
201 | 201 |
String objectString = object.retObjectString(); |
202 |
Solver solver = new Solver( act.getResources(), mCurrentObject, mCurrentObjectSize, objectString );
|
|
202 |
SolverMain solver = new SolverMain( act.getResources(), mCurrentObject, mCurrentObjectSize, objectString );
|
|
203 | 203 |
solver.start(); |
204 | 204 |
} |
205 | 205 |
} |
Also available in: Unified diff
Progress implementing RubikCube.retObjectString()