SudokuJS -- JavaScript Sudoku solver

SudokuJS has a step by step solver that implements basic strategies, enough to solve (non evil) newspaper sudoku puzzles. The solver is built to mimic humans in that it attempts strategies in order from easiest to most difficult, in each step. So if you're stuck with a puzzle this solver will show you the minimal next step to continue.

SudokuJS comes with a basic GUI for the sudoku board - the board is rendered on the screen, and the board cells listen for keyboard input from a user.

SudokuJS can generate sudoku puzzles of the same difficulties that it can solve, ranging from Easy to Very hard.

SudokuJS currently requires jQuery library.

### Run Demo Online

SudokuJS (4x4) - Introductory Sudoku : demo-board-size-4.html
SudokuJS (9x9) - Demo with controls: demo-edit-candidates.html
SudokuJS (9x9) - Demo with board generation: demo-generate-board.html
SudokuJS (9x9) - Simple demo: demo-simple.html
SudokuJS (9x9) - Demo with controls: demo-w-controls.html
SudokuJS (16x16) - Professional Sudoku : demo-board-size-16.html

### Usage

#### Initialization
   [script src='sudokuJS.js'][/script]
   [link rel='stylesheet' href='sudokuJS.css' /]

   [div id='sudoku'][/div]

   [script]
      var mySudokuJS = $("#sudoku").sudokuJS({
        difficulty: "medium" ("easy"|"medium"|"hard"|"very hard")
   });
   [/script]

You can also pass in your own board:

   //array representing a standard sudoku puzzle of size 9
   //use space for empty cells
   var board = [
      , , ,4, ,8, ,2,9
      , , , , , , , , ,4
      ,8,5, , ,2, , , ,7
      , , ,8,3,7,4,2, ,
      , ,2, , , , , , ,
      , , ,3,2,6,1,7, ,
      , , , , ,9,3,6,1,2
      ,2, , , , , ,4, ,3
      ,1,3, ,6,4,2, ,7,undefined
   ]
   //NOTE: if last cell of board is empty, 'undefined' has to be used as value!
   var mySudokuJS = $("#sudoku").sudokuJS({
      board: board
   });

#### Solving
Let `SudokuJS` solve your puzzle - either step by step, or all in one go:

   mySudokuJS.solveStep();
   mySudokuJS.solveAll();

#### Analyzing the board
The solver can tell you info about the board.

   var data = mySudokuJS.analyzeBoard();

   //data.error -- board is incorrect
   //data.finished === false -- board can't be solved because it requires more advanced strategies

   //if no error, and data.finished === true
   //data.level -- "easy"|"medium"|"hard"
   //data.score -- int [experimental]
   //data.usedStrategies -- [{title, freq}, ..],ranked by difficulty, easiest first

#### Board Generation
`SudokuJS` generate new sudoku puzzles on init when no board is passed in, and on `generateBoard` calls:

   mySudokuJS.generateBoard('easy');
   mySudokuJS.generateBoard('medium');
   mySudokuJS.generateBoard('hard');
   mySudokuJS.generateBoard('very hard');

The current implementation for board generation cannot guarantee hard or very hard puzzles generated on every try, so instead it continues over and over until is has succeeded. This means loading a very hard board can sometimes take up to a few seconds.

`generateBoard` accepts a `callback` function as a second parameter, that gets called when the new board is ready.

#### Candidates
Candidates are hidden when a board loads. To show/hide candidates:

   mySudokuJS.showCandidates();
   mySudokuJS.hideCandidates();

SudokuJS automatically removes impossible candidates on showCandidates();
candidates that can be eliminated via visualElimination (number already exists in same house).

Candidates can be edited on the board by setting SudokuJS to candidate editing mode:

   mySudokuJS.setEditingCandidates(true);

Input changes on board cells will now toggle the candidates rather than changes the value.

#### Clear board
Useful before entering new puzzle, if using keyboard input in the GUI.

   mySudokuJS.clearBoard();

#### Get/Set board
Get the board and save it away if you want. Set a new board and play with that one instead.
Setting automatically resets everything back to init state.

   mySudokuJS.getBoard();

   var newBoard = [
   ...
   ]

   mySudokuJS.setBoard(newBoard);

### Callbacks

#### boardUpdatedFn
Fires whenever the board is updated, whether by user or solver.

   $("#sudoku").sudokuJS({
      board: board
      ,boardUpdatedFn: function(data){
         //data.cause: "user input" | name of strategy used
         //data.cellsUpdated: [] of indexes for cells updated
            alert("board was updated!");
      }
   });

#### boardFinishedFn
Fires when the board has been completed.

   $("#sudoku").sudokuJS({
      board: board
      ,boardFinishedFn: function(data){
         //ONLY IF board was solved by solver:
         //data.difficultyInfo {
         // level: "easy", "medium", "hard"
         // ,score: int [experimental]
         //}
         alert("board was finished!");
      }
   });


#### boardErrorFn
Fires whenever the board is found to be incorrect, f.e. if solver detects there is no solution to board, or if passed in board is of invalid size.

   $("#sudoku").sudokuJS({
      board: board
      ,boardErrorFn: function(data){
         //data.msg -- f.e. "board incorrect"
         alert("board error!");
      }
   });

