This commit is contained in:
24
app/src/main/java/sudoku/constraint/DiagonalConstraint.java
Normal file
24
app/src/main/java/sudoku/constraint/DiagonalConstraint.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user