Revision c3e246e7
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/solvers/SolverMain.java | ||
---|---|---|
17 | 17 |
import org.distorted.main.R; |
18 | 18 |
import org.distorted.screens.ScreenList; |
19 | 19 |
import org.distorted.screens.RubikScreenSolver; |
20 |
import org.distorted.solvers.pduo.SolverPyraminxDuo; |
|
21 | 20 |
|
22 | 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 22 |
|
src/main/java/org/distorted/solvers/SolverPyraminxDuo.java | ||
---|---|---|
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.TwistyObject; |
|
16 |
import org.distorted.objectlib.tablebases.TablebasesPyraminxDuo; |
|
17 |
|
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
public class SolverPyraminxDuo extends SolverTablebase |
|
21 |
{ |
|
22 |
private static final int ERROR_CORNER_GYB_MISSING = -1; |
|
23 |
private static final int ERROR_CORNER_GYR_MISSING = -2; |
|
24 |
private static final int ERROR_CORNER_GBR_MISSING = -3; |
|
25 |
private static final int ERROR_CORNER_YBR_MISSING = -4; |
|
26 |
|
|
27 |
private static final int ERROR_CENTER_G_MISSING = -5; |
|
28 |
private static final int ERROR_CENTER_Y_MISSING = -6; |
|
29 |
private static final int ERROR_CENTER_B_MISSING = -7; |
|
30 |
private static final int ERROR_CENTER_R_MISSING = -8; |
|
31 |
|
|
32 |
private static final int ERROR_TWO_CENTERS_SWAP = -9; |
|
33 |
private static final int ERROR_CORNER_TWISTED = -10; |
|
34 |
|
|
35 |
private static final int ERROR_CORNERS_CANNOT = -11; |
|
36 |
|
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
private boolean cornerEqual(int[] corner, int c1, int c2, int c3) |
|
41 |
{ |
|
42 |
return ( (corner[0]==c1 && corner[1]==c2 && corner[2]==c3) || |
|
43 |
(corner[0]==c1 && corner[2]==c2 && corner[1]==c3) || |
|
44 |
(corner[1]==c1 && corner[0]==c2 && corner[2]==c3) || |
|
45 |
(corner[1]==c1 && corner[2]==c2 && corner[0]==c3) || |
|
46 |
(corner[2]==c1 && corner[1]==c2 && corner[0]==c3) || |
|
47 |
(corner[2]==c1 && corner[0]==c2 && corner[1]==c3) ); |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
private int checkAllCornersPresent(int[][] corners) |
|
53 |
{ |
|
54 |
boolean ybr = false; |
|
55 |
boolean gbr = false; |
|
56 |
boolean gyr = false; |
|
57 |
boolean gyb = false; |
|
58 |
|
|
59 |
for(int i=0; i<4; i++) |
|
60 |
{ |
|
61 |
if( cornerEqual(corners[i],0,1,2) ) gyb = true; |
|
62 |
if( cornerEqual(corners[i],0,1,3) ) gyr = true; |
|
63 |
if( cornerEqual(corners[i],0,2,3) ) gbr = true; |
|
64 |
if( cornerEqual(corners[i],1,2,3) ) ybr = true; |
|
65 |
} |
|
66 |
|
|
67 |
if( !ybr ) return ERROR_CORNER_YBR_MISSING; |
|
68 |
if( !gbr ) return ERROR_CORNER_GBR_MISSING; |
|
69 |
if( !gyr ) return ERROR_CORNER_GYR_MISSING; |
|
70 |
if( !gyb ) return ERROR_CORNER_GYB_MISSING; |
|
71 |
|
|
72 |
return 0; |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
private int checkAllCentersPresent(int[] centers) |
|
78 |
{ |
|
79 |
if( centers[0]!=0 && centers[1]!=0 && centers[2]!=0 && centers[3]!=0 ) return ERROR_CENTER_G_MISSING; |
|
80 |
if( centers[0]!=1 && centers[1]!=1 && centers[2]!=1 && centers[3]!=1 ) return ERROR_CENTER_Y_MISSING; |
|
81 |
if( centers[0]!=2 && centers[1]!=2 && centers[2]!=2 && centers[3]!=2 ) return ERROR_CENTER_B_MISSING; |
|
82 |
if( centers[0]!=3 && centers[1]!=3 && centers[2]!=3 && centers[3]!=3 ) return ERROR_CENTER_R_MISSING; |
|
83 |
|
|
84 |
return 0; |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
private int getFaceOfGreenCenter(int[] centers) |
|
90 |
{ |
|
91 |
if( centers[0]==0 ) return 0; |
|
92 |
if( centers[1]==0 ) return 1; |
|
93 |
if( centers[2]==0 ) return 2; |
|
94 |
if( centers[3]==0 ) return 3; |
|
95 |
|
|
96 |
return -1; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
private int[] computeMissingCornerColor(int[][] corners) |
|
102 |
{ |
|
103 |
int[] ret = new int[4]; |
|
104 |
|
|
105 |
for(int i=0; i<4; i++) |
|
106 |
for(int j=0; j<4; j++) |
|
107 |
if( corners[i][0]!=j && corners[i][1]!=j && corners[i][2]!=j ) ret[i]=j; |
|
108 |
|
|
109 |
return ret; |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
private int computeCornerTwist(int index, int[] corner, int[] missing) |
|
115 |
{ |
|
116 |
int twist1=0, twist2=0, twist3=0; |
|
117 |
|
|
118 |
switch(index) |
|
119 |
{ |
|
120 |
case 0: if( corner[1]==missing[1] ) twist1=1; |
|
121 |
if( corner[2]==missing[1] ) twist1=2; |
|
122 |
if( corner[0]==missing[2] ) twist2=2; |
|
123 |
if( corner[2]==missing[2] ) twist2=1; |
|
124 |
if( corner[0]==missing[3] ) twist3=1; |
|
125 |
if( corner[1]==missing[3] ) twist3=2; |
|
126 |
break; |
|
127 |
case 1: if( corner[1]==missing[0] ) twist1=1; |
|
128 |
if( corner[2]==missing[0] ) twist1=2; |
|
129 |
if( corner[0]==missing[2] ) twist2=1; |
|
130 |
if( corner[1]==missing[2] ) twist2=2; |
|
131 |
if( corner[0]==missing[3] ) twist3=2; |
|
132 |
if( corner[2]==missing[3] ) twist3=1; |
|
133 |
break; |
|
134 |
case 2: if( corner[1]==missing[0] ) twist1=1; |
|
135 |
if( corner[2]==missing[0] ) twist1=2; |
|
136 |
if( corner[0]==missing[1] ) twist2=2; |
|
137 |
if( corner[2]==missing[1] ) twist2=1; |
|
138 |
if( corner[0]==missing[3] ) twist3=1; |
|
139 |
if( corner[1]==missing[3] ) twist3=2; |
|
140 |
break; |
|
141 |
case 3: if( corner[1]==missing[0] ) twist1=1; |
|
142 |
if( corner[2]==missing[0] ) twist1=2; |
|
143 |
if( corner[0]==missing[1] ) twist2=1; |
|
144 |
if( corner[1]==missing[1] ) twist2=2; |
|
145 |
if( corner[0]==missing[2] ) twist3=2; |
|
146 |
if( corner[2]==missing[2] ) twist3=1; |
|
147 |
break; |
|
148 |
} |
|
149 |
|
|
150 |
return ( twist1!=twist2 || twist1!=twist3 ) ? ERROR_CORNERS_CANNOT : twist1; |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
private int computeCenterTwist(int[] centers, int color1, int color2) |
|
156 |
{ |
|
157 |
if( centers[0]==color1 ) |
|
158 |
{ |
|
159 |
if( centers[1]==color2 ) return 1; |
|
160 |
if( centers[2]==color2 ) return 2; |
|
161 |
if( centers[3]==color2 ) return 0; |
|
162 |
|
|
163 |
return -1; |
|
164 |
} |
|
165 |
if( centers[1]==color1 ) |
|
166 |
{ |
|
167 |
if( centers[0]==color2 ) return 1; |
|
168 |
if( centers[2]==color2 ) return 0; |
|
169 |
if( centers[3]==color2 ) return 2; |
|
170 |
|
|
171 |
return -1; |
|
172 |
} |
|
173 |
if( centers[2]==color1 ) |
|
174 |
{ |
|
175 |
if( centers[0]==color2 ) return 2; |
|
176 |
if( centers[1]==color2 ) return 0; |
|
177 |
if( centers[3]==color2 ) return 1; |
|
178 |
|
|
179 |
return -1; |
|
180 |
} |
|
181 |
if( centers[3]==color1 ) |
|
182 |
{ |
|
183 |
if( centers[0]==color2 ) return 0; |
|
184 |
if( centers[1]==color2 ) return 2; |
|
185 |
if( centers[2]==color2 ) return 1; |
|
186 |
|
|
187 |
return -1; |
|
188 |
} |
|
189 |
|
|
190 |
return -2; |
|
191 |
} |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public SolverPyraminxDuo(Resources res, TwistyObject object) |
|
196 |
{ |
|
197 |
super(res,object); |
|
198 |
} |
|
199 |
|
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public int tablebaseIndex(TwistyObject object) |
|
203 |
{ |
|
204 |
int[][] corners = new int[4][3]; |
|
205 |
int[] centers = new int[4]; |
|
206 |
int[] corner_twist = new int[4]; |
|
207 |
|
|
208 |
for(int i=0; i<4; i++) |
|
209 |
{ |
|
210 |
centers[i] = object.getCubitFaceStickerIndex(i+4,0) - 4; |
|
211 |
|
|
212 |
for(int j=0; j<3; j++) |
|
213 |
corners[i][j] = object.getCubitFaceStickerIndex(i,j); |
|
214 |
} |
|
215 |
|
|
216 |
int result1 = checkAllCornersPresent(corners); |
|
217 |
if( result1<0 ) return result1; |
|
218 |
|
|
219 |
int result2 = checkAllCentersPresent(centers); |
|
220 |
if( result2<0 ) return result2; |
|
221 |
|
|
222 |
int twist_gr = computeCenterTwist(centers,0,3); |
|
223 |
int twist_ry = computeCenterTwist(centers,3,1); |
|
224 |
|
|
225 |
if( (twist_ry-twist_gr+1)%3 != 0 ) return ERROR_TWO_CENTERS_SWAP; |
|
226 |
|
|
227 |
int total_twist=0; |
|
228 |
int[] missing = computeMissingCornerColor(corners); |
|
229 |
|
|
230 |
for(int i=0; i<4; i++) |
|
231 |
{ |
|
232 |
corner_twist[i] = computeCornerTwist(i,corners[i],missing); |
|
233 |
if( corner_twist[i]<0 ) return corner_twist[i]; |
|
234 |
total_twist += corner_twist[i]; |
|
235 |
} |
|
236 |
|
|
237 |
if( (total_twist-twist_gr)%3 !=0 ) return ERROR_CORNER_TWISTED; |
|
238 |
|
|
239 |
int green_face = getFaceOfGreenCenter(centers); |
|
240 |
|
|
241 |
return green_face + 4*(corner_twist[3] + 3*(corner_twist[2] + 3*(corner_twist[1] + 3*corner_twist[0]))); |
|
242 |
} |
|
243 |
|
|
244 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 |
|
|
246 |
public String error(int index, Resources res) |
|
247 |
{ |
|
248 |
switch(index) |
|
249 |
{ |
|
250 |
case ERROR_CORNER_YBR_MISSING: String c01 = res.getString(R.string.color_yellow3); |
|
251 |
String c02 = res.getString(R.string.color_blue3); |
|
252 |
String c03 = res.getString(R.string.color_red4); |
|
253 |
return res.getString(R.string.solver_generic_missing_corner,c01,c02,c03); |
|
254 |
case ERROR_CORNER_GBR_MISSING: String c11 = res.getString(R.string.color_green3); |
|
255 |
String c12 = res.getString(R.string.color_blue3); |
|
256 |
String c13 = res.getString(R.string.color_red4); |
|
257 |
return res.getString(R.string.solver_generic_missing_corner,c11,c12,c13); |
|
258 |
case ERROR_CORNER_GYR_MISSING: String c21 = res.getString(R.string.color_green3); |
|
259 |
String c22 = res.getString(R.string.color_yellow3); |
|
260 |
String c23 = res.getString(R.string.color_red4); |
|
261 |
return res.getString(R.string.solver_generic_missing_corner,c21,c22,c23); |
|
262 |
case ERROR_CORNER_GYB_MISSING: String c31 = res.getString(R.string.color_green3); |
|
263 |
String c32 = res.getString(R.string.color_yellow3); |
|
264 |
String c33 = res.getString(R.string.color_blue4); |
|
265 |
return res.getString(R.string.solver_generic_missing_corner,c31,c32,c33); |
|
266 |
case ERROR_CENTER_G_MISSING : String colorG = res.getString(R.string.color_green2); |
|
267 |
return res.getString(R.string.solver_generic_missing_center,colorG); |
|
268 |
case ERROR_CENTER_Y_MISSING : String colorY = res.getString(R.string.color_yellow2); |
|
269 |
return res.getString(R.string.solver_generic_missing_center,colorY); |
|
270 |
case ERROR_CENTER_B_MISSING : String colorB = res.getString(R.string.color_blue2); |
|
271 |
return res.getString(R.string.solver_generic_missing_center,colorB); |
|
272 |
case ERROR_CENTER_R_MISSING : String colorR = res.getString(R.string.color_red2); |
|
273 |
return res.getString(R.string.solver_generic_missing_center,colorR); |
|
274 |
case ERROR_TWO_CENTERS_SWAP : return res.getString(R.string.solver_generic_two_centers); |
|
275 |
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist); |
|
276 |
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot); |
|
277 |
} |
|
278 |
|
|
279 |
return null; |
|
280 |
} |
|
281 |
|
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
public String solution(int index, Resources res) |
|
285 |
{ |
|
286 |
TablebasesPyraminxDuo tb = new TablebasesPyraminxDuo(); |
|
287 |
tb.createTablebase(); |
|
288 |
|
|
289 |
return ""; |
|
290 |
} |
|
291 |
} |
|
292 |
|
src/main/java/org/distorted/solvers/pduo/SolverPyraminxDuo.java | ||
---|---|---|
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.pduo; |
|
11 |
|
|
12 |
import android.content.res.Resources; |
|
13 |
|
|
14 |
import org.distorted.main.R; |
|
15 |
import org.distorted.objectlib.main.TwistyObject; |
|
16 |
import org.distorted.solvers.SolverTablebase; |
|
17 |
|
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
public class SolverPyraminxDuo extends SolverTablebase |
|
21 |
{ |
|
22 |
private static final int ERROR_CORNER_GYB_MISSING = -1; |
|
23 |
private static final int ERROR_CORNER_GYR_MISSING = -2; |
|
24 |
private static final int ERROR_CORNER_GBR_MISSING = -3; |
|
25 |
private static final int ERROR_CORNER_YBR_MISSING = -4; |
|
26 |
|
|
27 |
private static final int ERROR_CENTER_G_MISSING = -5; |
|
28 |
private static final int ERROR_CENTER_Y_MISSING = -6; |
|
29 |
private static final int ERROR_CENTER_B_MISSING = -7; |
|
30 |
private static final int ERROR_CENTER_R_MISSING = -8; |
|
31 |
|
|
32 |
private static final int ERROR_TWO_CENTERS_SWAP = -9; |
|
33 |
private static final int ERROR_CORNER_TWISTED = -10; |
|
34 |
|
|
35 |
private static final int ERROR_CORNERS_CANNOT = -11; |
|
36 |
|
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
private boolean cornerEqual(int[] corner, int c1, int c2, int c3) |
|
41 |
{ |
|
42 |
return ( (corner[0]==c1 && corner[1]==c2 && corner[2]==c3) || |
|
43 |
(corner[0]==c1 && corner[2]==c2 && corner[1]==c3) || |
|
44 |
(corner[1]==c1 && corner[0]==c2 && corner[2]==c3) || |
|
45 |
(corner[1]==c1 && corner[2]==c2 && corner[0]==c3) || |
|
46 |
(corner[2]==c1 && corner[1]==c2 && corner[0]==c3) || |
|
47 |
(corner[2]==c1 && corner[0]==c2 && corner[1]==c3) ); |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
private int checkAllCornersPresent(int[][] corners) |
|
53 |
{ |
|
54 |
boolean ybr = false; |
|
55 |
boolean gbr = false; |
|
56 |
boolean gyr = false; |
|
57 |
boolean gyb = false; |
|
58 |
|
|
59 |
for(int i=0; i<4; i++) |
|
60 |
{ |
|
61 |
if( cornerEqual(corners[i],0,1,2) ) gyb = true; |
|
62 |
if( cornerEqual(corners[i],0,1,3) ) gyr = true; |
|
63 |
if( cornerEqual(corners[i],0,2,3) ) gbr = true; |
|
64 |
if( cornerEqual(corners[i],1,2,3) ) ybr = true; |
|
65 |
} |
|
66 |
|
|
67 |
if( !ybr ) return ERROR_CORNER_YBR_MISSING; |
|
68 |
if( !gbr ) return ERROR_CORNER_GBR_MISSING; |
|
69 |
if( !gyr ) return ERROR_CORNER_GYR_MISSING; |
|
70 |
if( !gyb ) return ERROR_CORNER_GYB_MISSING; |
|
71 |
|
|
72 |
return 0; |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
private int checkAllCentersPresent(int[] centers) |
|
78 |
{ |
|
79 |
if( centers[0]!=0 && centers[1]!=0 && centers[2]!=0 && centers[3]!=0 ) return ERROR_CENTER_G_MISSING; |
|
80 |
if( centers[0]!=1 && centers[1]!=1 && centers[2]!=1 && centers[3]!=1 ) return ERROR_CENTER_Y_MISSING; |
|
81 |
if( centers[0]!=2 && centers[1]!=2 && centers[2]!=2 && centers[3]!=2 ) return ERROR_CENTER_B_MISSING; |
|
82 |
if( centers[0]!=3 && centers[1]!=3 && centers[2]!=3 && centers[3]!=3 ) return ERROR_CENTER_R_MISSING; |
|
83 |
|
|
84 |
return 0; |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
private int getFaceOfGreenCenter(int[] centers) |
|
90 |
{ |
|
91 |
if( centers[0]==0 ) return 0; |
|
92 |
if( centers[1]==0 ) return 1; |
|
93 |
if( centers[2]==0 ) return 2; |
|
94 |
if( centers[3]==0 ) return 3; |
|
95 |
|
|
96 |
return -1; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
private int[] computeMissingCornerColor(int[][] corners) |
|
102 |
{ |
|
103 |
int[] ret = new int[4]; |
|
104 |
|
|
105 |
for(int i=0; i<4; i++) |
|
106 |
for(int j=0; j<4; j++) |
|
107 |
if( corners[i][0]!=j && corners[i][1]!=j && corners[i][2]!=j ) ret[i]=j; |
|
108 |
|
|
109 |
return ret; |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
private int computeCornerTwist(int index, int[] corner, int[] missing) |
|
115 |
{ |
|
116 |
int twist1=0, twist2=0, twist3=0; |
|
117 |
|
|
118 |
switch(index) |
|
119 |
{ |
|
120 |
case 0: if( corner[1]==missing[1] ) twist1=1; |
|
121 |
if( corner[2]==missing[1] ) twist1=2; |
|
122 |
if( corner[0]==missing[2] ) twist2=2; |
|
123 |
if( corner[2]==missing[2] ) twist2=1; |
|
124 |
if( corner[0]==missing[3] ) twist3=1; |
|
125 |
if( corner[1]==missing[3] ) twist3=2; |
|
126 |
break; |
|
127 |
case 1: if( corner[1]==missing[0] ) twist1=1; |
|
128 |
if( corner[2]==missing[0] ) twist1=2; |
|
129 |
if( corner[0]==missing[2] ) twist2=1; |
|
130 |
if( corner[1]==missing[2] ) twist2=2; |
|
131 |
if( corner[0]==missing[3] ) twist3=2; |
|
132 |
if( corner[2]==missing[3] ) twist3=1; |
|
133 |
break; |
|
134 |
case 2: if( corner[1]==missing[0] ) twist1=1; |
|
135 |
if( corner[2]==missing[0] ) twist1=2; |
|
136 |
if( corner[0]==missing[1] ) twist2=2; |
|
137 |
if( corner[2]==missing[1] ) twist2=1; |
|
138 |
if( corner[0]==missing[3] ) twist3=1; |
|
139 |
if( corner[1]==missing[3] ) twist3=2; |
|
140 |
break; |
|
141 |
case 3: if( corner[1]==missing[0] ) twist1=1; |
|
142 |
if( corner[2]==missing[0] ) twist1=2; |
|
143 |
if( corner[0]==missing[1] ) twist2=1; |
|
144 |
if( corner[1]==missing[1] ) twist2=2; |
|
145 |
if( corner[0]==missing[2] ) twist3=2; |
|
146 |
if( corner[2]==missing[2] ) twist3=1; |
|
147 |
break; |
|
148 |
} |
|
149 |
|
|
150 |
return ( twist1!=twist2 || twist1!=twist3 ) ? ERROR_CORNERS_CANNOT : twist1; |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
private int computeCenterTwist(int[] centers, int color1, int color2) |
|
156 |
{ |
|
157 |
if( centers[0]==color1 ) |
|
158 |
{ |
|
159 |
if( centers[1]==color2 ) return 1; |
|
160 |
if( centers[2]==color2 ) return 2; |
|
161 |
if( centers[3]==color2 ) return 0; |
|
162 |
|
|
163 |
return -1; |
|
164 |
} |
|
165 |
if( centers[1]==color1 ) |
|
166 |
{ |
|
167 |
if( centers[0]==color2 ) return 1; |
|
168 |
if( centers[2]==color2 ) return 0; |
|
169 |
if( centers[3]==color2 ) return 2; |
|
170 |
|
|
171 |
return -1; |
|
172 |
} |
|
173 |
if( centers[2]==color1 ) |
|
174 |
{ |
|
175 |
if( centers[0]==color2 ) return 2; |
|
176 |
if( centers[1]==color2 ) return 0; |
|
177 |
if( centers[3]==color2 ) return 1; |
|
178 |
|
|
179 |
return -1; |
|
180 |
} |
|
181 |
if( centers[3]==color1 ) |
|
182 |
{ |
|
183 |
if( centers[0]==color2 ) return 0; |
|
184 |
if( centers[1]==color2 ) return 2; |
|
185 |
if( centers[2]==color2 ) return 1; |
|
186 |
|
|
187 |
return -1; |
|
188 |
} |
|
189 |
|
|
190 |
return -2; |
|
191 |
} |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public SolverPyraminxDuo(Resources res, TwistyObject object) |
|
196 |
{ |
|
197 |
super(res,object); |
|
198 |
} |
|
199 |
|
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public int tablebaseIndex(TwistyObject object) |
|
203 |
{ |
|
204 |
int[][] corners = new int[4][3]; |
|
205 |
int[] centers = new int[4]; |
|
206 |
int[] corner_twist = new int[4]; |
|
207 |
|
|
208 |
for(int i=0; i<4; i++) |
|
209 |
{ |
|
210 |
centers[i] = object.getCubitFaceStickerIndex(i+4,0) - 4; |
|
211 |
|
|
212 |
for(int j=0; j<3; j++) |
|
213 |
corners[i][j] = object.getCubitFaceStickerIndex(i,j); |
|
214 |
} |
|
215 |
|
|
216 |
int result1 = checkAllCornersPresent(corners); |
|
217 |
if( result1<0 ) return result1; |
|
218 |
|
|
219 |
int result2 = checkAllCentersPresent(centers); |
|
220 |
if( result2<0 ) return result2; |
|
221 |
|
|
222 |
int twist_gr = computeCenterTwist(centers,0,3); |
|
223 |
int twist_ry = computeCenterTwist(centers,3,1); |
|
224 |
|
|
225 |
if( (twist_ry-twist_gr+1)%3 != 0 ) return ERROR_TWO_CENTERS_SWAP; |
|
226 |
|
|
227 |
int total_twist=0; |
|
228 |
int[] missing = computeMissingCornerColor(corners); |
|
229 |
|
|
230 |
for(int i=0; i<4; i++) |
|
231 |
{ |
|
232 |
corner_twist[i] = computeCornerTwist(i,corners[i],missing); |
|
233 |
if( corner_twist[i]<0 ) return corner_twist[i]; |
|
234 |
total_twist += corner_twist[i]; |
|
235 |
} |
|
236 |
|
|
237 |
if( (total_twist-twist_gr)%3 !=0 ) return ERROR_CORNER_TWISTED; |
|
238 |
|
|
239 |
int green_face = getFaceOfGreenCenter(centers); |
|
240 |
|
|
241 |
return green_face + 4*(corner_twist[3] + 3*(corner_twist[2] + 3*(corner_twist[1] + 3*corner_twist[0]))); |
|
242 |
} |
|
243 |
|
|
244 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 |
|
|
246 |
public String error(int index, Resources res) |
|
247 |
{ |
|
248 |
switch(index) |
|
249 |
{ |
|
250 |
case ERROR_CORNER_YBR_MISSING: String c01 = res.getString(R.string.color_yellow3); |
|
251 |
String c02 = res.getString(R.string.color_blue3); |
|
252 |
String c03 = res.getString(R.string.color_red4); |
|
253 |
return res.getString(R.string.solver_generic_missing_corner,c01,c02,c03); |
|
254 |
case ERROR_CORNER_GBR_MISSING: String c11 = res.getString(R.string.color_green3); |
|
255 |
String c12 = res.getString(R.string.color_blue3); |
|
256 |
String c13 = res.getString(R.string.color_red4); |
|
257 |
return res.getString(R.string.solver_generic_missing_corner,c11,c12,c13); |
|
258 |
case ERROR_CORNER_GYR_MISSING: String c21 = res.getString(R.string.color_green3); |
|
259 |
String c22 = res.getString(R.string.color_yellow3); |
|
260 |
String c23 = res.getString(R.string.color_red4); |
|
261 |
return res.getString(R.string.solver_generic_missing_corner,c21,c22,c23); |
|
262 |
case ERROR_CORNER_GYB_MISSING: String c31 = res.getString(R.string.color_green3); |
|
263 |
String c32 = res.getString(R.string.color_yellow3); |
|
264 |
String c33 = res.getString(R.string.color_blue4); |
|
265 |
return res.getString(R.string.solver_generic_missing_corner,c31,c32,c33); |
|
266 |
case ERROR_CENTER_G_MISSING : String colorG = res.getString(R.string.color_green2); |
|
267 |
return res.getString(R.string.solver_generic_missing_center,colorG); |
|
268 |
case ERROR_CENTER_Y_MISSING : String colorY = res.getString(R.string.color_yellow2); |
|
269 |
return res.getString(R.string.solver_generic_missing_center,colorY); |
|
270 |
case ERROR_CENTER_B_MISSING : String colorB = res.getString(R.string.color_blue2); |
|
271 |
return res.getString(R.string.solver_generic_missing_center,colorB); |
|
272 |
case ERROR_CENTER_R_MISSING : String colorR = res.getString(R.string.color_red2); |
|
273 |
return res.getString(R.string.solver_generic_missing_center,colorR); |
|
274 |
case ERROR_TWO_CENTERS_SWAP : return res.getString(R.string.solver_generic_two_centers); |
|
275 |
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist); |
|
276 |
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot); |
|
277 |
} |
|
278 |
|
|
279 |
return null; |
|
280 |
} |
|
281 |
|
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
public String solution(int index, Resources res) |
|
285 |
{ |
|
286 |
return ""; |
|
287 |
} |
|
288 |
} |
|
289 |
|
src/main/java/org/distorted/solvers/pduo/TablebasesPyraminxDuo.java | ||
---|---|---|
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.pduo; |
|
11 |
|
|
12 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
13 |
|
|
14 |
public class TablebasesPyraminxDuo |
|
15 |
{ |
|
16 |
|
|
17 |
} |
|
18 |
|
Also available in: Unified diff
Pyraminx Duo solver: initial code which creates the unpacked DB (does not work still)