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);
|
||||
}
|
||||
|
||||
@@ -58,8 +68,8 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
public boolean isValid(List<IConstraint> constraints) {
|
||||
//not implemented
|
||||
//for eachcase check contraintes
|
||||
// not implemented
|
||||
// for eachcase check contraintes
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,7 +84,7 @@ public class Sudoku {
|
||||
public List<MutableCell> getMutableCells() {
|
||||
List<MutableCell> mutableCells = new ArrayList<>();
|
||||
for (Cell cell : this.cells) {
|
||||
if (cell instanceof MutableCell){
|
||||
if (cell instanceof MutableCell) {
|
||||
mutableCells.add((MutableCell) cell);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +96,7 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
private Coordinate getCoordinateCell(Cell c) throws Exception {
|
||||
int x=0, y=0;
|
||||
int x = 0, y = 0;
|
||||
int size = this.getSize();
|
||||
|
||||
if (!this.contains(c)) {
|
||||
@@ -94,15 +104,14 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
for (Cell cell : this.cells) {
|
||||
if (cell == c){
|
||||
if (cell == c) {
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
if (x == size - 1){
|
||||
y+=1;
|
||||
x=0;
|
||||
}
|
||||
else {
|
||||
x+=1;
|
||||
if (x == size - 1) {
|
||||
y += 1;
|
||||
x = 0;
|
||||
} else {
|
||||
x += 1;
|
||||
}
|
||||
}
|
||||
return new Coordinate(x, y);
|
||||
@@ -123,14 +132,14 @@ public class Sudoku {
|
||||
|
||||
cell.setPossibleSymbols(newPossibleSymbols);
|
||||
|
||||
if (cell.getPossibleSymbols().isEmpty()){
|
||||
if (cell.getPossibleSymbols().isEmpty()) {
|
||||
throw new Exception("Rollback bitch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Sudoku {");
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user