diff --git a/src/Randomizer/Randomizer.php b/src/Randomizer/Randomizer.php index ee233e67..f9db19de 100644 --- a/src/Randomizer/Randomizer.php +++ b/src/Randomizer/Randomizer.php @@ -7,7 +7,6 @@ use Chess\Variant\Classical\PGN\AN\Color; use Chess\Variant\Classical\Board; use Chess\Variant\Classical\PGN\AN\Piece; -use Chess\Variant\Classical\Rule\CastlingRule; /** * Randomizer. @@ -19,10 +18,6 @@ */ class Randomizer { - const FILES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; - - const RANKS = ['1', '2', '3', '4', '5', '6', '7', '8']; - /** * Chess board. * @@ -30,20 +25,6 @@ class Randomizer */ protected Board $board; - /** - * Castling rule. - * - * @var array - */ - protected array $castlingRule; - - /** - * The items to be added. - * - * @var array - */ - protected array $items = []; - /** * Constructor. * @@ -52,13 +33,9 @@ class Randomizer */ public function __construct(string $turn, array $items = []) { - $this->castlingRule = (new CastlingRule())->getRule(); - - $this->items = $items; - + $this->board = new Board(); do { - $pieces = $this->kings(); - $pieces = $this->rand($items, $pieces); + $pieces = $this->rand($items, $this->kings()); $board = new Board($pieces); } while ($this->isAttackingKing($board)); @@ -66,7 +43,7 @@ public function __construct(string $turn, array $items = []) } /** - * Returns the Chess\Board object. + * Returns the board. * * @return \Chess\Variant\Classical\Board */ @@ -82,16 +59,10 @@ public function getBoard(): Board */ protected function sq(): string { - $files = self::FILES; - $ranks = self::RANKS; - - shuffle($files); - shuffle($ranks); - - $file = $files[0]; - $rank = $ranks[0]; + $sqs = $this->board->getSqs(); + shuffle($sqs); - return $file . $rank; + return $sqs[0]; } /** @@ -109,7 +80,7 @@ protected function areAdjacentSqs(string $w, string $b): bool } /** - * Creates a Chess\Board object with two randomly placed kings. + * Creates a board with two randomly placed kings. * * @return array */ @@ -129,8 +100,8 @@ protected function kings(): array ); $pieces = [ - new K(Color::W, $wSq, $this->castlingRule), - new K(Color::B, $bSq, $this->castlingRule), + new K(Color::W, $wSq, $this->board->getCastlingRule()), + new K(Color::B, $bSq, $this->board->getCastlingRule()), ]; $this->board = new Board($pieces);