Revision 083d854d
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/solvers/SolverDino6.java | ||
---|---|---|
58 | 58 |
|
59 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | 60 |
|
61 |
private int computeOpposite(int color, int[][] edges, boolean[] buffer)
|
|
61 |
private int computeOpposite(int color, int[][] edges) |
|
62 | 62 |
{ |
63 |
for(int i=0; i<6; i++) buffer[i] = false; |
|
63 |
int[] buffer = new int[6]; |
|
64 |
for(int i=0; i<6; i++) buffer[i] = 0; |
|
64 | 65 |
|
65 | 66 |
for(int i=0; i<12; i++) |
66 | 67 |
{ |
67 |
int[] edge = edges[i]; |
|
68 |
if( edge[0]==color ) buffer[edge[1]]=true; |
|
69 |
if( edge[1]==color ) buffer[edge[0]]=true; |
|
68 |
int e0 = edges[i][0]; |
|
69 |
int e1 = edges[i][1]; |
|
70 |
|
|
71 |
if( e0==color && e1==color) |
|
72 |
{ |
|
73 |
mErrorColor1 = color; |
|
74 |
return ERROR_EDGE_MONOCHROMATIC; |
|
75 |
} |
|
76 |
|
|
77 |
if( e0==color ) |
|
78 |
{ |
|
79 |
buffer[e1]++; |
|
80 |
|
|
81 |
if( buffer[e1]>1 ) |
|
82 |
{ |
|
83 |
mErrorColor1 = color; |
|
84 |
mErrorColor2 = e1; |
|
85 |
return ERROR_EDGE_TWICE; |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
if( e1==color ) |
|
90 |
{ |
|
91 |
buffer[e0]++; |
|
92 |
|
|
93 |
if( buffer[e0]>1 ) |
|
94 |
{ |
|
95 |
mErrorColor1 = color; |
|
96 |
mErrorColor2 = e0; |
|
97 |
return ERROR_EDGE_TWICE; |
|
98 |
} |
|
99 |
} |
|
70 | 100 |
} |
71 | 101 |
|
72 | 102 |
int total = 0; |
73 | 103 |
|
74 | 104 |
for(int i=0; i<6; i++) |
75 |
if( buffer[i] ) |
|
105 |
if( buffer[i]==1 )
|
|
76 | 106 |
{ |
77 | 107 |
if( i!=color) total++; |
78 | 108 |
else |
... | ... | |
84 | 114 |
|
85 | 115 |
if( total==4 ) |
86 | 116 |
for(int i=0; i<6; i++) |
87 |
if( !buffer[i] && i!=color ) return i;
|
|
117 |
if( buffer[i]==0 && i!=color ) return i;
|
|
88 | 118 |
|
89 | 119 |
return ERROR_EDGE_CANNOT; |
90 | 120 |
} |
... | ... | |
152 | 182 |
if( !present[i] ) |
153 | 183 |
{ |
154 | 184 |
mErrorColor1 = i; |
155 |
mErrorColor2 = (i<5 ? i+1 : 4 );
|
|
185 |
mErrorColor2 = (i<4 ? i+2 : i-2 );
|
|
156 | 186 |
return ERROR_EDGE_MISSING; |
157 | 187 |
} |
158 | 188 |
|
... | ... | |
160 | 190 |
|
161 | 191 |
mFaceColors[4] = edges[0][0]; |
162 | 192 |
mFaceColors[2] = edges[0][1]; |
163 |
mFaceColors[5] = computeOpposite(mFaceColors[4], edges, present);
|
|
193 |
mFaceColors[5] = computeOpposite(mFaceColors[4], edges); |
|
164 | 194 |
if( mFaceColors[5]<0 ) return mFaceColors[5]; |
165 | 195 |
|
166 |
mFaceColors[3] = computeOpposite(mFaceColors[2], edges, present);
|
|
196 |
mFaceColors[3] = computeOpposite(mFaceColors[2], edges); |
|
167 | 197 |
if( mFaceColors[3]<0 ) return mFaceColors[3]; |
168 | 198 |
|
169 | 199 |
int success = fillUpRemainingFaceColors(present); |
Also available in: Unified diff
Dino6 solver: error detection should work fine now.