src/de/uapcore/sudoku/Solver.java

changeset 8
e70a0e3555fb
parent 7
2c0a2766461c
equal deleted inserted replaced
7:2c0a2766461c 8:e70a0e3555fb
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 // Backtrack 175 // Backtrack
176 return solve(f, candidates) && complete(f); 176 return solve(f, candidates);
177 } 177 }
178 178
179 public boolean check(Field f) { 179 public boolean check(Field f) {
180 int line[]; 180 int line[];
181 for (int i = 0 ; i < 9 ; i++) { 181 for (int i = 0 ; i < 9 ; i++) {
197 return false; 197 return false;
198 } 198 }
199 } 199 }
200 } 200 }
201 201
202 return true;
203 }
204
205 private boolean complete(Field f) {
206 for (int i = 0 ; i < 9 ; i++) {
207 if (!complete(f.getRow(i))) {
208 return false;
209 }
210 if (!complete(f.getColumn(i))) {
211 return false;
212 }
213 }
214 for (int x = 0 ; x < 3 ; x++) {
215 for (int y = 0 ; y < 3 ; y++) {
216 if (!complete(f.getSquare(x, y))) {
217 return false;
218 }
219 }
220 }
221 return true;
222 }
223
224 private boolean complete(int[][] square) {
225 for (int x = 0 ; x < 3 ; x++) {
226 for (int y = 0 ; y < 3 ; y++) {
227 if (square[x][y] == 0) {
228 return false;
229 }
230 }
231 }
232 return true;
233 }
234
235 private boolean complete(int[] line) {
236 for (int i = 0 ; i < 9 ; i++) {
237 if (line[i] == 0) {
238 return false;
239 }
240 }
241 return true; 202 return true;
242 } 203 }
243 204
244 private boolean valid(int[] line) { 205 private boolean valid(int[] line) {
245 int numbers[]; 206 int numbers[];

mercurial