#### candidateShowToggleFn
The solver automatically switches to showing candidates when a solve step was invoked which only updated the candidates on the board. To catch this change (for updating UI, etc), there is a callback:

   $("#sudoku").sudokuJS({
      board: board
      ,candidateShowToggleFn: function(showingBoolean){
         alert("candidates showing: " + showingBoolean); //true|false
      }
   }

### Extra
The solver is board size agnostic, so you can pass in any valid sudoku sized board (f.e. 4x4, 9x9, 16x16) - however the CSS included only handles 9x9 boards. Currently you can't change boardSize after init.

### Changelog
* boardSize option, now working. Demos for board sizes
* Candidate editing mode
* Board generator, easy - very hard
* Simple UI and better interface
* Step by step sudoku solver

Write a review

Note: HTML is not translated!
    Bad           Good
Captcha

SudokuJS -- JavaScript Sudoku solver

  • Product Code: MOD190820030548
  • Availability: In Stock
  • Viewed: 16407
  • Units Sold: 2
  • Sold By: BestScripts
  • Seller Rating:
  • Seller Reviews: (0)
  • $19.95

  • Ex Tax: $19.95

Available Options


Related Products

Chinese Chess in HTML5 and JavaScript

Chinese Chess in HTML5 and JavaScript

Chinese Chess in HTML5 and JavaScript This is a project of Chinese Chess with AI based on HTML5/C..

$0.00 Ex Tax: $0.00

Save
10%

Math Tutor For Kids

Math Tutor For Kids

[JavaScript Game] Math Tutor For Kids ==================== A simle browser based math game for sma..

$8.95 $9.95 Ex Tax: $8.95

Educational Maze Game for Kids - HTML5 Games

Educational Maze Game for Kids - HTML5 Games

Educational Maze Game for Kids is an Easy fun Maze for Preschool Toddler Kids. Maze puzzle is alwa..

$0.00 Ex Tax: $0.00

Javascript Breakout Game, Online HTML5 Game

Javascript Breakout Game, Online HTML5 Game

Bring back nostalgic memories with Breakout! It still has the same gameplay and challenges as al..

$9.95 Ex Tax: $9.95

Save
25%

HTML Invoice with Fillable Forms

HTML Invoice with Fillable Forms

HTML Invoice with Fillable Forms HTML Invoice with Fillable Forms is a minimal clean unique, modern..

$29.95 $39.95 Ex Tax: $29.95

HTML5 PDF Annotation Source Code License

HTML5 PDF Annotation Source Code License

HTML5 PDF Annotation Source Code License HTML5 PDF Annotation is a HTML5 Based Document & Image Ann..

$6,500.00 Ex Tax: $6,500.00

Akala - Mobile Template for Food, Cafe and Restaurant

Akala - Mobile Template for Food, Cafe and Restaurant

Akala is Mobile Template for Food, Cafe and Restaurant have 4 creative home pages, 3 Product list, 4..

$14.00 Ex Tax: $14.00

Auri - A Modern Mobile Template

Auri - A Modern Mobile Template

Auri – A Modern Mobile Template is super clean templates, fits in every niche such as clean portfoli..

$14.00 Ex Tax: $14.00

3D Racer Online HTML5 Javascript Game

3D Racer Online HTML5 Javascript Game

3D Racer Online HTML5 Javascript Game 3D Racing is an exciting car games game. Check it out on Very..

$9.95 Ex Tax: $9.95

Arena5 - HTML5 Game for Web, Written by Html5 and JavaScript, Game Template

Arena5 - HTML5 Game for Web, Written by Html5 and JavaScript, Game Template

Arena5 - HTML5 Game for Web, written by Html5 and JavaScript, Game Template Use WASD or Arrow k..

$19.95 Ex Tax: $19.95

JQuery Html5 Video Player

JQuery Html5 Video Player

JQuery Html5 Video Player is a fantastic HTML5 video player based on jQuery JavaScript Library. Th..

$29.95 Ex Tax: $29.95

Tiny Platformer Online HTML5 Javascript Game

Tiny Platformer Online HTML5 Javascript Game

Tiny Platformer Online HTML5 Javascript Game..

$9.95 Ex Tax: $9.95

Online HTML5 Delta Game, JavaScript Shooting Game

Online HTML5 Delta Game, JavaScript Shooting Game

Javascript HTML5 Delta Game, JavaScript Shooting Game ================= This is a small weekend ho..

$9.95 Ex Tax: $9.95

Tags: html5 sudoku, javascript sudoku, js sudoku, play sudoku, sudoku, sudoku game, sudoku puzzles, web sudoku

You Recently Viewed

DOC to Any Converter Command Line

DOC to Any Converter Command Line

DOC to Any Converter Command Line can be used to batch convert DOC, DOCX, DOCM, RTF, TXT, PPT, PPT..

$79.00 Ex Tax: $79.00

DocVoicer (Text-To-Speech) Software

DocVoicer (Text-To-Speech) Software

DocVoicer is a Text-To-Speech (TTS) software to read Text, PDF, MS Office, OpenOffice, Web Page an..

$39.95 Ex Tax: $39.95

PDF to Vector Converter Command Line

PDF to Vector Converter Command Line

PDF to Vector Converter Command Line -- Batch convert from PDF files to Vector formats. PDF to Ve..

$295.00 Ex Tax: $295.00

Save
20%

BatchPrint for Windows

BatchPrint for Windows

BatchPrint is a batch printing software for Windows to batch print multiple documents in different f..

$39.95 $49.95 Ex Tax: $39.95