| Total Complexity | 9 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class HintGenerator |
||
| 12 | { |
||
| 13 | public function generateOne(Grid $grid): Location |
||
| 14 | { |
||
| 15 | $locationList = $this->generateAll($grid); |
||
| 16 | if (empty($locationList)) { |
||
| 17 | throw new UnsolvableException(); |
||
| 18 | } |
||
| 19 | shuffle($locationList); |
||
| 20 | |||
| 21 | return $locationList[0]; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return Location[] |
||
| 26 | */ |
||
| 27 | public function generateAll(Grid $grid): array |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return Location[] |
||
| 41 | */ |
||
| 42 | private function getLocations(): array |
||
| 43 | { |
||
| 44 | $locations = []; |
||
| 45 | for ($row = 0; $row < Grid::NUMBER_OF_ROWS; $row++) { |
||
| 46 | for ($column = 0; $column < Grid::NUMBER_OF_COLUMNS; $column++) { |
||
| 47 | $locations[] = new Location($row, $column); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | return $locations; |
||
| 52 | } |
||
| 53 | |||
| 54 | private function hasOnePossibleValue(Grid $grid, Location $location): bool |
||
| 59 | } |
||
| 60 | } |
||
| 61 |