-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
57 lines (48 loc) · 1.62 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// A dummy gameset to solve
$blocks = array(
'006000300', '309000080', '070132060',
'009070465', '400000001', '000040900',
'040927080', '060500902', '007000300',
);
$board = implode('', $blocks);
// Initiate the required classes
include('painter.php');
include('parser.php');
include('generator.php');
include('calculator.php');
include('sudoku.php');
include('validator.php');
$Validator = new Validator();
$Sudoku = new Sudoku();
$Generator = new SudokuGenerator($Sudoku);
$Parser = new SudokuParser($Sudoku);
$Painter = new SudokuPainter($Sudoku, $Parser);
$Calculator = new SudokuCalculator($Sudoku, $Generator, $Painter, $Validator);
// Cgecj if the board only needs to be drawn, or a solution to be calculated
if (!empty($_POST['square']) || PHP_SAPI == 'cli') {
// If runned in CL mode, use the provided board input
if (PHP_SAPI == 'cli') {
$numberstring = $board;
} else {
// Retrieve the provided gameset
$numberstring = $Generator->generateNumberStringFromArray($_POST['square']);
}
// Start with validating the provided gameset
$Calculator->checkCorrectnessNumberstring($numberstring);
// Try to calculate a solution
$solution = $Calculator->calculateSolution($numberstring);
// Draw the final solution onto a board
echo $Painter->printSudokuBoard($solution, true);
} else {
// Draw a empty board
echo <<<html
<form method="post">
{$Painter->printSudokuBoard($board)}
<input type="submit" value="Oplossen">
</form>
html;
}
// Draw a Sudoku gameboard
// p102
//echo $Painter->printSudokuBoard($board, false);