1.1 --- a/src/de/uapcore/sudoku/Solver.java Sat Jan 26 18:43:49 2013 +0100 1.2 +++ b/src/de/uapcore/sudoku/Solver.java Sat Jan 26 19:34:31 2013 +0100 1.3 @@ -38,11 +38,11 @@ 1.4 public boolean check(Field f) { 1.5 int line[]; 1.6 for (int i = 0 ; i < 9 ; i++) { 1.7 - line = getRow(f, i); 1.8 + line = f.getRow(i); 1.9 if (!valid(line)) { 1.10 return false; 1.11 } 1.12 - line = getColumn(f, i); 1.13 + line = f.getColumn(i); 1.14 if (!valid(line)) { 1.15 return false; 1.16 } 1.17 @@ -51,7 +51,7 @@ 1.18 int square[][]; 1.19 for (int x = 0 ; x < 3 ; x++) { 1.20 for (int y = 0 ; y < 3 ; y++) { 1.21 - square = getSquare(f, x, y); 1.22 + square = f.getSquare(x, y); 1.23 if (!valid(square)) { 1.24 return false; 1.25 } 1.26 @@ -82,11 +82,12 @@ 1.27 } 1.28 1.29 private boolean valid(int[] line) { 1.30 - int numbers[] = new int[9]; 1.31 + int numbers[]; 1.32 + numbers = new int[9]; 1.33 for (int i = 0 ; i < 9 ; i++) { 1.34 int l = line[i]-1; 1.35 if (l >= 0) { 1.36 - if (++numbers[l] > 1) { 1.37 + if ((++numbers[l]) > 1) { 1.38 return false; 1.39 } 1.40 } 1.41 @@ -98,51 +99,8 @@ 1.42 private boolean valid(int[][] square) { 1.43 int[] line = new int[9]; 1.44 for (int x = 0 ; x < 3 ; x++) { 1.45 - for (int y = 0 ; y < 3 ; y++) { 1.46 - line[3*x+y] = square[x][y]; 1.47 - } 1.48 + System.arraycopy(square[x], 0, line, 3*x, 3); 1.49 } 1.50 return valid(line); 1.51 } 1.52 - 1.53 - private int[][] getSquare(Field f, int x, int y) { 1.54 - if (x < 0 || x > 2 || y < 0 || y > 2) { 1.55 - throw new IllegalArgumentException("Invalid square coordinates"); 1.56 - } 1.57 - int[][] square = new int[3][3]; 1.58 - 1.59 - for (int u = 0 ; u < 3 ; u++) { 1.60 - for (int v = 0 ; v < 3 ; v++) { 1.61 - square[u][v] = f.getCellValue(3*x+u, 3*y+v); 1.62 - } 1.63 - } 1.64 - 1.65 - return square; 1.66 - } 1.67 - 1.68 - private int[] getRow(Field f, int y) { 1.69 - if (y < 0 || y > 8) { 1.70 - throw new IllegalArgumentException("Invalid row number"); 1.71 - } 1.72 - int row[] = new int[9]; 1.73 - 1.74 - for (int x = 0 ; x < 9 ; x++) { 1.75 - row[x] = f.getCellValue(x, y); 1.76 - } 1.77 - 1.78 - return row; 1.79 - } 1.80 - 1.81 - private int[] getColumn(Field f, int x) { 1.82 - if (x < 0 || x > 8) { 1.83 - throw new IllegalArgumentException("Invalid column number"); 1.84 - } 1.85 - int column[] = new int[9]; 1.86 - 1.87 - for (int y = 0 ; y < 9 ; y++) { 1.88 - column[y] = f.getCellValue(x, y); 1.89 - } 1.90 - 1.91 - return column; 1.92 - } 1.93 }