Extending SudokuSolver interface and specifying @overrides in implementation
This commit is contained in:
parent
383af5be58
commit
6366a5e0f2
2 changed files with 22 additions and 1 deletions
|
@ -10,6 +10,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setBoard(int[][] board) {
|
||||
this.board = board;
|
||||
}
|
||||
|
@ -17,6 +18,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int[][] getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
@ -24,6 +26,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* Resets the board to all zeros
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
board = new int[9][9];
|
||||
}
|
||||
|
@ -31,6 +34,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean solve() {
|
||||
return solve(0, 0);
|
||||
}
|
||||
|
@ -79,6 +83,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* Randomizes the board. This guarantees a solvable board.
|
||||
*/
|
||||
@Override
|
||||
public void randomizeBoard() {
|
||||
this.clear();
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
|
@ -94,6 +99,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void set(int row, int col, int val) {
|
||||
if (row < 9 && col < 9) {
|
||||
board[row][col] = val;
|
||||
|
@ -103,6 +109,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int get(int row, int col) {
|
||||
if (row < 9 && col < 9) {
|
||||
return board[row][col];
|
||||
|
@ -113,6 +120,7 @@ public class Solver implements SudokuSolver {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLegal(int row, int col, int val) {
|
||||
if (row < 0 || row >= 9 || col < 0 || col >= 9 || val < 1 || val > 9) {
|
||||
return false;
|
||||
|
@ -153,6 +161,7 @@ public class Solver implements SudokuSolver {
|
|||
*
|
||||
* @return true if solved
|
||||
*/
|
||||
@Override
|
||||
public boolean isSolved() {
|
||||
return isSolved(0, 0);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public interface SudokuSolver {
|
|||
* @param board a board to copy values from
|
||||
* @throws IllegalArgumentException if board is invalid, e.g. not 9x9
|
||||
*/
|
||||
void setBoard(int[][] board);
|
||||
void setBoard(int[][] board) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Get a copy of the sudoku board
|
||||
|
@ -49,6 +49,18 @@ public interface SudokuSolver {
|
|||
*/
|
||||
void set(int row, int col, int nbr);
|
||||
|
||||
/**
|
||||
* Randomize the board. Guaranteed to be solvable.
|
||||
*/
|
||||
void randomizeBoard();
|
||||
|
||||
/**
|
||||
* Check if the board is solved
|
||||
*
|
||||
* @return true if solved
|
||||
*/
|
||||
boolean isSolved();
|
||||
|
||||
/**
|
||||
* Clear the board
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue