This commit is contained in:
@@ -20,4 +20,27 @@ public class SudokuPrinter {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toStringRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int y = 0; y < s.getSize(); y++) {
|
||||
// Ajouter une ligne vide entre les blocs horizontaux
|
||||
if (y % blockHeight == 0 && y > 0) {
|
||||
result.append("\n");
|
||||
}
|
||||
StringBuilder line = new StringBuilder("[ ");
|
||||
for (int x = 0; x < s.getSize(); x++) {
|
||||
// Ajouter la valeur de la cellule
|
||||
line.append((s.getCell(x, y).getSymbolIndex() + 1)).append(" ");
|
||||
|
||||
// Ajouter un séparateur vertical entre les blocs
|
||||
if (x % blockWidth == blockWidth - 1 && x != s.getSize() - 1) {
|
||||
line.append("| ");
|
||||
}
|
||||
}
|
||||
line.append("]");
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user