Removed ISolver since we are not implementing different solvers.
Corrected GameController listening to GameCells.
This commit is contained in:
parent
8089adf862
commit
643c45070f
6 changed files with 28 additions and 36 deletions
|
@ -6,6 +6,7 @@ import android.content.SharedPreferences;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import tu_darmstadt.sudoku.controller.generator.Generator;
|
||||||
import tu_darmstadt.sudoku.game.CellConflict;
|
import tu_darmstadt.sudoku.game.CellConflict;
|
||||||
import tu_darmstadt.sudoku.game.CellConflictList;
|
import tu_darmstadt.sudoku.game.CellConflictList;
|
||||||
import tu_darmstadt.sudoku.game.GameBoard;
|
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.GameType;
|
||||||
import tu_darmstadt.sudoku.game.ICellAction;
|
import tu_darmstadt.sudoku.game.ICellAction;
|
||||||
import tu_darmstadt.sudoku.game.IModelChangedListener;
|
import tu_darmstadt.sudoku.game.IModelChangedListener;
|
||||||
import tu_darmstadt.sudoku.game.solver.Solver;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 06.11.2015.
|
* Created by Chris on 06.11.2015.
|
||||||
|
@ -50,7 +50,8 @@ public class GameController implements IModelChangedListener {
|
||||||
|
|
||||||
public GameController(GameType type, SharedPreferences pref) {
|
public GameController(GameType type, SharedPreferences pref) {
|
||||||
setGameType(type);
|
setGameType(type);
|
||||||
gameBoard = new GameBoard(size, sectionHeight, sectionWidth);
|
gameBoard = new GameBoard(type);
|
||||||
|
gameBoard.registerOnModelChangeListener(this);
|
||||||
setSettings(pref);
|
setSettings(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +60,9 @@ public class GameController implements IModelChangedListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadNewLevel(GameType type, int difficulty) {
|
public void loadNewLevel(GameType type, int difficulty) {
|
||||||
|
Generator generator = new Generator();
|
||||||
|
// TODO call methods to generate level.
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case Default_6x6:
|
case Default_6x6:
|
||||||
loadLevel(new GameInfoContainer(1, GameDifficulty.Easy, GameType.Default_6x6,
|
loadLevel(new GameInfoContainer(1, GameDifficulty.Easy, GameType.Default_6x6,
|
||||||
|
@ -109,7 +113,7 @@ public class GameController implements IModelChangedListener {
|
||||||
this.gameID = gic.getID();
|
this.gameID = gic.getID();
|
||||||
|
|
||||||
setGameType(gic.getGameType());
|
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.");
|
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) {
|
public void setSettings(SharedPreferences pref) {
|
||||||
|
@ -143,17 +150,9 @@ public class GameController implements IModelChangedListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<GameBoard> solve() {
|
public LinkedList<GameBoard> solve() {
|
||||||
// TODO call solve at the beginning.. when loading a level.
|
|
||||||
if(solvedBoards.size() == 0) {
|
if(solvedBoards.size() == 0) {
|
||||||
switch (gameType) {
|
|
||||||
case Default_9x9:
|
solver = new Solver(gameBoard);
|
||||||
case Default_6x6:
|
|
||||||
case Default_12x12:
|
|
||||||
solver = new Solver(gameBoard);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException("No Solver for this GameType defined.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (solver.solve(solver.getGameBoard())) {
|
if (solver.solve(solver.getGameBoard())) {
|
||||||
solvedBoards.addAll(solver.getSolutions());
|
solvedBoards.addAll(solver.getSolutions());
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package tu_darmstadt.sudoku.game.solver;
|
package tu_darmstadt.sudoku.controller;
|
||||||
|
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -15,7 +15,7 @@ import tu_darmstadt.sudoku.game.ICellAction;
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 10.11.2015.
|
* Created by Chris on 10.11.2015.
|
||||||
*/
|
*/
|
||||||
public class Solver implements ISolver {
|
public class Solver {
|
||||||
|
|
||||||
private GameBoard gameBoard = null;
|
private GameBoard gameBoard = null;
|
||||||
private LinkedList<GameBoard> solutions = new LinkedList<>();
|
private LinkedList<GameBoard> solutions = new LinkedList<>();
|
||||||
|
@ -152,7 +152,6 @@ public class Solver implements ISolver {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean calculateNextPossibleStep() {
|
public boolean calculateNextPossibleStep() {
|
||||||
|
|
||||||
return false;
|
return false;
|
|
@ -0,0 +1,8 @@
|
||||||
|
package tu_darmstadt.sudoku.controller.generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 19.11.2015.
|
||||||
|
*/
|
||||||
|
public class Generator {
|
||||||
|
|
||||||
|
}
|
|
@ -17,10 +17,11 @@ public class GameBoard implements Cloneable {
|
||||||
private GameCell[][] field;
|
private GameCell[][] field;
|
||||||
private List<IModelChangedListener> modelChangedListeners = new LinkedList<>();
|
private List<IModelChangedListener> modelChangedListeners = new LinkedList<>();
|
||||||
|
|
||||||
public GameBoard(int size, int sectionHeight, int sectionWidth) {
|
public GameBoard(GameType gameType) {
|
||||||
this.sectionHeight = sectionHeight;
|
this.gameType = gameType;
|
||||||
this.sectionWidth = sectionWidth;
|
this.sectionHeight = gameType.getSectionHeight();
|
||||||
this.size = size;
|
this.sectionWidth = gameType.getSectionWidth();
|
||||||
|
this.size = gameType.getSize();
|
||||||
|
|
||||||
field = new GameCell[size][size];
|
field = new GameCell[size][size];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
|
|
||||||
}
|
|
|
@ -12,6 +12,7 @@ import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import tu_darmstadt.sudoku.game.GameCell;
|
import tu_darmstadt.sudoku.game.GameCell;
|
||||||
import tu_darmstadt.sudoku.controller.Symbol;
|
import tu_darmstadt.sudoku.controller.Symbol;
|
||||||
|
import tu_darmstadt.sudoku.game.IModelChangedListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by TMZ_LToP on 10.11.2015.
|
* Created by TMZ_LToP on 10.11.2015.
|
||||||
|
|
Loading…
Reference in a new issue