-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku.php
116 lines (106 loc) · 2.71 KB
/
sudoku.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* This class is used to provide other classes with default informartion about the
* Sudoku game
*
* @author WIM
* @version Release: $Id:$
*/
class Sudoku
{
/**
* The maximum number that can be used in the game
*
* @var integer
* @access private
*/
private $rangeMax = 9;
/**
* Provide the available numbers in the Sudoku game
*
* @return array The available numbers
* @access public
* @author WIM
*/
public function getAvailableNumbers()
{
return range(1, $this->rangeMax);
}
/**
* Set the maximum number that can be used in this game
*
* @param integer $number The maximum number
*
* @return void
* @access public
* @author WIM
*/
public function setMaxNumber($number)
{
if (empty($number) || !is_numeric($number)) {
throw new Exception('No (valid) number has been provided');
}
$this->rangeMax = $number;
}
/**
* Get the border length of the board
*
* @return integer The length of the border
* @access public
* @author WIM
*/
public function getBoardBorderLength()
{
return count($this->getAvailableNumbers());
}
/**
* Get the border length of a single block on the board
*
* @return integer The border length of a single block
* @access public
* @author WIM
*/
public function getBlockBorderLength()
{
// Calculate the length of the border of the board
$length = sqrt(count($this->getAvailableNumbers()));
// Check if the recieved length is valid
if ((int) $length != $length) {
throw new Exception('No valid value for the border length could be calculated');
}
return $length;
}
/**
* Calculate the number o fblocks provided at one side of the board
*
* @return integer The number of blocks at one side
* @access public
* @author WIM
*/
public function getNumberBlockPerSide()
{
return $this->getBoardBorderLength() / $this->getBlockBorderLength();
}
/**
* Calculate the number of squares on one side of the board
*
* @return integer The number of squares on one side
* @access public
* @author WIM
*/
public function getNumberOfSquaresOnBoard()
{
return $this->getBoardBorderLength() * $this->getBoardBorderLength();
}
/**
* Get the number of squares within a block
*
* @return integer The number of squares
* @access public
* @author WIM
*/
public function getNumberOfSquaresInBlock()
{
return count($this->getAvailableNumbers());
}
}