1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2024 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 static org.distorted.objectlib.solvers.verifiers.SolverAbstract.*;
|
13
|
|
14
|
import android.content.res.Resources;
|
15
|
|
16
|
import org.distorted.main.R;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public class SolverErrors
|
21
|
{
|
22
|
private static final int[][] colorsHex =
|
23
|
{
|
24
|
{R.string.color_yellow1,R.string.color_yellow2,R.string.color_yellow3,R.string.color_yellow4,R.string.color_yellow5,R.string.color_yellow6,R.string.color_yellow7 },
|
25
|
{R.string.color_white1 ,R.string.color_white2 ,R.string.color_white3 ,R.string.color_white4 ,R.string.color_white5 ,R.string.color_white6 ,R.string.color_white7 },
|
26
|
{R.string.color_blue1 ,R.string.color_blue2 ,R.string.color_blue3 ,R.string.color_blue4 ,R.string.color_blue5 ,R.string.color_blue6 ,R.string.color_blue7 },
|
27
|
{R.string.color_green1 ,R.string.color_green2 ,R.string.color_green3 ,R.string.color_green4 ,R.string.color_green5 ,R.string.color_green6 ,R.string.color_green7 },
|
28
|
{R.string.color_red1 ,R.string.color_red2 ,R.string.color_red3 ,R.string.color_red4 ,R.string.color_red5 ,R.string.color_red6 ,R.string.color_red7 },
|
29
|
{R.string.color_orange1,R.string.color_orange2,R.string.color_orange3,R.string.color_orange4,R.string.color_orange5,R.string.color_orange6,R.string.color_orange7 },
|
30
|
};
|
31
|
private static final int[][] colorsTet =
|
32
|
{
|
33
|
{R.string.color_green1 ,R.string.color_green2 ,R.string.color_green3 ,R.string.color_green4 ,R.string.color_green5 ,R.string.color_green6 ,R.string.color_green7 },
|
34
|
{R.string.color_yellow1,R.string.color_yellow2,R.string.color_yellow3,R.string.color_yellow4,R.string.color_yellow5,R.string.color_yellow6,R.string.color_yellow7 },
|
35
|
{R.string.color_blue1 ,R.string.color_blue2 ,R.string.color_blue3 ,R.string.color_blue4 ,R.string.color_blue5 ,R.string.color_blue6 ,R.string.color_blue7 },
|
36
|
{R.string.color_red1 ,R.string.color_red2 ,R.string.color_red3 ,R.string.color_red4 ,R.string.color_red5 ,R.string.color_red6 ,R.string.color_red7 },
|
37
|
};
|
38
|
private static final int[][] colorsOct =
|
39
|
{
|
40
|
{R.string.color_violet1,R.string.color_violet2,R.string.color_violet3,R.string.color_violet4,R.string.color_violet5,R.string.color_violet6,R.string.color_violet7 },
|
41
|
{R.string.color_grey1 ,R.string.color_grey2 ,R.string.color_grey3 ,R.string.color_grey4 ,R.string.color_grey5 ,R.string.color_grey6 ,R.string.color_grey7 },
|
42
|
{R.string.color_blue1 ,R.string.color_blue2 ,R.string.color_blue3 ,R.string.color_blue4 ,R.string.color_blue5 ,R.string.color_blue6 ,R.string.color_blue7 },
|
43
|
{R.string.color_red1 ,R.string.color_red2 ,R.string.color_red3 ,R.string.color_red4 ,R.string.color_red5 ,R.string.color_red6 ,R.string.color_red7 },
|
44
|
{R.string.color_orange1,R.string.color_orange2,R.string.color_orange3,R.string.color_orange4,R.string.color_orange5,R.string.color_orange6,R.string.color_orange7 },
|
45
|
{R.string.color_green1 ,R.string.color_green2 ,R.string.color_green3 ,R.string.color_green4 ,R.string.color_green5 ,R.string.color_green6 ,R.string.color_green7 },
|
46
|
{R.string.color_white1 ,R.string.color_white2 ,R.string.color_white3 ,R.string.color_white4 ,R.string.color_white5 ,R.string.color_white6 ,R.string.color_white7 },
|
47
|
{R.string.color_yellow1,R.string.color_yellow2,R.string.color_yellow3,R.string.color_yellow4,R.string.color_yellow5,R.string.color_yellow6,R.string.color_yellow7 },
|
48
|
};
|
49
|
|
50
|
private static final int[][] colorsDod =
|
51
|
{
|
52
|
{R.string.color_yellow1,R.string.color_yellow2,R.string.color_yellow3,R.string.color_yellow4,R.string.color_yellow5,R.string.color_yellow6,R.string.color_yellow7 },
|
53
|
{R.string.color_orange1,R.string.color_orange2,R.string.color_orange3,R.string.color_orange4,R.string.color_orange5,R.string.color_orange6,R.string.color_orange7 },
|
54
|
{R.string.color_red1 ,R.string.color_red2 ,R.string.color_red3 ,R.string.color_red4 ,R.string.color_red5 ,R.string.color_red6 ,R.string.color_red7 },
|
55
|
{R.string.color_sandy1 ,R.string.color_sandy2 ,R.string.color_sandy3 ,R.string.color_sandy4 ,R.string.color_sandy5 ,R.string.color_sandy6 ,R.string.color_sandy7 },
|
56
|
{R.string.color_dblue1 ,R.string.color_dblue2 ,R.string.color_dblue3 ,R.string.color_dblue4 ,R.string.color_dblue5 ,R.string.color_dblue6 ,R.string.color_dblue7 },
|
57
|
{R.string.color_white1 ,R.string.color_white2 ,R.string.color_white3 ,R.string.color_white4 ,R.string.color_white5 ,R.string.color_white6 ,R.string.color_white7 },
|
58
|
{R.string.color_grey1 ,R.string.color_grey2 ,R.string.color_grey3 ,R.string.color_grey4 ,R.string.color_grey5 ,R.string.color_grey6 ,R.string.color_grey7 },
|
59
|
{R.string.color_blue1 ,R.string.color_blue2 ,R.string.color_blue3 ,R.string.color_blue4 ,R.string.color_blue5 ,R.string.color_blue6 ,R.string.color_blue7 },
|
60
|
{R.string.color_green1 ,R.string.color_green2 ,R.string.color_green3 ,R.string.color_green4 ,R.string.color_green5 ,R.string.color_green6 ,R.string.color_green7 },
|
61
|
{R.string.color_violet1,R.string.color_violet2,R.string.color_violet3,R.string.color_violet4,R.string.color_violet5,R.string.color_violet6,R.string.color_violet7 },
|
62
|
{R.string.color_pink1 ,R.string.color_pink2 ,R.string.color_pink3 ,R.string.color_pink4 ,R.string.color_pink5 ,R.string.color_pink6 ,R.string.color_pink7 },
|
63
|
{R.string.color_dgreen1,R.string.color_dgreen2,R.string.color_dgreen3,R.string.color_dgreen4,R.string.color_dgreen5,R.string.color_dgreen6,R.string.color_dgreen7 },
|
64
|
};
|
65
|
|
66
|
private static final int[][] colorsDi4 =
|
67
|
{
|
68
|
{R.string.color_yellow1,R.string.color_yellow2,R.string.color_yellow3,R.string.color_yellow4,R.string.color_yellow5,R.string.color_yellow6,R.string.color_yellow7 },
|
69
|
{R.string.color_white1 ,R.string.color_white2 ,R.string.color_white3 ,R.string.color_white4 ,R.string.color_white5 ,R.string.color_white6 ,R.string.color_white7 },
|
70
|
{R.string.color_blue1 ,R.string.color_blue2 ,R.string.color_blue3 ,R.string.color_blue4 ,R.string.color_blue5 ,R.string.color_blue6 ,R.string.color_blue7 },
|
71
|
{R.string.color_red1 ,R.string.color_red2 ,R.string.color_red3 ,R.string.color_red4 ,R.string.color_red5 ,R.string.color_red6 ,R.string.color_red7 },
|
72
|
};
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
private static int getHexColor(int color,int variant) { return colorsHex[color][variant]; }
|
77
|
private static int getTetColor(int color,int variant) { return colorsTet[color][variant]; }
|
78
|
private static int getOctColor(int color,int variant) { return colorsOct[color][variant]; }
|
79
|
private static int getDodColor(int color,int variant) { return colorsDod[color][variant]; }
|
80
|
private static int getDi4Color(int color,int variant) { return colorsDi4[color][variant]; }
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
private static String hexCornerMissingError(Resources res, int face0, int face1, int face2)
|
85
|
{
|
86
|
int j0 = getHexColor(face0,3);
|
87
|
int j1 = getHexColor(face1,3);
|
88
|
int j2 = getHexColor(face2,4);
|
89
|
|
90
|
String c0 = res.getString(j0);
|
91
|
String c1 = res.getString(j1);
|
92
|
String c2 = res.getString(j2);
|
93
|
|
94
|
return res.getString(R.string.solver_generic_missing_corner,c0,c1,c2);
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
private static String hexCenterMissingError(Resources res, int face)
|
100
|
{
|
101
|
int color = getHexColor(face,2);
|
102
|
String clr= res.getString(color);
|
103
|
return res.getString(R.string.solver_generic_missing_center,clr);
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
private static String hexEdgeMissingError(Resources res, int face0, int face1)
|
109
|
{
|
110
|
int j0 = getHexColor(face0,3);
|
111
|
int j1 = getHexColor(face1,6);
|
112
|
|
113
|
String c0 = res.getString(j0);
|
114
|
String c1 = res.getString(j1);
|
115
|
|
116
|
return res.getString(R.string.solver_generic_missing_edge,c0,c1);
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
private static String hexEdgeTwistedError(Resources res, int color0, int color1)
|
122
|
{
|
123
|
int j0 = getHexColor(color0,3);
|
124
|
int j1 = getHexColor(color1,6);
|
125
|
|
126
|
String c0 = res.getString(j0);
|
127
|
String c1 = res.getString(j1);
|
128
|
|
129
|
return res.getString(R.string.solver_generic_twisted_edge,c0,c1);
|
130
|
}
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
private static String hexCornerTwistedError(Resources res, int color0, int color1, int color2)
|
135
|
{
|
136
|
int j0 = getHexColor(color0,3);
|
137
|
int j1 = getHexColor(color1,3);
|
138
|
int j2 = getHexColor(color2,5);
|
139
|
|
140
|
String c0 = res.getString(j0);
|
141
|
String c1 = res.getString(j1);
|
142
|
String c2 = res.getString(j2);
|
143
|
|
144
|
return res.getString(R.string.solver_generic_twisted_corner,c0,c1,c2);
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
private static String hexEdgeMonoError(Resources res, int color)
|
150
|
{
|
151
|
int j0 = getHexColor(color,3);
|
152
|
int j1 = getHexColor(color,6);
|
153
|
String c0 = res.getString(j0);
|
154
|
String c1 = res.getString(j1);
|
155
|
|
156
|
return res.getString(R.string.solver_generic_edge_mono,c0,c1);
|
157
|
}
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
|
161
|
private static String hexEdgeTwiceError(Resources res, int color0, int color1)
|
162
|
{
|
163
|
int j0 = getHexColor(color0,3);
|
164
|
int j1 = getHexColor(color1,6);
|
165
|
String c0 = res.getString(j0);
|
166
|
String c1 = res.getString(j1);
|
167
|
|
168
|
return res.getString(R.string.solver_generic_edge_twice,c0,c1);
|
169
|
}
|
170
|
|
171
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172
|
|
173
|
private static String octCenterMissingError(Resources res, int face)
|
174
|
{
|
175
|
int index = getOctColor(face,2);
|
176
|
String color = res.getString(index);
|
177
|
return res.getString(R.string.solver_generic_missing_center,color);
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
private static String octCornerMissingError(Resources res, int f1, int f2)
|
183
|
{
|
184
|
int i1 = getOctColor(f1,3);
|
185
|
int i2 = getOctColor(f2,4);
|
186
|
String c1 = res.getString(i1);
|
187
|
String c2 = res.getString(i2);
|
188
|
return res.getString(R.string.solver_generic_missing_corner2,c1,c2);
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
|
193
|
private static String tetCornerMissingError(Resources res, int color0, int color1, int color2)
|
194
|
{
|
195
|
int j0 = getTetColor(color0,3);
|
196
|
int j1 = getTetColor(color1,3);
|
197
|
int j2 = getTetColor(color2,4);
|
198
|
|
199
|
String c0 = res.getString(j0);
|
200
|
String c1 = res.getString(j1);
|
201
|
String c2 = res.getString(j2);
|
202
|
|
203
|
return res.getString(R.string.solver_generic_missing_corner,c0,c1,c2);
|
204
|
}
|
205
|
|
206
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
|
208
|
private static String tetEdgeMissingError(Resources res, int face0, int face1)
|
209
|
{
|
210
|
int j0 = getTetColor(face0,3);
|
211
|
int j1 = getTetColor(face1,6);
|
212
|
|
213
|
String c0 = res.getString(j0);
|
214
|
String c1 = res.getString(j1);
|
215
|
|
216
|
return res.getString(R.string.solver_generic_missing_edge,c0,c1);
|
217
|
}
|
218
|
|
219
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220
|
|
221
|
private static String tetCenterMissingError(Resources res, int face)
|
222
|
{
|
223
|
int j = getTetColor(face,2);
|
224
|
String c = res.getString(j);
|
225
|
return res.getString(R.string.solver_generic_missing_center,c);
|
226
|
}
|
227
|
|
228
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
229
|
|
230
|
private static String tetVertexMissingError(Resources res, int color0, int color1, int color2)
|
231
|
{
|
232
|
int j0 = getTetColor(color0,3);
|
233
|
int j1 = getTetColor(color1,3);
|
234
|
int j2 = getTetColor(color2,4);
|
235
|
|
236
|
String c0 = res.getString(j0);
|
237
|
String c1 = res.getString(j1);
|
238
|
String c2 = res.getString(j2);
|
239
|
|
240
|
return res.getString(R.string.solver_generic_missing_vertex,c0,c1,c2);
|
241
|
}
|
242
|
|
243
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
244
|
|
245
|
private static String dodCornerMissingError(Resources res, int color0, int color1, int color2)
|
246
|
{
|
247
|
int j0 = getDodColor(color0,3);
|
248
|
int j1 = getDodColor(color1,3);
|
249
|
int j2 = getDodColor(color2,4);
|
250
|
|
251
|
String c0 = res.getString(j0);
|
252
|
String c1 = res.getString(j1);
|
253
|
String c2 = res.getString(j2);
|
254
|
|
255
|
return res.getString(R.string.solver_generic_missing_corner,c0,c1,c2);
|
256
|
}
|
257
|
|
258
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259
|
|
260
|
private static String dodEdgeMissingError(Resources res, int face0, int face1)
|
261
|
{
|
262
|
int j0 = getDodColor(face0,3);
|
263
|
int j1 = getDodColor(face1,6);
|
264
|
|
265
|
String c0 = res.getString(j0);
|
266
|
String c1 = res.getString(j1);
|
267
|
|
268
|
return res.getString(R.string.solver_generic_missing_edge,c0,c1);
|
269
|
}
|
270
|
|
271
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
272
|
|
273
|
private static String dodCenterMissingError(Resources res, int face)
|
274
|
{
|
275
|
int j = getDodColor(face,2);
|
276
|
String c = res.getString(j);
|
277
|
return res.getString(R.string.solver_generic_missing_center,c);
|
278
|
}
|
279
|
|
280
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281
|
|
282
|
private static String di4EdgeThreeError(Resources res, int color)
|
283
|
{
|
284
|
int j0 = getDi4Color(color,7);
|
285
|
String c0 = res.getString(j0);
|
286
|
return res.getString(R.string.solver_generic_edge_three,c0);
|
287
|
}
|
288
|
|
289
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
290
|
|
291
|
public static String error(Resources res, int[] err, int[] faceColors)
|
292
|
{
|
293
|
switch(err[0])
|
294
|
{
|
295
|
case ERROR_HEX_CORNER_MISSING : return hexCornerMissingError(res,err[1],err[2],err[3]);
|
296
|
case ERROR_HEX_CENTER_MISSING : return hexCenterMissingError(res,err[1]);
|
297
|
case ERROR_HEX_EDGE_MISSING : return hexEdgeMissingError(res,err[1],err[2]);
|
298
|
case ERROR_HEX_EDGE_TWISTED : return hexEdgeTwistedError(res,err[1],err[2]);
|
299
|
case ERROR_HEX_EDGE_MONOCHROMATIC: return hexEdgeMonoError(res,err[1]);
|
300
|
case ERROR_HEX_EDGE_TWICE : return hexEdgeTwiceError(res,err[1],err[2]);
|
301
|
case ERROR_HEX_CORNER_TWISTED : return hexCornerTwistedError(res,err[1],err[2],err[3]);
|
302
|
|
303
|
case ERROR_TET_CORNER_MISSING : return tetCornerMissingError(res,err[1],err[2],err[3]);
|
304
|
case ERROR_TET_VERTEX_MISSING : return tetVertexMissingError(res,err[1],err[2],err[3]);
|
305
|
case ERROR_TET_EDGE_MISSING : return tetEdgeMissingError(res,faceColors[err[1]],faceColors[err[2]]);
|
306
|
case ERROR_TET_CENTER_MISSING : return tetCenterMissingError(res,err[1]);
|
307
|
|
308
|
case ERROR_OCT_CENTER_MISSING : return octCenterMissingError(res,err[1]);
|
309
|
case ERROR_OCT_CORNER_MISSING : return octCornerMissingError(res,err[1],err[2]);
|
310
|
|
311
|
case ERROR_DOD_CENTER_MISSING : return dodCenterMissingError(res,err[1]);
|
312
|
case ERROR_DOD_EDGE_MISSING : return dodEdgeMissingError(res,err[1],err[2]);
|
313
|
case ERROR_DOD_CORNER_MISSING : return dodCornerMissingError(res,err[1],err[2],err[3]);
|
314
|
|
315
|
case ERROR_DI4_EDGE_THREE : return di4EdgeThreeError(res,err[1]);
|
316
|
|
317
|
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot);
|
318
|
case ERROR_EDGE_CANNOT : return res.getString(R.string.solver_generic_edges_cannot);
|
319
|
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist);
|
320
|
case ERROR_CORNER_TWIST_90 : return res.getString(R.string.solver_generic_corner_twist) + " (90)";
|
321
|
case ERROR_CORNER_TWIST_180 : return res.getString(R.string.solver_generic_corner_twist) + " (180)";
|
322
|
case ERROR_EDGE_TWISTED : return res.getString(R.string.solver_generic_edge_twist);
|
323
|
case ERROR_TWO_CENTERS : return res.getString(R.string.solver_generic_two_centers);
|
324
|
case ERROR_TWO_CORNERS : return res.getString(R.string.solver_generic_two_corners);
|
325
|
case ERROR_TWO_EDGES : return res.getString(R.string.solver_generic_two_edges);
|
326
|
case ERROR_FREE_CORNERS_NOT_EVEN : return res.getString(R.string.solver_generic_free_corners_odd);
|
327
|
case ERROR_FREE_CORNERS_ROTATED : return res.getString(R.string.solver_generic_free_corners_rotated);
|
328
|
case ERROR_VERTICES_CANNOT : return res.getString(R.string.solver_generic_vertices_cannot);
|
329
|
case ERROR_C_V_DONT_MATCH : return res.getString(R.string.solver_generic_c_v_dont_match);
|
330
|
case ERROR_TWO_CORNERS_TWO_EDGES : return res.getString(R.string.solver_two_corners_two_edges);
|
331
|
}
|
332
|
|
333
|
return null;
|
334
|
}
|
335
|
}
|