PHP Classes

PHP Sudoku Solver: Generate and solve Sudoku puzzles

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 216 All time: 8,306 This week: 39Up
Version License PHP version Categories
sudoku-solver 1.0.0GNU Lesser Genera...5Algorithms, PHP 5, Games
Description 

Author

This class can senerate and solve Sudoku puzzles.

It takes a parameter that defines the size of the gride of a Sudoku puzzle that it will generate.

The class can render the generated Sudoku puzzle in an HTML table.

The class can also solve the puzzle determining the sequence of moves necessary to complete it.

Picture of Samuel Adeshina
  Performance   Level  
Name: Samuel Adeshina is available for providing paid consulting. Contact Samuel Adeshina .
Classes: 19 packages by
Country: Nigeria Nigeria
Age: 25
All time rank: 5232 in Nigeria Nigeria
Week rank: 49 Up3 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

Example


<?php
/*
    Description: This test file stores the current game play (an array actually)
                    In a session variable, you could decide to use cookies,
                    html5 state saving or any method of keeping the current data in memory
                    that works best for you.

    Author: Samuel Adeshina

    Dependency: The sudoku.php class file bundled together with this file is required
                    run the test.php file in a browser to get a 'visual instance' of how this works
*/
   
require_once("sudoku.php");
   
SESSION_START();
    if (!isset(
$_GET["loc"]) || !isset($_GET["sudokutype"]) || !isset($_GET["startover"])
        ||
$_GET["sudokutype"] == '' || $_GET["startover"] == '' || $_GET["loc"] == ''
      
)
        {
           
$_GET["sudokutype"] = 9;
           
$_GET["startover"] = "false";
           
$_GET["loc"] = "a1";
        }
   
$loc = $_GET["loc"];
   
$startover = $_GET["startover"];
   
$sudokType = $_GET["sudokutype"];
   
$mySudoku = new sudoku($sudokType); //Instantiating the sudoku class with a grid size of whatever is in the variable: $sudokType
   
if ($startover == "true")
    {
        if (isset(
$_SESSION["currentmoves"]))
        {
            unset(
$_SESSION["currentmoves"]);
        }
    }
    if (!isset(
$_SESSION["currentmoves"]) || !is_array($_SESSION["currentmoves"]))
    {
       
$_SESSION["currentmoves"] = $mySudoku->_populateSubs(); //Populating the board
   
}
   
//echo "<center>Number Of Iterations For Current Play: ";
   
$_SESSION["currentmoves"] = $mySudoku->_solveSudoku($loc, $_SESSION["currentmoves"]); //Generates the value of the grid with a name of : $loc ($loc could be a1, c4, i8 and so on)
   
$mySudoku->_viewSudoku($_SESSION["currentmoves"]);
    if (
in_array(-1, $_SESSION["currentmoves"]))
    {
       
$index = array_search(-1, $_SESSION["currentmoves"]);
       
$_SESSION["currentmoves"][$index] = '--'; //displays a custom character(s) in the grid incase the value cant be determined through brute force
   
}
?>


  Files folder image Files (5)  
File Role Description
Accessible without login Plain text file jquery.js Data JQuery Library needed only fr testing
Accessible without login Plain text file LICENSE Lic. License File
Plain text file sudoku.php Class Main Class File
Accessible without login Plain text file test.php Aux. Contains A Sample Interface Design For A Working Sudoku Game
Accessible without login Plain text file testProcessor.php Example Contains the Logic for the test file

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:216
This week:0
All time:8,306
This week:39Up