Esempio n. 1
0
  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);
      }
    }
  }
Esempio n. 2
0
 private Grid(int size, boolean createSquares) {
   init(size, createSquares);
 }