Revision 4ad82629
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/solvers/SolverIvyCube.java | ||
---|---|---|
15 | 15 |
import org.distorted.objectlib.main.ObjectType; |
16 | 16 |
import org.distorted.objectlib.main.TwistyObject; |
17 | 17 |
import org.distorted.objectlib.tablebases.ImplementedTablebasesList; |
18 |
import org.distorted.objectlib.tablebases.TablebaseHelpers; |
|
18 | 19 |
import org.distorted.objectlib.tablebases.TablebasesAbstract; |
19 | 20 |
|
20 | 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
145 | 146 |
return 0; |
146 | 147 |
} |
147 | 148 |
|
148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
|
|
150 |
private int swaps(int val, int[] buffer, int len) |
|
151 |
{ |
|
152 |
int ret = 0; |
|
153 |
|
|
154 |
for(int i=0; i<len; i++) |
|
155 |
{ |
|
156 |
if( buffer[i] >val ) ret++; |
|
157 |
else if( buffer[i]==val ) return ret; |
|
158 |
} |
|
159 |
|
|
160 |
return -1; |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
private boolean permutationIsEven(int[] buffer) |
|
166 |
{ |
|
167 |
int len = buffer.length; |
|
168 |
int numOfSwaps = 0; |
|
169 |
for(int i=0; i<len; i++) numOfSwaps += swaps(i,buffer,len); |
|
170 |
return (numOfSwaps%2==0); |
|
171 |
} |
|
172 |
|
|
173 | 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
174 | 150 |
|
175 | 151 |
private int computeCenterColors(int[] buffer, int[] faceColors, int[] centers) |
... | ... | |
183 | 159 |
buffer[center]=color; |
184 | 160 |
} |
185 | 161 |
|
186 |
return permutationIsEven(buffer) ? 0 : ERROR_TWO_CENTERS_SWAP; |
|
162 |
return TablebaseHelpers.permutationIsEven(buffer) ? 0 : ERROR_TWO_CENTERS_SWAP;
|
|
187 | 163 |
} |
188 | 164 |
//////////////////////////////////////////////////////////////////////////////////////// |
189 | 165 |
|
... | ... | |
194 | 170 |
return 2; |
195 | 171 |
} |
196 | 172 |
|
197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 |
|
|
199 |
private int computeOrder(int[] permutation, int index) |
|
200 |
{ |
|
201 |
int numOfSmaller = 0; |
|
202 |
int val = permutation[index]; |
|
203 |
|
|
204 |
for(int i=0; i<index; i++) |
|
205 |
if( permutation[i]<val ) numOfSmaller++; |
|
206 |
|
|
207 |
return val-numOfSmaller; |
|
208 |
} |
|
209 |
|
|
210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
211 |
|
|
212 |
private int computeEvenPermutationNum(int[] permutation) |
|
213 |
{ |
|
214 |
int n0 = computeOrder(permutation,0); |
|
215 |
int n1 = computeOrder(permutation,1); |
|
216 |
int n2 = computeOrder(permutation,2); |
|
217 |
int n3 = computeOrder(permutation,3); |
|
218 |
|
|
219 |
return n0 + 6*(n1+ 5*(n2+4*n3)); |
|
220 |
} |
|
221 |
|
|
222 | 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
223 | 174 |
|
224 | 175 |
public SolverIvyCube(Resources res, TwistyObject object) |
... | ... | |
243 | 194 |
for(int i=0; i<6; i++) |
244 | 195 |
centers[i] = object.getCubitFaceStickerIndex(i+4,0) - 6; |
245 | 196 |
|
246 |
for(int i=0; i<4; i++) |
|
247 |
{ |
|
248 |
android.util.Log.e("D", "corner "+i+" : "+corners[i][0]+" "+corners[i][1]+" "+corners[i][2]); |
|
249 |
} |
|
250 |
for(int i=0; i<6; i++) |
|
251 |
{ |
|
252 |
android.util.Log.e("D", "center "+i+" : "+centers[i]); |
|
253 |
} |
|
254 |
|
|
255 | 197 |
int result1 = checkAllCentersPresent(centers); |
256 | 198 |
if( result1<0 ) return result1; |
257 | 199 |
|
... | ... | |
266 | 208 |
twist[2] = computeCornerTwist(corners[2],face_colors[4]); |
267 | 209 |
twist[3] = computeCornerTwist(corners[3],face_colors[5]); |
268 | 210 |
|
269 |
int perm_num = computeEvenPermutationNum(center_colors); |
|
270 |
|
|
271 |
android.util.Log.e("D", "twist : "+twist[0]+" "+twist[1]+" "+twist[2]+" "+twist[3]); |
|
272 |
|
|
273 |
int ret = perm_num + 360*(twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*twist[3]))); |
|
274 |
|
|
275 |
android.util.Log.e("D", "index: "+ret+" perm_num="+perm_num); |
|
211 |
int perm_num = TablebaseHelpers.computeEvenPermutationNum(center_colors); |
|
276 | 212 |
|
277 |
return ret;
|
|
213 |
return perm_num + 360*(twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*twist[3])));
|
|
278 | 214 |
} |
279 | 215 |
|
280 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Ivy solver finished