1 |
420eb96d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
ca278d11
|
Leszek Koltunski
|
import org.distorted.main.R;
|
15 |
420eb96d
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
16 |
|
|
import org.distorted.solvers.SolverTablebase;
|
17 |
|
|
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
public class SolverPyraminxDuo extends SolverTablebase
|
21 |
|
|
{
|
22 |
ca278d11
|
Leszek Koltunski
|
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 |
7bdd481b
|
Leszek Koltunski
|
|
27 |
ca278d11
|
Leszek Koltunski
|
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 |
7bdd481b
|
Leszek Koltunski
|
|
32 |
ca278d11
|
Leszek Koltunski
|
private static final int ERROR_TWO_CENTERS_SWAP = -9;
|
33 |
|
|
private static final int ERROR_CORNER_TWISTED = -10;
|
34 |
|
|
|
35 |
3cf8f87d
|
Leszek Koltunski
|
private static final int ERROR_EDGE_GY = -11;
|
36 |
|
|
private static final int ERROR_EDGE_GB = -12;
|
37 |
|
|
private static final int ERROR_EDGE_GR = -13;
|
38 |
|
|
private static final int ERROR_EDGE_YB = -14;
|
39 |
|
|
private static final int ERROR_EDGE_YR = -15;
|
40 |
|
|
private static final int ERROR_EDGE_BR = -16;
|
41 |
|
|
|
42 |
ca278d11
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
private boolean cornerEqual(int[] corner, int c1, int c2, int c3)
|
45 |
|
|
{
|
46 |
|
|
return ( (corner[0]==c1 && corner[1]==c2 && corner[2]==c3) ||
|
47 |
|
|
(corner[0]==c1 && corner[2]==c2 && corner[1]==c3) ||
|
48 |
|
|
(corner[1]==c1 && corner[0]==c2 && corner[2]==c3) ||
|
49 |
|
|
(corner[1]==c1 && corner[2]==c2 && corner[0]==c3) ||
|
50 |
|
|
(corner[2]==c1 && corner[1]==c2 && corner[0]==c3) ||
|
51 |
|
|
(corner[2]==c1 && corner[0]==c2 && corner[1]==c3) );
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
private int checkAllCornersPresent(int[][] corners)
|
57 |
|
|
{
|
58 |
|
|
boolean ybr = false;
|
59 |
|
|
boolean gbr = false;
|
60 |
|
|
boolean gyr = false;
|
61 |
|
|
boolean gyb = false;
|
62 |
|
|
|
63 |
|
|
for(int i=0; i<4; i++)
|
64 |
|
|
{
|
65 |
|
|
if( cornerEqual(corners[i],0,1,2) ) gyb = true;
|
66 |
|
|
if( cornerEqual(corners[i],0,1,3) ) gyr = true;
|
67 |
|
|
if( cornerEqual(corners[i],0,2,3) ) gbr = true;
|
68 |
|
|
if( cornerEqual(corners[i],1,2,3) ) ybr = true;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
if( !ybr ) return ERROR_CORNER_YBR_MISSING;
|
72 |
|
|
if( !gbr ) return ERROR_CORNER_GBR_MISSING;
|
73 |
|
|
if( !gyr ) return ERROR_CORNER_GYR_MISSING;
|
74 |
|
|
if( !gyb ) return ERROR_CORNER_GYB_MISSING;
|
75 |
|
|
|
76 |
|
|
return 0;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
private int checkAllCentersPresent(int[] centers)
|
82 |
|
|
{
|
83 |
|
|
if( centers[0]!=0 && centers[1]!=0 && centers[2]!=0 && centers[3]!=0 ) return ERROR_CENTER_G_MISSING;
|
84 |
|
|
if( centers[0]!=1 && centers[1]!=1 && centers[2]!=1 && centers[3]!=1 ) return ERROR_CENTER_Y_MISSING;
|
85 |
|
|
if( centers[0]!=2 && centers[1]!=2 && centers[2]!=2 && centers[3]!=2 ) return ERROR_CENTER_B_MISSING;
|
86 |
|
|
if( centers[0]!=3 && centers[1]!=3 && centers[2]!=3 && centers[3]!=3 ) return ERROR_CENTER_R_MISSING;
|
87 |
|
|
|
88 |
|
|
return 0;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
|
93 |
|
|
private int getFaceOfGreenCenter(int[] centers)
|
94 |
|
|
{
|
95 |
|
|
if( centers[0]==0 ) return 0;
|
96 |
|
|
if( centers[1]==0 ) return 1;
|
97 |
|
|
if( centers[2]==0 ) return 2;
|
98 |
|
|
if( centers[3]==0 ) return 3;
|
99 |
|
|
|
100 |
|
|
return -1;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
3cf8f87d
|
Leszek Koltunski
|
private int computeCornerTwist(int index, int[][] corners)
|
106 |
ca278d11
|
Leszek Koltunski
|
{
|
107 |
3cf8f87d
|
Leszek Koltunski
|
return 0; // TODO
|
108 |
ca278d11
|
Leszek Koltunski
|
}
|
109 |
|
|
|
110 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111 |
|
|
|
112 |
|
|
private int computeCenterTwist(int[] centers, int color1, int color2)
|
113 |
|
|
{
|
114 |
|
|
if( centers[0]==color1 )
|
115 |
|
|
{
|
116 |
|
|
if( centers[1]==color2 ) return 1;
|
117 |
3cf8f87d
|
Leszek Koltunski
|
if( centers[2]==color2 ) return 2;
|
118 |
|
|
if( centers[3]==color2 ) return 0;
|
119 |
ca278d11
|
Leszek Koltunski
|
|
120 |
|
|
return -1;
|
121 |
|
|
}
|
122 |
|
|
if( centers[1]==color1 )
|
123 |
|
|
{
|
124 |
|
|
if( centers[0]==color2 ) return 1;
|
125 |
3cf8f87d
|
Leszek Koltunski
|
if( centers[2]==color2 ) return 0;
|
126 |
|
|
if( centers[3]==color2 ) return 2;
|
127 |
ca278d11
|
Leszek Koltunski
|
|
128 |
|
|
return -1;
|
129 |
|
|
}
|
130 |
|
|
if( centers[2]==color1 )
|
131 |
|
|
{
|
132 |
3cf8f87d
|
Leszek Koltunski
|
if( centers[0]==color2 ) return 2;
|
133 |
|
|
if( centers[1]==color2 ) return 0;
|
134 |
ca278d11
|
Leszek Koltunski
|
if( centers[3]==color2 ) return 1;
|
135 |
|
|
|
136 |
|
|
return -1;
|
137 |
|
|
}
|
138 |
|
|
if( centers[3]==color1 )
|
139 |
|
|
{
|
140 |
3cf8f87d
|
Leszek Koltunski
|
if( centers[0]==color2 ) return 0;
|
141 |
|
|
if( centers[1]==color2 ) return 2;
|
142 |
ca278d11
|
Leszek Koltunski
|
if( centers[2]==color2 ) return 1;
|
143 |
|
|
|
144 |
|
|
return -1;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
return -2;
|
148 |
|
|
}
|
149 |
420eb96d
|
Leszek Koltunski
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
|
|
public SolverPyraminxDuo(Resources res, TwistyObject object)
|
153 |
|
|
{
|
154 |
|
|
super(res,object);
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158 |
7bdd481b
|
Leszek Koltunski
|
|
159 |
ca278d11
|
Leszek Koltunski
|
public int tablebaseIndex(TwistyObject object)
|
160 |
420eb96d
|
Leszek Koltunski
|
{
|
161 |
ca278d11
|
Leszek Koltunski
|
int[][] corners = new int[4][3];
|
162 |
|
|
int[] centers = new int[4];
|
163 |
3cf8f87d
|
Leszek Koltunski
|
int[] corner_twist = new int[4];
|
164 |
ca278d11
|
Leszek Koltunski
|
|
165 |
|
|
for(int i=0; i<4; i++)
|
166 |
|
|
{
|
167 |
3cf8f87d
|
Leszek Koltunski
|
centers[i] = object.getCubitFaceStickerIndex(i+4,0) - 4;
|
168 |
ca278d11
|
Leszek Koltunski
|
|
169 |
|
|
for(int j=0; j<3; j++)
|
170 |
|
|
corners[i][j] = object.getCubitFaceStickerIndex(i,j);
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
int result1 = checkAllCornersPresent(corners);
|
174 |
|
|
if( result1<0 ) return result1;
|
175 |
|
|
|
176 |
|
|
int result2 = checkAllCentersPresent(centers);
|
177 |
|
|
if( result2<0 ) return result2;
|
178 |
|
|
|
179 |
|
|
int twist_gr = computeCenterTwist(centers,0,3);
|
180 |
|
|
int twist_ry = computeCenterTwist(centers,3,1);
|
181 |
|
|
|
182 |
|
|
if( (twist_ry-twist_gr+1)%3 != 0 ) return ERROR_TWO_CENTERS_SWAP;
|
183 |
|
|
|
184 |
3cf8f87d
|
Leszek Koltunski
|
int total_twist=0;
|
185 |
|
|
|
186 |
|
|
for(int i=0; i<4; i++)
|
187 |
|
|
{
|
188 |
|
|
corner_twist[i] = computeCornerTwist(i,corners);
|
189 |
|
|
if( corner_twist[i]<0 ) return corner_twist[i];
|
190 |
|
|
total_twist += corner_twist[i];
|
191 |
|
|
}
|
192 |
ca278d11
|
Leszek Koltunski
|
|
193 |
|
|
if( (total_twist-twist_gr)%3 !=0 ) return ERROR_CORNER_TWISTED;
|
194 |
|
|
|
195 |
|
|
int green_face = getFaceOfGreenCenter(centers);
|
196 |
|
|
|
197 |
3cf8f87d
|
Leszek Koltunski
|
return green_face + 4*(corner_twist[3] + 3*(corner_twist[2] + 3*(corner_twist[1] + 3*corner_twist[0])));
|
198 |
420eb96d
|
Leszek Koltunski
|
}
|
199 |
|
|
|
200 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
7bdd481b
|
Leszek Koltunski
|
|
202 |
ca278d11
|
Leszek Koltunski
|
public String error(int index, Resources res)
|
203 |
420eb96d
|
Leszek Koltunski
|
{
|
204 |
ca278d11
|
Leszek Koltunski
|
switch(index)
|
205 |
|
|
{
|
206 |
3cf8f87d
|
Leszek Koltunski
|
case ERROR_CORNER_YBR_MISSING: String c01 = res.getString(R.string.color_yellow3);
|
207 |
|
|
String c02 = res.getString(R.string.color_blue3);
|
208 |
|
|
String c03 = res.getString(R.string.color_red4);
|
209 |
|
|
return res.getString(R.string.solver_generic_missing_corner,c01,c02,c03);
|
210 |
|
|
case ERROR_CORNER_GBR_MISSING: String c11 = res.getString(R.string.color_green3);
|
211 |
|
|
String c12 = res.getString(R.string.color_blue3);
|
212 |
|
|
String c13 = res.getString(R.string.color_red4);
|
213 |
|
|
return res.getString(R.string.solver_generic_missing_corner,c11,c12,c13);
|
214 |
|
|
case ERROR_CORNER_GYR_MISSING: String c21 = res.getString(R.string.color_green3);
|
215 |
|
|
String c22 = res.getString(R.string.color_yellow3);
|
216 |
|
|
String c23 = res.getString(R.string.color_red4);
|
217 |
|
|
return res.getString(R.string.solver_generic_missing_corner,c21,c22,c23);
|
218 |
|
|
case ERROR_CORNER_GYB_MISSING: String c31 = res.getString(R.string.color_green3);
|
219 |
|
|
String c32 = res.getString(R.string.color_yellow3);
|
220 |
|
|
String c33 = res.getString(R.string.color_blue4);
|
221 |
|
|
return res.getString(R.string.solver_generic_missing_corner,c31,c32,c33);
|
222 |
ca278d11
|
Leszek Koltunski
|
case ERROR_CENTER_G_MISSING : String colorG = res.getString(R.string.color_green2);
|
223 |
|
|
return res.getString(R.string.solver_generic_missing_center,colorG);
|
224 |
|
|
case ERROR_CENTER_Y_MISSING : String colorY = res.getString(R.string.color_yellow2);
|
225 |
|
|
return res.getString(R.string.solver_generic_missing_center,colorY);
|
226 |
|
|
case ERROR_CENTER_B_MISSING : String colorB = res.getString(R.string.color_blue2);
|
227 |
|
|
return res.getString(R.string.solver_generic_missing_center,colorB);
|
228 |
|
|
case ERROR_CENTER_R_MISSING : String colorR = res.getString(R.string.color_red2);
|
229 |
|
|
return res.getString(R.string.solver_generic_missing_center,colorR);
|
230 |
|
|
case ERROR_TWO_CENTERS_SWAP : return res.getString(R.string.solver_generic_two_centers);
|
231 |
|
|
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist);
|
232 |
686de47a
|
Leszek Koltunski
|
case ERROR_EDGE_GY : String c41 = res.getString(R.string.color_green3);
|
233 |
|
|
String c42 = res.getString(R.string.color_yellow5);
|
234 |
|
|
return res.getString(R.string.solver_generic_two_corners,c41,c42);
|
235 |
|
|
case ERROR_EDGE_GB : String c51 = res.getString(R.string.color_green3);
|
236 |
|
|
String c52 = res.getString(R.string.color_blue5);
|
237 |
|
|
return res.getString(R.string.solver_generic_two_corners,c51,c52);
|
238 |
|
|
case ERROR_EDGE_GR : String c61 = res.getString(R.string.color_green3);
|
239 |
|
|
String c62 = res.getString(R.string.color_red5);
|
240 |
|
|
return res.getString(R.string.solver_generic_two_corners,c61,c62);
|
241 |
|
|
case ERROR_EDGE_YB : String c71 = res.getString(R.string.color_yellow3);
|
242 |
|
|
String c72 = res.getString(R.string.color_blue5);
|
243 |
|
|
return res.getString(R.string.solver_generic_two_corners,c71,c72);
|
244 |
|
|
case ERROR_EDGE_YR : String c81 = res.getString(R.string.color_yellow3);
|
245 |
|
|
String c82 = res.getString(R.string.color_red5);
|
246 |
|
|
return res.getString(R.string.solver_generic_two_corners,c81,c82);
|
247 |
|
|
case ERROR_EDGE_BR : String c91 = res.getString(R.string.color_blue3);
|
248 |
|
|
String c92 = res.getString(R.string.color_red5);
|
249 |
|
|
return res.getString(R.string.solver_generic_two_corners,c91,c92);
|
250 |
ca278d11
|
Leszek Koltunski
|
}
|
251 |
|
|
|
252 |
|
|
return null;
|
253 |
420eb96d
|
Leszek Koltunski
|
}
|
254 |
|
|
|
255 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
7bdd481b
|
Leszek Koltunski
|
|
257 |
ca278d11
|
Leszek Koltunski
|
public String solution(int index, Resources res)
|
258 |
420eb96d
|
Leszek Koltunski
|
{
|
259 |
7bdd481b
|
Leszek Koltunski
|
return "";
|
260 |
420eb96d
|
Leszek Koltunski
|
}
|
261 |
|
|
}
|