4.75

4.8 | 8 ratings Rate this file 173 downloads (last 30 days) File Size: 17.46 KB File ID: #14073

Sudoku (Dancing Links Solver)

by Per-Anders Ekstrom

 

23 Feb 2007 (Updated 27 Feb 2007)

Code covered by BSD License  

SUDOKU Graphical User Interface for playing Sudoku-Puzzles.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

Game Rules:
Fill in the grid so that every row, every column, and every 3x3 box contains the digits 1 through 9.
 
Game Board:
The sudoku interface lets the user solve sudoku puzzles graphically. The puzzles are either generated by the built-in puzzle generator (three difficult levels can be chosen), randomly taken from the built-in database of 160 really difficult puzzles, entered manually by the or loaded from three standard ascii sudoku files 'Simple Sudoku' (.ss), 'Sudoku Puzzle' (.sdk) or 'Sudoku Puzzle Collection' (.sdm).
 The game board can be saved to Simple Sudoku and Sudoku Puzzle files.
 The current board can also be exported to various image-files, such as, png, bmp, eps or tiff. The board can be printed and also copied to clipboard to be pasted as an image in for example a MS Word document.
 
Game Controls:
The sudoku game can be played using either mouse or keyboard (or both). Move around marker using arrow keys and add a number using number keys. Delete, backspace or 0 (zero) will remove number from board. With mouse you move around marker using left-click and reach a context-menu with number choices using right-click.
Illegal characters can not be entered.
 
Game Solver:
The sudoku game has two built-in puzzle solvers, one quick and one 'human-like'. The quick one is based on Dancing Links (DLX), a technique suggested by Donald Knuth to efficiently implement his Algorithm X. Algorithm X is a recursive, nondeterministic, depth-first, brute-force algorithm that finds all solutions to the exact cover problem. The human solver finds Naked Singles, Hidden Singles, Naked Pairs and Locked Candidates 1 and 2. If this is not enough it takes a guess and tries to solve it recursively.
The dlx-solver is used for solving and generating puzzles while the human puzzle is used to generate a log of solution steps.
The game allows for automatic solving of the whole puzzle or just one single square. To help the user one can show all possible candidates for unfilled squares as well as showing all mistakes in a different color as well as making it impossible to make an illegal mark.
 
Extra Game Features:
The sudoku game has Undo and Redo functionality that can be reached from the Edit-menu, Context-menu or by the shortcuts Ctrl-Z (Undo) and Ctrl-R (Redo).
Every time one restarts a game a timer is started. Current time can be shown using Ctrl-T or enable/disabled from the Help menu.
A coloring help of possible candidates can be added to the matrix from the colored numbers in the toolbar.
 
Example:
sudoku % Start Main Sudoku Interface
sudoku('uitest') % Solve all 160 boards in database (test set)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Sudoku! (v3.4)

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (10)
26 Feb 2007 John D'Errico

A superb Sudoku tool. Great help. Everything I tried worked as it should. It can generate game layouts for you.

A minor complaint - this tool almost makes solving a puzzle too easy. ;-) Well done anyway.

02 Mar 2007 Eric Dean

Very impressive!

04 Mar 2007 Ali Karapelit  
10 Mar 2007 Zhijun Wang

Very good

28 Mar 2007 Aasmund Kvamme

Very nice graphics and an excellent logic!

04 Apr 2007 Paul G

Excellent code!

08 Jun 2007 Gersi Rami

No comment

13 Sep 2007 kiko kiko

Hi,
I think there is a bug around line 176.
kiko

14 Sep 2007 Per-Anders Ekström

Hello Kiko Kiko, thanks for mentioning. My first guess is that you have an old Matlab version, this Sudoku game was developed using release R2006a. At line 176 I use a function named arrayfun introduced in R14sp3, so if you have an older version than that it will not work.
Cheers!
P-A

03 Jul 2008 tddt dtduh

fgjrtu

Please login to add a comment or rating.
Updates
27 Feb 2007

Enhanced the toolbar to use a real toolbar.

Tag Activity for this File
Tag Applied By Date/Time
games Per-Anders Ekstrom 22 Oct 2008 09:01:50
sudoku Per-Anders Ekstrom 22 Oct 2008 09:01:50
dancing links Per-Anders Ekstrom 22 Oct 2008 09:01:50
algorithm x Per-Anders Ekstrom 22 Oct 2008 09:01:50
hidden Per-Anders Ekstrom 22 Oct 2008 09:01:50
naked single Per-Anders Ekstrom 22 Oct 2008 09:01:50
donald knuth Per-Anders Ekstrom 22 Oct 2008 09:01:50
potw Shari Freedman 21 Apr 2009 16:32:19
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com