This commit is contained in:
@@ -21,11 +21,21 @@ public class Sudoku {
|
||||
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
|
||||
*
|
||||
* @return false if it can't be done
|
||||
*/
|
||||
public boolean setCellSymbol(int x, int y, int value) {
|
||||
assert (isValidCoords(x, y));
|
||||
for (IConstraint constraint : this.constraints) {
|
||||
if (!constraint.canBePlaced(this, x, y, value)) {
|
||||
return false;
|
||||
@@ -41,7 +51,7 @@ public class Sudoku {
|
||||
|
||||
public Cell getCell(int x, int y) {
|
||||
int index = y * getSize() + x;
|
||||
assert(index < getSize() * getSize());
|
||||
assert (isValidCoords(x, y));
|
||||
return this.cells.get(index);
|
||||
}
|
||||
|
||||
@@ -100,8 +110,7 @@ public class Sudoku {
|
||||
if (x == size - 1) {
|
||||
y += 1;
|
||||
x = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
x += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user