PHP Classes

Sudoku Solver: Solve Soduku puzzle game

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   Screenshots Screenshots   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum (6)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2009-02-11 (6 years ago) RSS 2.0 feedStarStarStar 50%Total: 4,359 This week: 1All time: 617 This week: 1,128Down
Version License Categories  
sudoku 1.0GNU General Publi...PHP 5, Games, Artificial intelligence
Description Author  

Sudoku is a puzzle that has become very popular recently and has been published in many newspapers.

Sudoku is a number puzzle where you are presented with a grid of size 9 by 9, that is subdivided in 9 blocks of 3 by 3. Some fields in the grid contain a digit from 1 to 9. The objective is to fill in the rest of the fields such that each row, column and block will contain all digits exactly once. A good Sudoku has a single solution.

This class attempts to use the same strategies that a human player would use to solve a Sudoku puzzle. It can solve many Sudoku puzzles but not all, because it only uses logic and refrains from brute-force solving.

You can interactively influence the solution process to try out rules of your own. You can easily enter a Sudoku puzzle and save it to try it again later. PHP 5 is required.

Innovation Award  
PHP Programming Innovation award nominee
September 2005
Number 8

Prize: One subscription to the PHP Magazine
There are games that were meant to be played only by human players. Multi-player games need more than one human player to be available. Sometimes it is not possible to have more human player available. In that case, it would be interesting if the human player could play with a computer based player.

The challenge of implementing games that need to have computer based players is that they usually need to emulate human intelligence to make human-computer games almost as interesting as human-human games.

This class implements an educative example of the use of artificially intelligence to demonstrate how a computer can emulate human intelligence to accomplish similar tasks.

This example can be useful for those that are interested in learning how to apply artificial intelligence techniques to solve problems on which it is interesting that a computer plays the role of human being, in games or in other more serious types of applications.

Manuel Lemos
Picture of Ghica van Emde Boas
Name: Ghica van Emde Boas is available for providing paid consulting. Contact Ghica van Emde Boas .
Classes: 1 package by
Country: The Netherlands The Netherlands
Age: 71
All time rank: 63819 in The Netherlands The Netherlands
Week rank: 916 Down27 in The Netherlands The Netherlands Down
Innovation award
Innovation award
Nominee: 1x

1. To use the sudoku solver, just unpack the package to a directory of your choice.
2. Place the examples in a local directory on your client.
3. !!! Create a subdirectory of the directory where you put the Sudoku Solver classes,
call it temp, and make sure you can move uploaded files (the Sudoku examples) 
to this directory, by making it writable. 
4. Start the solver by executing the sudoku.php script.

A PHP4 version can be found in the sudoku4 subdirectory (note point 3 also)

Summary of changes made by Mike Diplock - Feb. 2009
I have attached the files I changed to implement the x-wing solution ( ) and I have also attached three puzzles that require the x-wing solution.
I found that the array_diff function acting on objects does not work in php 5.2.8 due to changes in _to_string() so I have modified getRCB to actually ignore certain fields when it builds the array rather than doing the diff afterwards.
I have completely rewritten the group check as I couldn't work out how the old method worked and it seemed overly complicated. I have implemented it here using a combinadic algorithm which is more efficent and was also required for the x-wing solution.

Ton Meuleman - added the checkGrouping solution, March 2007

original author: Ghica van Emde Boas, Sept. 2005
  • screenshot3.jpg
  • screenshot2.jpg
  • screenshot1.jpg
  Files folder image Files  
File Role Description
Files folder imagesudoku4 (6 files)
Plain text file DLX.class.php Class new solution rule
Plain text file license.txt Lic. GPL License
Plain text file NumberField.class.php Class NumberField class
Plain text file open-easy1.txt Data Easy example
Plain text file open-hard1.txt Data Hard example
Plain text file puzzle1.txt Example puzzle requiring x-wing
Plain text file puzzle2.txt Example puzzle requiring x-wing
Plain text file puzzle3.txt Example puzzle requiring x-wing
Accessible without login Plain text file readme.txt Doc. readme
Plain text file Solver.class.php Class Solver class
Accessible without login HTML file sudoku-help.html Doc. Help and Documentation
Plain text file Sudoku.class.php Class User interface class
Plain text file sudoku.css Data Style sheet
Plain text file sudoku.php Appl. Starter script

  Files folder image Files  /  sudoku4  
File Role Description
  Plain text file NumberField.class.php Class PHP4 Numberfield class
  Plain text file Solver.class.php Class PHP4 Solver class
  HTML file sudoku-help.html Doc. PHP4 help file
  Plain text file Sudoku.class.php Class PHP4 Sudoku class
  Plain text file sudoku.css Data PHP4 Numberfield class
  Plain text file sudoku.php Aux. PHP4 Numberfield class

 Version Control Unique User Downloads Download Rankings  
 0%Total:4,359All time:617
 This week:1This week:1,128Down
 User Ratings  
 All time