package if(!this.numInCol(col,value) && !this.numInRow(row,value) && !this.numInBox(row,col,value)) { return true;

package sudoku;
import java.util.Arrays;
//////////////////////////////////////////////////////////////////// SudokuModelpublic class SudokuModel { //================================================================ constants private static final int BOARD_SIZE = 9; private static final int SUBSQUARE = 3; // Size of subsquare.
//=================================================================== fields private int _board; //============================================================== constructor public SudokuModel() { _board = new intBOARD_SIZEBOARD_SIZE; } //============================================================== constructor public SudokuModel(String initialBoard) { this(); // Call no parameter constructor first. // initializeFromString(initialBoard); } //===================================================== initializeFromString public void initializeFromString(final String boardStr) { clear(); // Clear all values from the board. int row = 0; int col = 0; int boardLength = BOARD_SIZE*BOARD_SIZE; //… Loop over every character. for (int i = 0; i < boardLength; i++) { char c = boardStr.charAt(i); if (c >= ‘1’ && c <='9') { if (row > BOARD_SIZE || col > BOARD_SIZE) { throw new IllegalArgumentException(“SudokuModel: ” + ” Attempt to initialize outside 1-9 ” + ” at row ” + (row+1) + ” and col ” + (col+1)); } _boardrowcol = c – ‘0’; // Translate digit to int. col++; } else if (c == ‘.’) { col++; } else if (c == ‘/’) { row++; col = 0; } else { throw new IllegalArgumentException(“SudokuModel: Character ‘” + c + “‘ not allowed in board specification”); } } } //============================================================== islegalMove public boolean isLegalMove(int row, int col, int val) { return row>=0 && row=0 && col0 && val<=9 && _boardrowcol==0; } //=================================================================== setVal public void setVal(int r, int c, int v) { _boardrc = v; } //=================================================================== getVal public int getVal(int row, int col) { return _boardrowcol; } //===================================================================== clear public void clear() { for (int row = 0; row < BOARD_SIZE; row++) { for (int col = 0; col < BOARD_SIZE; col++) { setVal(row, col, 0); } } } /* ======================= Solver ====================================== */ public void makeMove(int row,int col, int value) { if(this.isValidMove(row,col,value)) { this._boardrowcol = value; // this.mutablerowcol = isMutable; } } public boolean isValidMove(int row,int col,int value) { if(this.isLegalMove(row, col, value)) { if(!this.numInCol(col,value) && !this.numInRow(row,value) && !this.numInBox(row,col,value)) { return true; } } return false; } public boolean numInCol(int col,int value) { if(col <= BOARD_SIZE) { for(int row=0;row < BOARD_SIZE;row++) { if(this._boardrowcol == value) { return true; } } } return false; } public boolean numInRow(int row,int value) { if(row <= BOARD_SIZE) { for(int col=0;col < BOARD_SIZE;col++) { if(this._boardrowcol == value) { return true; } } } return false; } public boolean numInBox(int row,int col,int value) { // if(this.inRange(row, col)) { int boxRow = row / SUBSQUARE; int boxCol = col / SUBSQUARE; int startingRow = (boxRow*SUBSQUARE); int startingCol = (boxCol*SUBSQUARE); for(int r = startingRow;r <= (startingRow+SUBSQUARE)-1;r++) { for(int c = startingCol;c <= (startingCol+SUBSQUARE)-1;c++) { if(this._boardrc == value) { return true; } } } // } return false; } public int deepCopyArray() { int a2 = new intthis._board.lengththis._board0.length; for (int i = 0; i < this._board.length; i++) { for (int j = 0; j < this._board0.length; j++) { a2ij = this._boardij; } } return a2; } public boolean deepEquals(int a2){ return Arrays.deepEquals(this._board, a2); } public boolean solved(){ for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { if(this._boardij == 0){ return false; } } } return true; } public void printBoard() { //prints for (int i = 0; i < 9; ++i) { if (i % 3 == 0)System.out.println(" -----------------------"); for (int j = 0; j < 9; ++j) { if (j % 3 == 0) System.out.print("| "); System.out.print(this._boardij == 0 ? " " : this._boardij); System.out.print(' '); } System.out.println("|"); } System.out.println(" -----------------------"); System.out.println(); }}