146 * @return true if a solution could be found, false if the field is unsolvable |
146 * @return true if a solution could be found, false if the field is unsolvable |
147 */ |
147 */ |
148 public boolean solve(Field f) { |
148 public boolean solve(Field f) { |
149 |
149 |
150 // Calculate initial candidates |
150 // Calculate initial candidates |
151 List<Integer> candidates[][] = new List[9][9]; |
151 List<Integer>[][] candidates = new List[9][9]; |
152 for (int x = 0 ; x < 9 ; x++) { |
152 for (int x = 0 ; x < 9 ; x++) { |
153 for (int y = 0 ; y < 9 ; y++) { |
153 for (int y = 0 ; y < 9 ; y++) { |
154 candidates[x][y] = new ArrayList<>(9); |
154 candidates[x][y] = new ArrayList<>(9); |
155 if (f.getCellValue(x, y) == 0) { |
155 if (f.getCellValue(x, y) == 0) { |
156 // All numbers are candidates |
156 // All numbers are candidates |
187 * |
187 * |
188 * @param f the field to check |
188 * @param f the field to check |
189 * @return true, if the check succeeds, false otherwise |
189 * @return true, if the check succeeds, false otherwise |
190 */ |
190 */ |
191 public boolean check(Field f) { |
191 public boolean check(Field f) { |
192 int line[]; |
192 int[] line; |
193 for (int i = 0 ; i < 9 ; i++) { |
193 for (int i = 0 ; i < 9 ; i++) { |
194 line = f.getRow(i); |
194 line = f.getRow(i); |
195 if (!valid(line)) { |
195 if (!valid(line)) { |
196 return false; |
196 return false; |
197 } |
197 } |