What is Sudoku?

Traditional Sudoku is a 9x9 puzzle grid made up of nine 3x3 regions. Each region, row, and column contains nine cells each.

How to Play

The numbers shown in the example are the "givens". These numbers can not be changed in any puzzle. You solve the puzzle by filling in the empty cells with a single number (from all the possible candidates) that doesn't violate Sudoku rules (for a simple overview of the rules see here). There is only one correct number per cell.

My Object Model

Objects I think I will need are:

  • Main Board - The main object that holds all of the other smaller grids, rows and columns
  • Cells - The smallest level of the Main Board which will store the values possible and the selected value
  • Timer - I will need an object to tell the time from when a puzzle is loaded to when it is completed

Arrays I think I will need are:

  • Current Game - An array of current values of Main Board that will store the current, given and missing values. This array will change with each move and will be used to compare for errors and puzzle completion.
  • Correct Puzzle - An array showing the correct values of the current puzzle; this will be a full array containing 81 values and will be used to compare the current game array to find any errors and also check to see when the puzzle is complete.
  • User History - An array showing the Cell and value that the user selected so I can "Undo" moves for the user; this will be a simple array that will store the location and previous value of the cell before any change, allowing me to easily step backwards and undo a users input.
  • 2D Array of Rows - An array with 9 array's each containing the data for a row in the board; this will allow me to easily find possible values by using this array to index the current 1x9 row for possible options and will look like this; [[1,2,3,4,5,6,7,8,9],[9,8,7,6,5,4,3,2,1],[]......]
  • 2D Array of Columns - An array with 9 array's each containing the data for a column in the board; this will allow me to easily find possible values by using this array to index the current 9x1 column for possible options and will look like this; [[1,2,3,4,5,6,7,8,9],[9,8,7,6,5,4,3,2,1],[]......]
  • 2D Array of Boxes - An array with 9 array's each containing the data for a box in the board; this will allow me to easily find possible values by using this array to index the current 3x3 box for possible options and will look like this; [[1,2,3,4,5,6,7,8,9],[9,8,7,6,5,4,3,2,1],[]......]
  • Array's of Pre-Made Games - Several various game array's for each difficulty level; This will have an array like this which contains a string of numbers that I will parse out into the respective cells; '000400070170900082600500040000049300900356008006270000060005001810004029090002000'

Some of the functions I think I will need are:

  • LoadGame(level) - This will take one parameter, the level of difficulty and choose one of the predefined games to load into the browser. This will dynamically load in the HTML needed with the current cells that are editable and which are not with their given styles.
  • SetValue(selection) - This will take the users selection and insert it into the Current Game array.
  • Validate() - This will not take any parameters, but will simply loop through the current game array and compare it for incorrect values. Then change the css styling of those values to reflect the incorrect values.
  • Possibles(cell) - This will take the current cell as a parameter and return a list of possible values that the user can choose from. This function will look at the Row, Column, and Small Grid areas and eliminate any selected values to show what is remaining.
500fail_a.html