checking boudaries
All checks were successful
Linux arm64 / Build (push) Successful in 1m0s

This commit is contained in:
2025-01-21 21:30:08 +01:00
parent dabcbe1d9a
commit f44311fd5c

View File

@@ -21,11 +21,21 @@ public class Sudoku {
this.constraints = constraints; this.constraints = constraints;
} }
/**
* @return wether the coords are in the sudoku
*/
public boolean isValidCoords(int x, int y) {
int index = y * getSize() + x;
return index < getSize() * getSize();
}
/** /**
* Try to place a cell at the given coordinate * Try to place a cell at the given coordinate
*
* @return false if it can't be done * @return false if it can't be done
*/ */
public boolean setCellSymbol(int x, int y, int value) { public boolean setCellSymbol(int x, int y, int value) {
assert (isValidCoords(x, y));
for (IConstraint constraint : this.constraints) { for (IConstraint constraint : this.constraints) {
if (!constraint.canBePlaced(this, x, y, value)) { if (!constraint.canBePlaced(this, x, y, value)) {
return false; return false;
@@ -41,7 +51,7 @@ public class Sudoku {
public Cell getCell(int x, int y) { public Cell getCell(int x, int y) {
int index = y * getSize() + x; int index = y * getSize() + x;
assert(index < getSize() * getSize()); assert (isValidCoords(x, y));
return this.cells.get(index); return this.cells.get(index);
} }
@@ -100,8 +110,7 @@ public class Sudoku {
if (x == size - 1) { if (x == size - 1) {
y += 1; y += 1;
x = 0; x = 0;
} } else {
else {
x += 1; x += 1;
} }
} }