| Total Complexity | 8 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 12 | final class NQueensPuzzle implements Puzzle |
||
| 13 | { |
||
| 14 | /** @var Board */ |
||
| 15 | private $board; |
||
| 16 | /** @var Moves */ |
||
| 17 | private $moves; |
||
| 18 | |||
| 19 | public function __construct(Board $board, Moves $moves) |
||
| 20 | { |
||
| 21 | $this->board = $board; |
||
| 22 | $this->moves = $moves; |
||
| 23 | } |
||
| 24 | |||
| 25 | public static function forQueens(int $n): Puzzle |
||
| 26 | { |
||
| 27 | return new self(Board::ofSize($n), Moves::none()); |
||
| 28 | } |
||
| 29 | |||
| 30 | public function representation(): string |
||
| 31 | { |
||
| 32 | $board = explode(PHP_EOL, (string) $this->board); |
||
| 33 | /** @var QueenPlacement $queen */ |
||
| 34 | foreach ($this->moves as $queen) { |
||
| 35 | $board[1 + $queen->row()][2 + $queen->column() * 3] = 'Q'; |
||
| 36 | } |
||
| 37 | return implode(PHP_EOL, $board); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function afterMaking(Move ...$moves): Puzzle |
||
| 41 | { |
||
| 42 | return new self($this->board, $this->moves->add(...$moves)); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function isSolved(): bool |
||
| 46 | { |
||
| 47 | return $this->board->isSolvedWith(...$this->moves); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function movesSoFar(): Moves |
||
| 51 | { |
||
| 52 | return $this->moves; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function possibleMoves(): Moves |
||
| 58 | } |
||
| 59 | } |
||
| 60 |