diff --git a/app/src/main/java/sudoku/Bloc.java b/app/src/main/java/sudoku/Bloc.java deleted file mode 100644 index ca9069b..0000000 --- a/app/src/main/java/sudoku/Bloc.java +++ /dev/null @@ -1,26 +0,0 @@ -package sudoku; - -import java.util.ArrayList; -import java.util.List; - -public class Bloc { - - private final List cases; - - public Bloc(List cases) { - this.cases = cases; - } - - public Bloc() { - this.cases = new ArrayList<>(); - } - - public List getCases() { - return cases; - } - - void addCase(Case newCase) { - this.cases.add(newCase); - } - -} diff --git a/app/src/main/java/sudoku/Block.java b/app/src/main/java/sudoku/Block.java new file mode 100644 index 0000000..ec12bc4 --- /dev/null +++ b/app/src/main/java/sudoku/Block.java @@ -0,0 +1,26 @@ +package sudoku; + +import java.util.ArrayList; +import java.util.List; + +public class Block { + + private final List cells; + + public Block(List cells) { + this.cells = cells; + } + + public Block() { + this.cells = new ArrayList<>(); + } + + public List getCells() { + return cells; + } + + void addCell(Cell newCell) { + this.cells.add(newCell); + } + +} diff --git a/app/src/main/java/sudoku/Case.java b/app/src/main/java/sudoku/Cell.java similarity index 56% rename from app/src/main/java/sudoku/Case.java rename to app/src/main/java/sudoku/Cell.java index 7f340ad..36d9d3b 100644 --- a/app/src/main/java/sudoku/Case.java +++ b/app/src/main/java/sudoku/Cell.java @@ -1,19 +1,19 @@ package sudoku; -public class Case { +public class Cell { private static int NOSYMBOLE = -1; private int symboleIndex; - private Bloc bloc = null; + private Block block = null; - public Case(int symboleIndex) { + public Cell(int symboleIndex) { this.symboleIndex = symboleIndex; } /** * @brief Default constructor, empty square */ - public Case() { + public Cell() { this(NOSYMBOLE); } @@ -29,18 +29,19 @@ public class Case { setSymboleIndex(NOSYMBOLE); } - public Bloc getBloc() { - return this.bloc; + public Block getBlock() { + return this.block; } - void setBloc(Bloc bloc) { - this.bloc = bloc; + // only SudokuFactory should access this + void setBlock(Block block) { + this.block = block; } @Override public boolean equals(Object obj) { - if (obj instanceof Case autreCase) - return autreCase.getSymboleIndex() == this.getSymboleIndex(); - return super.equals(obj); + if (obj instanceof Cell otherCell) + return otherCell.getSymboleIndex() == this.getSymboleIndex(); + return false; } } diff --git a/app/src/main/java/sudoku/Sudoku.java b/app/src/main/java/sudoku/Sudoku.java index da29fba..3e0fded 100644 --- a/app/src/main/java/sudoku/Sudoku.java +++ b/app/src/main/java/sudoku/Sudoku.java @@ -8,29 +8,22 @@ import java.util.List; */ public class Sudoku { - private final List blocs; - private final List cases; + private final List blocks; + private final List cells; - public Sudoku(List cases, List blocs) { - // assert(symbolCount >= 2); - // // initialisation des cases - // this.cases = new ArrayList<>(symbolCount * symbolCount); - // Collections.fill(this.cases, new Case()); - // // initialisation des blocs - // this.blocs = new ArrayList<>(symbolCount); - // Collections.fill(this.blocs, new Bloc(null)); - this.cases = cases; - this.blocs = blocs; + public Sudoku(List cells, List blocks) { + this.cells = cells; + this.blocks = blocks; } - public Case getCase(int x, int y) { + public Cell getCell(int x, int y) { int index = y * getSize() + x; assert(index < getSize() * getSize()); - return this.cases.get(index); + return this.cells.get(index); } public int getSize() { - return this.blocs.size(); + return this.blocks.size(); } } diff --git a/app/src/main/java/sudoku/SudokuFactory.java b/app/src/main/java/sudoku/SudokuFactory.java index 4773b4f..644b9b2 100644 --- a/app/src/main/java/sudoku/SudokuFactory.java +++ b/app/src/main/java/sudoku/SudokuFactory.java @@ -5,38 +5,38 @@ import java.util.List; public class SudokuFactory { - private static List initCases(int size) { - List cases = new ArrayList<>(size * size); + private static List initCells(int size) { + List cells = new ArrayList<>(size * size); for (int i = 0; i < size * size; i++) { - cases.add(new Case()); + cells.add(new Cell()); } - return cases; + return cells; } - private static List initRectangleBlocs(List cases, int width, int height) { - List blocs = new ArrayList<>(); + private static List initRectangleBlocs(List cells, int width, int height) { + List blocs = new ArrayList<>(); int size = width * height; for (int i = 0; i < size; i++) { - Bloc newBloc = new Bloc(); - int blocX = i % height; - int blocY = i / height; + Block newBlock = new Block(); + int blockX = i % height; + int blockY = i / height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - int index = ((y + blocY * height) * size + (x + blocX * width)); - Case caseBloc = cases.get(index); - caseBloc.setBloc(newBloc); - newBloc.addCase(caseBloc); + int index = ((y + blockY * height) * size + (x + blockX * width)); + Cell blockCell = cells.get(index); + blockCell.setBlock(newBlock); + newBlock.addCell(blockCell); } } - blocs.add(newBloc); + blocs.add(newBlock); } return blocs; } public static MultiDoku createBasicEmptyRectangleSudoku(int width, int height) { int symbolCount = width * height; - List cases = initCases(symbolCount); - List blocs = initRectangleBlocs(cases, width, height); + List cases = initCells(symbolCount); + List blocs = initRectangleBlocs(cases, width, height); Sudoku s = new Sudoku(cases, blocs); List ss = new ArrayList<>(); ss.add(s); diff --git a/app/src/main/java/sudoku/constraint/BlockConstraint.java b/app/src/main/java/sudoku/constraint/BlockConstraint.java index dc537e1..18be660 100644 --- a/app/src/main/java/sudoku/constraint/BlockConstraint.java +++ b/app/src/main/java/sudoku/constraint/BlockConstraint.java @@ -1,15 +1,15 @@ package sudoku.constraint; -import sudoku.Bloc; -import sudoku.Case; +import sudoku.Block; +import sudoku.Cell; import sudoku.Sudoku; public class BlockConstraint implements IConstraint{ @Override public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) { - Bloc bloc = s.getCase(x, y).getBloc(); - return !bloc.getCases().contains(new Case(newSymbolIndex)); + Block bloc = s.getCell(x, y).getBlock(); + return !bloc.getCells().contains(new Cell(newSymbolIndex)); } } diff --git a/app/src/main/java/sudoku/constraint/ColumnConstraint.java b/app/src/main/java/sudoku/constraint/ColumnConstraint.java index ef71445..4c74ef2 100644 --- a/app/src/main/java/sudoku/constraint/ColumnConstraint.java +++ b/app/src/main/java/sudoku/constraint/ColumnConstraint.java @@ -7,7 +7,7 @@ public class ColumnConstraint implements IConstraint { @Override public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) { for (int i = 0; i < s.getSize(); i++) { - if (s.getCase(x, newSymbolIndex).getSymboleIndex() == newSymbolIndex) + if (s.getCell(x, newSymbolIndex).getSymboleIndex() == newSymbolIndex) return false; } return true; diff --git a/app/src/main/java/sudoku/constraint/LineConstraint.java b/app/src/main/java/sudoku/constraint/LineConstraint.java index f6836cd..8837229 100644 --- a/app/src/main/java/sudoku/constraint/LineConstraint.java +++ b/app/src/main/java/sudoku/constraint/LineConstraint.java @@ -7,7 +7,7 @@ public class LineConstraint implements IConstraint { @Override public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) { for (int i = 0; i < s.getSize(); i++) { - if (s.getCase(newSymbolIndex, y).getSymboleIndex() == newSymbolIndex) + if (s.getCell(newSymbolIndex, y).getSymboleIndex() == newSymbolIndex) return false; } return true;