|
1 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2 |
// Copyright 2023 Leszek Koltunski //
|
|
3 |
// //
|
|
4 |
// This file is part of Magic Cube. //
|
|
5 |
// //
|
|
6 |
// 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 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9 |
|
|
10 |
package org.distorted.solvers;
|
|
11 |
|
|
12 |
import android.content.res.Resources;
|
|
13 |
|
|
14 |
import org.distorted.main.R;
|
|
15 |
import org.distorted.objectlib.main.ObjectSignatures;
|
|
16 |
import org.distorted.objectlib.main.TwistyObject;
|
|
17 |
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
|
|
18 |
import org.distorted.objectlib.tablebases.TablebasesAbstract;
|
|
19 |
|
|
20 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
21 |
|
|
22 |
public class SolverSkewb extends SolverTablebase
|
|
23 |
{
|
|
24 |
private static final int ERROR_CORNER_135_MISSING = -1;
|
|
25 |
private static final int ERROR_CORNER_134_MISSING = -2;
|
|
26 |
private static final int ERROR_CORNER_125_MISSING = -3;
|
|
27 |
private static final int ERROR_CORNER_124_MISSING = -4;
|
|
28 |
private static final int ERROR_CORNER_035_MISSING = -5;
|
|
29 |
private static final int ERROR_CORNER_034_MISSING = -6;
|
|
30 |
private static final int ERROR_CORNER_025_MISSING = -7;
|
|
31 |
private static final int ERROR_CORNER_024_MISSING = -8;
|
|
32 |
|
|
33 |
private static final int ERROR_CENTER_0_MISSING = -9;
|
|
34 |
private static final int ERROR_CENTER_1_MISSING = -10;
|
|
35 |
private static final int ERROR_CENTER_2_MISSING = -11;
|
|
36 |
private static final int ERROR_CENTER_3_MISSING = -12;
|
|
37 |
private static final int ERROR_CENTER_4_MISSING = -13;
|
|
38 |
private static final int ERROR_CENTER_5_MISSING = -14;
|
|
39 |
|
|
40 |
private static final int ERROR_CORNERS_CANNOT = -15;
|
|
41 |
private static final int ERROR_CORNER_TWISTED = -16;
|
|
42 |
private static final int ERROR_TWO_CENTERS = -17;
|
|
43 |
private static final int ERROR_TWO_CORNERS = -18;
|
|
44 |
|
|
45 |
private TablebasesAbstract mSolver;
|
|
46 |
private int[] mFaceColors;
|
|
47 |
|
|
48 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
49 |
|
|
50 |
public SolverSkewb(Resources res, TwistyObject object)
|
|
51 |
{
|
|
52 |
super(res,object);
|
|
53 |
}
|
|
54 |
|
|
55 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
56 |
|
|
57 |
private void getCorners(TwistyObject object, int[][] corners)
|
|
58 |
{
|
|
59 |
|
|
60 |
}
|
|
61 |
|
|
62 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
63 |
|
|
64 |
private int checkAllCornersPresent(int[][] corners)
|
|
65 |
{
|
|
66 |
return 0;
|
|
67 |
}
|
|
68 |
|
|
69 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
70 |
|
|
71 |
private int[] computeFaceColors(int[][] corners)
|
|
72 |
{
|
|
73 |
return null;
|
|
74 |
}
|
|
75 |
|
|
76 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
77 |
|
|
78 |
private void getCenters(TwistyObject object, int[] centers)
|
|
79 |
{
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
84 |
|
|
85 |
private int checkAllCentersPresent(int[] centers)
|
|
86 |
{
|
|
87 |
return 0;
|
|
88 |
}
|
|
89 |
|
|
90 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
91 |
|
|
92 |
public int tablebaseIndex(TwistyObject object)
|
|
93 |
{
|
|
94 |
int[][] corners = new int[6][3];
|
|
95 |
int[] centers = new int[6];
|
|
96 |
int[] corner_twist= new int[6];
|
|
97 |
|
|
98 |
getCorners(object,corners);
|
|
99 |
|
|
100 |
int result1 = checkAllCornersPresent(corners);
|
|
101 |
if( result1<0 ) return result1;
|
|
102 |
|
|
103 |
mFaceColors = computeFaceColors(corners);
|
|
104 |
|
|
105 |
getCenters(object,centers);
|
|
106 |
int result2 = checkAllCentersPresent(centers);
|
|
107 |
if( result2<0 ) return result2;
|
|
108 |
|
|
109 |
// TODO...
|
|
110 |
|
|
111 |
return 0;
|
|
112 |
}
|
|
113 |
|
|
114 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
115 |
|
|
116 |
private int getColorIndex2(int face)
|
|
117 |
{
|
|
118 |
switch(mFaceColors[face])
|
|
119 |
{
|
|
120 |
case 0: return R.string.color_yellow2;
|
|
121 |
case 1: return R.string.color_white2;
|
|
122 |
case 2: return R.string.color_blue2;
|
|
123 |
case 3: return R.string.color_green2;
|
|
124 |
case 4: return R.string.color_red2;
|
|
125 |
case 5: return R.string.color_orange2;
|
|
126 |
}
|
|
127 |
|
|
128 |
return -1;
|
|
129 |
}
|
|
130 |
|
|
131 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
132 |
|
|
133 |
private int getColorIndex3(int face)
|
|
134 |
{
|
|
135 |
switch(mFaceColors[face])
|
|
136 |
{
|
|
137 |
case 0: return R.string.color_yellow3;
|
|
138 |
case 1: return R.string.color_white3;
|
|
139 |
case 2: return R.string.color_blue3;
|
|
140 |
case 3: return R.string.color_green3;
|
|
141 |
case 4: return R.string.color_red3;
|
|
142 |
case 5: return R.string.color_orange3;
|
|
143 |
}
|
|
144 |
|
|
145 |
return -1;
|
|
146 |
}
|
|
147 |
|
|
148 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
149 |
|
|
150 |
private int getColorIndex4(int face)
|
|
151 |
{
|
|
152 |
switch(mFaceColors[face])
|
|
153 |
{
|
|
154 |
case 0: return R.string.color_yellow4;
|
|
155 |
case 1: return R.string.color_white4;
|
|
156 |
case 2: return R.string.color_blue4;
|
|
157 |
case 3: return R.string.color_green4;
|
|
158 |
case 4: return R.string.color_red4;
|
|
159 |
case 5: return R.string.color_orange4;
|
|
160 |
}
|
|
161 |
|
|
162 |
return -1;
|
|
163 |
}
|
|
164 |
|
|
165 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
166 |
|
|
167 |
private String cornerError(Resources res, int face0, int face1, int face2)
|
|
168 |
{
|
|
169 |
int j0 = getColorIndex3(face0);
|
|
170 |
int j1 = getColorIndex3(face1);
|
|
171 |
int j2 = getColorIndex4(face2);
|
|
172 |
|
|
173 |
String c0 = res.getString(j0);
|
|
174 |
String c1 = res.getString(j1);
|
|
175 |
String c2 = res.getString(j2);
|
|
176 |
|
|
177 |
return res.getString(R.string.solver_generic_missing_corner,c0,c1,c2);
|
|
178 |
}
|
|
179 |
|
|
180 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
181 |
|
|
182 |
private String centerError(Resources res, int face)
|
|
183 |
{
|
|
184 |
int color = getColorIndex2(face);
|
|
185 |
String clr= res.getString(color);
|
|
186 |
return res.getString(R.string.solver_generic_missing_center,clr);
|
|
187 |
}
|
|
188 |
|
|
189 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
190 |
|
|
191 |
public String error(int index, Resources res)
|
|
192 |
{
|
|
193 |
switch(index)
|
|
194 |
{
|
|
195 |
case ERROR_CORNER_135_MISSING: return cornerError(res,1,3,5);
|
|
196 |
case ERROR_CORNER_134_MISSING: return cornerError(res,1,3,4);
|
|
197 |
case ERROR_CORNER_125_MISSING: return cornerError(res,1,2,5);
|
|
198 |
case ERROR_CORNER_124_MISSING: return cornerError(res,1,2,4);
|
|
199 |
case ERROR_CORNER_035_MISSING: return cornerError(res,0,3,5);
|
|
200 |
case ERROR_CORNER_034_MISSING: return cornerError(res,0,3,4);
|
|
201 |
case ERROR_CORNER_025_MISSING: return cornerError(res,0,2,5);
|
|
202 |
case ERROR_CORNER_024_MISSING: return cornerError(res,0,2,4);
|
|
203 |
|
|
204 |
case ERROR_CENTER_0_MISSING : return centerError(res,0);
|
|
205 |
case ERROR_CENTER_1_MISSING : return centerError(res,1);
|
|
206 |
case ERROR_CENTER_2_MISSING : return centerError(res,2);
|
|
207 |
case ERROR_CENTER_3_MISSING : return centerError(res,3);
|
|
208 |
case ERROR_CENTER_4_MISSING : return centerError(res,4);
|
|
209 |
case ERROR_CENTER_5_MISSING : return centerError(res,5);
|
|
210 |
|
|
211 |
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot);
|
|
212 |
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist);
|
|
213 |
case ERROR_TWO_CENTERS : return res.getString(R.string.solver_generic_two_centers);
|
|
214 |
case ERROR_TWO_CORNERS : return res.getString(R.string.solver_generic_two_corners);
|
|
215 |
}
|
|
216 |
|
|
217 |
return null;
|
|
218 |
}
|
|
219 |
|
|
220 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
221 |
|
|
222 |
public int[][] solution(int index, Resources res)
|
|
223 |
{
|
|
224 |
if( mSolver==null )
|
|
225 |
{
|
|
226 |
mSolver = ImplementedTablebasesList.createUnpacked(ObjectSignatures.SKEW_2);
|
|
227 |
|
|
228 |
if( mSolver!=null )
|
|
229 |
{
|
|
230 |
mSolver.createTablebase(-1);
|
|
231 |
mSolver.pack();
|
|
232 |
}
|
|
233 |
}
|
|
234 |
|
|
235 |
return mSolver!=null ? mSolver.solution(index,null) : null;
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
Beginnings of the Skewb solver.