public Grid(String puzzle) { String[] initRows = puzzle.split("[\\n\\r]"); List<String> rowList = new ArrayList<String>(); for (String row : initRows) { if (row.trim().length() > 0) { rowList.add(row); } } String[] rows = rowList.toArray(new String[rowList.size()]); init(rows.length, true); for (int row = 0; row < rows.length; row++) { String cols = rows[row]; int col = 0; for (int idx = 0; idx < cols.length(); idx++) { char c = cols.charAt(idx); if (c == ' ') { continue; } int value = Integer.parseInt(String.valueOf(c)); if (value != 0) { setValue(row, col, value); } col++; } if (col != rows.length) { throw new IllegalArgumentException(puzzle); } } }
public void setValues(int row, int[] values) { for (int col = 0; col < size; col++) { if (values[col] != 0) { setValue(row, col, values[col]); } } }
public Grid(Grid grid) { this(grid.size, true); for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { if (grid.squares[row][col].hasValue()) { setValue(row, col, grid.squares[row][col].getValue()); } } } }
public void executeMove(Grid grid) { grid.setValue(this.row, this.col, this.value); remainingSquares = grid.getRemainingSquares(); remainingCandidates = grid.getRemainingCandidates(); }
public void setValue(int row, int col, int value) { if (value < 1 || value > this.size) { throw new IllegalArgumentException("Illegal value: " + value); } setValue(this.squares[row][col], value); }