Files
Sudoku/app/src/main/java/sudoku/constraint/DiagonalConstraint.java
Persson-dev a580321bd0
All checks were successful
Linux arm64 / Build (push) Successful in 42s
doc: constraints
2025-02-02 22:25:28 +01:00

28 lines
610 B
Java

package sudoku.constraint;
import sudoku.structure.Sudoku;
/**
* Contrainte de diagonale
*/
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 - 1, i).getSymbolIndex() == newSymbolIndex)
return false;
}
}
// not in diagonal
return true;
}
}