diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java index 76d6ecf..35a25d1 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import java.util.LinkedList; import java.util.List; +import tu_darmstadt.sudoku.controller.generator.Generator; import tu_darmstadt.sudoku.game.CellConflict; import tu_darmstadt.sudoku.game.CellConflictList; import tu_darmstadt.sudoku.game.GameBoard; @@ -15,7 +16,6 @@ import tu_darmstadt.sudoku.game.GameDifficulty; import tu_darmstadt.sudoku.game.GameType; import tu_darmstadt.sudoku.game.ICellAction; import tu_darmstadt.sudoku.game.IModelChangedListener; -import tu_darmstadt.sudoku.game.solver.Solver; /** * Created by Chris on 06.11.2015. @@ -50,7 +50,8 @@ public class GameController implements IModelChangedListener { public GameController(GameType type, SharedPreferences pref) { setGameType(type); - gameBoard = new GameBoard(size, sectionHeight, sectionWidth); + gameBoard = new GameBoard(type); + gameBoard.registerOnModelChangeListener(this); setSettings(pref); } @@ -59,6 +60,9 @@ public class GameController implements IModelChangedListener { } public void loadNewLevel(GameType type, int difficulty) { + Generator generator = new Generator(); + // TODO call methods to generate level. + switch(type) { case Default_6x6: loadLevel(new GameInfoContainer(1, GameDifficulty.Easy, GameType.Default_6x6, @@ -109,7 +113,7 @@ public class GameController implements IModelChangedListener { this.gameID = gic.getID(); setGameType(gic.getGameType()); - this.gameBoard = new GameBoard(size, sectionHeight, sectionWidth); + this.gameBoard = new GameBoard(gic.getGameType()); if(fixedValues == null) throw new IllegalArgumentException("fixedValues may not be null."); @@ -136,6 +140,9 @@ public class GameController implements IModelChangedListener { } } } + + // call the solve function to get the solution of this board + solve(); } public void setSettings(SharedPreferences pref) { @@ -143,17 +150,9 @@ public class GameController implements IModelChangedListener { } public LinkedList solve() { - // TODO call solve at the beginning.. when loading a level. if(solvedBoards.size() == 0) { - switch (gameType) { - case Default_9x9: - case Default_6x6: - case Default_12x12: - solver = new Solver(gameBoard); - break; - default: - throw new UnsupportedOperationException("No Solver for this GameType defined."); - } + + solver = new Solver(gameBoard); if (solver.solve(solver.getGameBoard())) { solvedBoards.addAll(solver.getSolutions()); diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java b/app/src/main/java/tu_darmstadt/sudoku/controller/Solver.java similarity index 99% rename from app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java rename to app/src/main/java/tu_darmstadt/sudoku/controller/Solver.java index c6a1deb..9714aa3 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/Solver.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.game.solver; +package tu_darmstadt.sudoku.controller; import android.graphics.Point; import android.util.Log; @@ -15,7 +15,7 @@ import tu_darmstadt.sudoku.game.ICellAction; /** * Created by Chris on 10.11.2015. */ -public class Solver implements ISolver { +public class Solver { private GameBoard gameBoard = null; private LinkedList solutions = new LinkedList<>(); @@ -152,7 +152,6 @@ public class Solver implements ISolver { return result; } - @Override public boolean calculateNextPossibleStep() { return false; diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/generator/Generator.java b/app/src/main/java/tu_darmstadt/sudoku/controller/generator/Generator.java new file mode 100644 index 0000000..d183f4f --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/generator/Generator.java @@ -0,0 +1,8 @@ +package tu_darmstadt.sudoku.controller.generator; + +/** + * Created by Chris on 19.11.2015. + */ +public class Generator { + +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java index 6266f77..33527da 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java @@ -17,10 +17,11 @@ public class GameBoard implements Cloneable { private GameCell[][] field; private List modelChangedListeners = new LinkedList<>(); - public GameBoard(int size, int sectionHeight, int sectionWidth) { - this.sectionHeight = sectionHeight; - this.sectionWidth = sectionWidth; - this.size = size; + public GameBoard(GameType gameType) { + this.gameType = gameType; + this.sectionHeight = gameType.getSectionHeight(); + this.sectionWidth = gameType.getSectionWidth(); + this.size = gameType.getSize(); field = new GameCell[size][size]; } diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/solver/ISolver.java b/app/src/main/java/tu_darmstadt/sudoku/game/solver/ISolver.java deleted file mode 100644 index add7e75..0000000 --- a/app/src/main/java/tu_darmstadt/sudoku/game/solver/ISolver.java +++ /dev/null @@ -1,16 +0,0 @@ -package tu_darmstadt.sudoku.game.solver; - -import tu_darmstadt.sudoku.game.GameBoard; - -/** - * Created by Chris on 11.11.2015. - */ -public interface ISolver { - - public boolean solve(GameBoard gameBoard); - - public boolean calculateNextPossibleStep(); - - public GameBoard getGameBoard(); - -} diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java index 4e8d72b..4d8e32a 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java @@ -12,6 +12,7 @@ import android.widget.RelativeLayout; import tu_darmstadt.sudoku.game.GameCell; import tu_darmstadt.sudoku.controller.Symbol; +import tu_darmstadt.sudoku.game.IModelChangedListener; /** * Created by TMZ_LToP on 10.11.2015.