Revision 03c3bcaa
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/solvers/SolverDino6.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
public class SolverDino6 extends SolverTablebase |
23 | 23 |
{ |
24 |
private static final int ERROR_EDGE_MISSING = -1; |
|
25 |
private static final int ERROR_EDGE_CANNOT = -2; |
|
26 |
private static final int ERROR_EDGE_TWISTED = -3; |
|
24 |
private static final int ERROR_EDGE_MISSING = -1; |
|
25 |
private static final int ERROR_EDGE_CANNOT = -2; |
|
26 |
private static final int ERROR_EDGE_TWISTED = -3; |
|
27 |
private static final int ERROR_EDGE_MONOCHROMATIC = -4; |
|
28 |
|
|
29 |
int[][] EDGE_MAP = { |
|
30 |
{4,2},{0,4},{4,3},{1,4}, |
|
31 |
{2,0},{3,0},{3,1},{2,1}, |
|
32 |
{5,2},{0,5},{5,3},{1,5} |
|
33 |
}; |
|
27 | 34 |
|
28 | 35 |
private TablebasesAbstract mSolver; |
29 |
private int[] mFaceColors; |
|
36 |
private final int[] mFaceColors;
|
|
30 | 37 |
private int mErrorColor1, mErrorColor2; |
31 | 38 |
|
32 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
34 | 41 |
public SolverDino6(Resources res, TwistyObject object) |
35 | 42 |
{ |
36 | 43 |
super(res,object); |
44 |
mFaceColors = new int[6]; |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
private void getEdges(TwistyObject object, int[][] edges) |
|
50 |
{ |
|
51 |
for(int i=0; i<12; i++) |
|
52 |
{ |
|
53 |
edges[i][0] = object.getCubitFaceStickerIndex(i,0); |
|
54 |
edges[i][1] = object.getCubitFaceStickerIndex(i,1); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
private int computeOpposite(int color, int[][] edges, boolean[] buffer) |
|
61 |
{ |
|
62 |
for(int i=0; i<6; i++) buffer[i] = false; |
|
63 |
|
|
64 |
for(int i=0; i<12; i++) |
|
65 |
{ |
|
66 |
int[] edge = edges[i]; |
|
67 |
if( edge[0]==color ) buffer[edge[1]]=true; |
|
68 |
if( edge[1]==color ) buffer[edge[0]]=true; |
|
69 |
} |
|
70 |
|
|
71 |
int total = 0; |
|
72 |
|
|
73 |
for(int i=0; i<6; i++) |
|
74 |
if( buffer[i] ) |
|
75 |
{ |
|
76 |
if( i!=color) total++; |
|
77 |
else |
|
78 |
{ |
|
79 |
mErrorColor1 = i; |
|
80 |
return ERROR_EDGE_MONOCHROMATIC; |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
if( total==4 ) |
|
85 |
for(int i=0; i<6; i++) |
|
86 |
if( !buffer[i] && i!=color ) return i; |
|
87 |
|
|
88 |
return ERROR_EDGE_CANNOT; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
private int fillUpRemainingFaceColors(boolean[] buffer) |
|
94 |
{ |
|
95 |
for(int i=0; i<6; i++) |
|
96 |
{ |
|
97 |
buffer[i] = false; |
|
98 |
} |
|
99 |
for(int i=0; i<6; i++) |
|
100 |
{ |
|
101 |
int color = mFaceColors[i]; |
|
102 |
if( color>=0 ) buffer[color] = true; |
|
103 |
} |
|
104 |
|
|
105 |
int total = 0; |
|
106 |
for(int i=0; i<6; i++) |
|
107 |
if( buffer[i] ) total++; |
|
108 |
|
|
109 |
if( total==4 ) |
|
110 |
{ |
|
111 |
for(int i=0; i<6; i++) |
|
112 |
if( !buffer[i] ) |
|
113 |
{ |
|
114 |
buffer[i]=true; |
|
115 |
mFaceColors[0] = i; |
|
116 |
break; |
|
117 |
} |
|
118 |
for(int i=0; i<6; i++) |
|
119 |
if( !buffer[i] ) |
|
120 |
{ |
|
121 |
buffer[i]=true; |
|
122 |
mFaceColors[1] = i; |
|
123 |
break; |
|
124 |
} |
|
125 |
|
|
126 |
return 0; |
|
127 |
} |
|
128 |
|
|
129 |
return ERROR_EDGE_CANNOT; |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
private int figureOutFaceColors(int[][] edges) |
|
135 |
{ |
|
136 |
boolean[] present = new boolean[6]; |
|
137 |
|
|
138 |
for(int i=0; i<6; i++) mFaceColors[i] = -1; |
|
139 |
|
|
140 |
for(int i=0; i<12; i++) |
|
141 |
{ |
|
142 |
int[] edge = edges[i]; |
|
143 |
int c0 = edge[0]; |
|
144 |
int c1 = edge[1]; |
|
145 |
|
|
146 |
if( c0>=0 && c0<6 ) present[c0] = true; |
|
147 |
if( c1>=0 && c1<6 ) present[c1] = true; |
|
148 |
} |
|
149 |
|
|
150 |
for(int i=0; i<6; i++) |
|
151 |
if( !present[i] ) |
|
152 |
{ |
|
153 |
mErrorColor1 = i; |
|
154 |
mErrorColor2 = (i<5 ? i+1 : 4 ); |
|
155 |
return ERROR_EDGE_MISSING; |
|
156 |
} |
|
157 |
|
|
158 |
if( edges[0][0]==edges[0][1] ) return ERROR_EDGE_CANNOT; |
|
159 |
|
|
160 |
mFaceColors[4] = edges[0][0]; |
|
161 |
mFaceColors[2] = edges[0][1]; |
|
162 |
mFaceColors[5] = computeOpposite(mFaceColors[4], edges, present); |
|
163 |
if( mFaceColors[5]<0 ) return ERROR_EDGE_CANNOT; |
|
164 |
|
|
165 |
mFaceColors[3] = computeOpposite(mFaceColors[2], edges, present); |
|
166 |
if( mFaceColors[3]<0 ) return ERROR_EDGE_CANNOT; |
|
167 |
|
|
168 |
int success = fillUpRemainingFaceColors(present); |
|
169 |
if( success<0 ) return success; |
|
170 |
|
|
171 |
return 0; |
|
172 |
} |
|
173 |
|
|
174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
175 |
|
|
176 |
private boolean notPresent(int face0, int face1, int[][] edges) |
|
177 |
{ |
|
178 |
int c0=mFaceColors[face0]; |
|
179 |
int c1=mFaceColors[face1]; |
|
180 |
|
|
181 |
for(int i=0; i<12; i++) |
|
182 |
{ |
|
183 |
int[] edge = edges[i]; |
|
184 |
if( edge[0]==c0 && edge[1]==c1 ) return false; |
|
185 |
if( edge[0]==c1 && edge[1]==c0 ) return false; |
|
186 |
} |
|
187 |
return true; |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
public int checkAllPresent(int[][] edges) |
|
193 |
{ |
|
194 |
for(int i=0; i<12; i++) |
|
195 |
{ |
|
196 |
int[] map = EDGE_MAP[i]; |
|
197 |
int m1 = map[0]; |
|
198 |
int m2 = map[1]; |
|
199 |
|
|
200 |
if( notPresent(m1,m2,edges) ) |
|
201 |
{ |
|
202 |
android.util.Log.e("D", "edge missing i="+i+" m1="+m1+" m2="+m2); |
|
203 |
|
|
204 |
mErrorColor1 = mFaceColors[m1]; |
|
205 |
mErrorColor2 = mFaceColors[m2]; |
|
206 |
return ERROR_EDGE_MISSING; |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
return 0; |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
private boolean wrongTwist(int face0, int face1, int[][] edges) |
|
216 |
{ |
|
217 |
int c0=mFaceColors[face0]; |
|
218 |
int c1=mFaceColors[face1]; |
|
219 |
|
|
220 |
for(int i=0; i<12; i++) |
|
221 |
{ |
|
222 |
int[] edge = edges[i]; |
|
223 |
if( edge[1]==c0 && edge[0]==c1 ) return true; |
|
224 |
} |
|
225 |
return false; |
|
226 |
} |
|
227 |
|
|
228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
229 |
|
|
230 |
public int checkTwist(int[][] edges) |
|
231 |
{ |
|
232 |
for(int i=0; i<12; i++) |
|
233 |
{ |
|
234 |
int[] map = EDGE_MAP[i]; |
|
235 |
int m1 = map[0]; |
|
236 |
int m2 = map[1]; |
|
237 |
|
|
238 |
if( wrongTwist(m1,m2,edges) ) |
|
239 |
{ |
|
240 |
mErrorColor1 = mFaceColors[m1]; |
|
241 |
mErrorColor2 = mFaceColors[m2]; |
|
242 |
return ERROR_EDGE_TWISTED; |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
return 0; |
|
37 | 247 |
} |
38 | 248 |
|
39 | 249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
41 | 251 |
public int tablebaseIndex(TwistyObject object) |
42 | 252 |
{ |
43 | 253 |
int[][] edges = new int[12][2]; |
254 |
getEdges(object,edges); |
|
255 |
|
|
256 |
int result1 = figureOutFaceColors(edges); |
|
257 |
if( result1<0 ) return result1; |
|
258 |
|
|
259 |
for(int i=0; i<6; i++) |
|
260 |
{ |
|
261 |
android.util.Log.e("D", "face "+i+" : "+mFaceColors[i]); |
|
262 |
} |
|
263 |
|
|
264 |
int result2 = checkAllPresent(edges); |
|
265 |
if( result2<0 ) return result2; |
|
266 |
|
|
267 |
int result3 = checkTwist(edges); |
|
268 |
if( result3<0 ) return result3; |
|
269 |
|
|
44 | 270 |
return 0; |
45 | 271 |
} |
46 | 272 |
|
... | ... | |
104 | 330 |
return res.getString(R.string.solver_generic_twisted_edge,c0,c1); |
105 | 331 |
} |
106 | 332 |
|
333 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
334 |
|
|
335 |
private String edgeMonoError(Resources res, int color) |
|
336 |
{ |
|
337 |
int j0 = getColorIndex3(color); |
|
338 |
int j1 = getColorIndex6(color); |
|
339 |
String c0 = res.getString(j0); |
|
340 |
String c1 = res.getString(j1); |
|
341 |
|
|
342 |
return res.getString(R.string.solver_generic_edge_mono,c0,c1); |
|
343 |
} |
|
344 |
|
|
107 | 345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
108 | 346 |
|
109 | 347 |
public String error(int index, Resources res) |
110 | 348 |
{ |
111 | 349 |
switch(index) |
112 | 350 |
{ |
113 |
case ERROR_EDGE_MISSING : return edgeMissingError(res,mErrorColor1,mErrorColor2); |
|
114 |
case ERROR_EDGE_TWISTED : return edgeTwistedError(res,mErrorColor1,mErrorColor2); |
|
115 |
case ERROR_EDGE_CANNOT : return res.getString(R.string.solver_generic_edges_cannot); |
|
351 |
case ERROR_EDGE_MISSING : return edgeMissingError(res,mErrorColor1,mErrorColor2); |
|
352 |
case ERROR_EDGE_TWISTED : return edgeTwistedError(res,mErrorColor1,mErrorColor2); |
|
353 |
case ERROR_EDGE_MONOCHROMATIC: return edgeMonoError(res,mErrorColor1); |
|
354 |
case ERROR_EDGE_CANNOT : return res.getString(R.string.solver_generic_edges_cannot); |
|
116 | 355 |
} |
117 | 356 |
|
118 | 357 |
return null; |
src/main/res/values-de/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">Oktaederstücke können nicht so verdreht werden, sodass alle Seiten einfarbig sind!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">Kanten können nicht verdreht werden, sodass alle Seiten einfarbig sind!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">Oktaederstücke und Tetraederecken passen nicht zusammen!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s-%2$s Kante?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">Es gibt nur %1$d %2$s Facelets.</string> |
103 | 104 |
<string name="solver_cube3_error2">Nicht alle 12 Kanten gibt es genau einmal!</string> |
src/main/res/values-es/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">¡Las piezas octaédricas no se pueden torcer para que todos los lados sean monocromáticos!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">¡Los bordes no se pueden torcer para que todos los lados sean monocromáticos!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">¡Las piezas octaédricas y las esquinas tetraédricas no coinciden!</string> |
101 |
<string name="solver_generic_edge_mono">Borde %1$s-%2$s?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">Solo hay %1$d facetas %2$s.</string> |
103 | 104 |
<string name="solver_cube3_error2">¡No todos los 12 bordes existen exactamente una vez!</string> |
src/main/res/values-fr/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">Les pièces octaédriques ne peuvent pas être tordues afin que tous les côtés soient monochromes !</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">Les bords ne peuvent pas être tordus pour que tous les côtés soient monochromes !</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">Les pièces octaédriques et les coins tétraédriques ne correspondent pas !</string> |
101 |
<string name="solver_generic_edge_mono">Bord %1$s-%2$s?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">Il n\'y a que %1$d facettes %2$s.</string> |
103 | 104 |
<string name="solver_cube3_error2">Les 12 arêtes n\'existent pas exactement une fois !</string> |
src/main/res/values-ja/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">すべての面が単色になるように、八面体のピースをねじることはできません。</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">すべての面が単色になるようにエッジをねじることはできません。</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">八面体のピースと四面体の角が一致しません!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s%2$s エッジ?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">%2$s小顔は%1$dつだけ</string> |
103 | 104 |
<string name="solver_cube3_error2">12 のエッジすべてが 存在するわけではありません。</string> |
src/main/res/values-ko/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">팔면체 조각은 뒤틀릴 수 없으므로 모든면이 단색입니다!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">모든 면이 단색이 되도록 가장자리를 비틀 수 없습니다!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">팔면체 조각과 사면체 모서리가 일치하지 않습니다!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s%2$s 에지?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">%2$s작은 얼굴은 %1$d개뿐입니다.</string> |
103 | 104 |
<string name="solver_cube3_error2">12개의 가장자리 모두가 정확하게 한 번 존재하지 않습니다!</string> |
src/main/res/values-pl/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">Części ośmiościennych nie da się skręcić tak, aby wszystkie boki były monochromatyczne!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">Krawędzi nie da się skręcić tak, aby wszystkie boki były monochromatyczne!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">Części ośmiościenne i czworościenne rogi nie pasują do siebie!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s-%2$s krawędz?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">Jest tylko %1$d %2$s ścian.</string> |
103 | 104 |
<string name="solver_cube3_error2">Któraś z 12 krawędzi nie istnieje!</string> |
src/main/res/values-ru/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">Восьмигранные фигуры нельзя скрутить так, чтобы все стороны были однотонными!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">Ребр нельзя скрутить так, чтобы все стороны были однотонными!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">Восьмигранные фигуры и четырехгранные углы не совпадают!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s-%2$s ребрo?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">Всего %1$d %2$s граней!</string> |
103 | 104 |
<string name="solver_cube3_error2">Не все 12 ребер существуют в единичном экземпляре!</string> |
src/main/res/values-zh-rCN/strings.xml | ||
---|---|---|
104 | 104 |
<string name="solver_generic_vertices_cannot">八面体块不能扭曲,所以所有面都是单色的!</string> |
105 | 105 |
<string name="solver_generic_edges_cannot">边缘不能扭曲,所以所有的面都是单色的!</string> |
106 | 106 |
<string name="solver_generic_c_v_dont_match">八面体块和四面体角不匹配!</string> |
107 |
<string name="solver_generic_edge_mono">%1$s%2$s 边缘?</string> |
|
107 | 108 |
|
108 | 109 |
<string name="solver_cube3_error1">只有%1$d个%2$s小面</string> |
109 | 110 |
<string name="solver_cube3_error2">并非所有12条边都只存在一次!</string> |
src/main/res/values-zh-rTW/strings.xml | ||
---|---|---|
98 | 98 |
<string name="solver_generic_vertices_cannot">八面體塊不能扭曲,所以所有面都是單色的!</string> |
99 | 99 |
<string name="solver_generic_edges_cannot">邊緣不能扭曲,所以所有的面都是單色的!</string> |
100 | 100 |
<string name="solver_generic_c_v_dont_match">八面體塊和四面體角不匹配!</string> |
101 |
<string name="solver_generic_edge_mono">%1$s%2$s 邊緣?</string> |
|
101 | 102 |
|
102 | 103 |
<string name="solver_cube3_error1">只有%1$d個%2$s小臉</string> |
103 | 104 |
<string name="solver_cube3_error2">並非所有12條邊都只存在一次!</string> |
src/main/res/values/strings.xml | ||
---|---|---|
118 | 118 |
<string name="solver_generic_vertices_cannot">Octahedral pieces cannot be twisted so that all faces are monochromatic!</string> |
119 | 119 |
<string name="solver_generic_edges_cannot">Edges cannot be twisted so that all faces are monochromatic!</string> |
120 | 120 |
<string name="solver_generic_c_v_dont_match">Octahedral pieces and tetrahedral corners do not match!</string> |
121 |
<string name="solver_generic_edge_mono">%1$s-%2$s edge?</string> |
|
121 | 122 |
|
122 | 123 |
<string name="solver_cube3_error1">There are only %1$d %2$s facelets.</string> |
123 | 124 |
<string name="solver_cube3_error2">Not all 12 edges exist exactly once!</string> |
Also available in: Unified diff
Dino6 solver: skeleton.