begin multidoku display code

This commit is contained in:
2025-01-26 22:19:56 +01:00
parent 3bb610b9c2
commit 3a0279afe3
5 changed files with 190 additions and 25 deletions

View File

@@ -7,6 +7,9 @@ public class Block {
private final List<Cell> cells;
// faster access to the sudoku
private List<Sudoku> sudokus;
public Block(List<Cell> cells) {
this.cells = cells;
}
@@ -39,4 +42,12 @@ public class Block {
}
return false;
}
public List<Sudoku> getSudokus() {
return sudokus;
}
void setSudokus(List<Sudoku> sudokus) {
this.sudokus = sudokus;
}
}

View File

@@ -30,4 +30,12 @@ public class Coordinate {
return this.y * size + this.x;
}
public Coordinate add(Coordinate other) {
return new Coordinate(this.x + other.x, this.y + other.y);
}
public Coordinate sub(Coordinate other) {
return new Coordinate(this.x - other.x, this.y - other.y);
}
}

View File

@@ -15,6 +15,7 @@ public class Sudoku {
private final List<Cell> cells;
private final List<IConstraint> constraints;
private boolean isMutable;
private int blockWidth;
public Sudoku(List<Cell> cells, List<Block> blocks, List<IConstraint> constraints) {
this.cells = cells;
@@ -23,7 +24,7 @@ public class Sudoku {
}
public int[] toCoords(int index) {
return new int[]{index % getSize(), index / getSize()};
return new int[] { index % getSize(), index / getSize() };
}
public int toIndex(int x, int y) {
@@ -71,6 +72,10 @@ public class Sudoku {
}
}
public int getBlockWidth() {
return blockWidth;
}
/**
* Try to place a cell at the given coordinate
*
@@ -162,6 +167,8 @@ public class Sudoku {
throw new Exception("The given cell is not in this sudoku.");
}
// TODO: use this.cells.indexOf();
for (Cell cell : this.cells) {
if (cell == c) {
return new Coordinate(x, y);