# Sudoku.java - /* * Sudoku.java * * Implementation of a...

• 5
• 78% (9) 7 out of 9 people found this document helpful

This preview shows page 1 - 3 out of 5 pages.

/*** Sudoku.java** Implementation of a class that represents a Sudoku puzzle and solves* it using recursive backtracking.** Computer Science 112, Boston University** your name:* partner's name and email (if any):*/import java.io.*;// allows us to read from a fileimport java.util.*;public class Sudoku {// The current contents of the cells of the puzzle.private int[][] grid;/** Indicates whether the value in a given cell is fixed* (i.e., part of the initial configuration).* valIsFixed[r][c] is true if the value in the cell* at row r, column c is fixed, and false otherwise.*/private boolean[][] valIsFixed;/** This 3-D array allows us to determine if a given subgrid (i.e.,* a given 3x3 region of the puzzle) already contains a given* value.We use 2 indices to identify a given subgrid:**(0,0)(0,1)(0,2)**(1,0)(1,1)(1,2)**(2,0)(2,1)(2,2)** For example, subgridHasVal[0][2][5] will be true if the subgrid* in the upper right-hand corner already has a 5 in it, and false* otherwise.*/private boolean[][][] subgridHasVal;/*** ADD YOUR ADDITIONAL FIELDS HERE. ***/private boolean[][] rowHasVal;private boolean[][] colHasVal;/** Constructs a new Puzzle object, which initially* has all empty cells.*/public Sudoku() {this.grid = new int[9][9];this.valIsFixed = new boolean[9][9];/** Note that the third dimension of the following array is 10,
* because we need to be able to use the possible values* (1 through 9) as indices.

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 5 pages?