add diagonal constraint
All checks were successful
Linux arm64 / Build (push) Successful in 42s

This commit is contained in:
2025-01-29 15:48:01 +01:00
parent de1f3c59d6
commit cd792a0f8a

View File

@@ -0,0 +1,24 @@
package sudoku.constraint;
import sudoku.structure.Sudoku;
public class DiagonalConstraint implements IConstraint {
@Override
public boolean canBePlaced(Sudoku s, int x, int y, int newSymbolIndex) {
if (x == y) {
for (int i = 0; i < s.getSize(); i++) {
if (s.getCell(i, i).getSymbolIndex() == newSymbolIndex)
return false;
}
} else if (s.getSize() - x == y) {
for (int i = 0; i < s.getSize(); i++) {
if (s.getCell(s.getSize() - i, i).getSymbolIndex() == newSymbolIndex)
return false;
}
}
// not in diagonal
return true;
}
}