/** * @param MoveCalculator $moveCalculator */ public function finishTurn(MoveCalculator $moveCalculator) { if ($this->hasFinished()) { return; } $this->next(); if ($moveCalculator->isCheckmated($this->getCurrentColor(), $this->getBoard())) { switch ($this->getOpposingPlayer()->getColor()) { case Color::WHITE: $this->setFinishedReason(GameInterface::FINISHED_REASON_CHECKMATE_BY_WHITE); break; case Color::BLACK: $this->setFinishedReason(GameInterface::FINISHED_REASON_CHECKMATE_BY_BLACK); break; } $this->setFinished(true); } elseif (empty($moveCalculator->possibleMovesBy($this->getCurrentColor(), $this->getBoard()))) { switch ($this->getCurrentColor()) { case Color::WHITE: $this->setFinishedReason(GameInterface::FINISHED_REASON_STALEMATE_FOR_WHITE); break; case Color::BLACK: $this->setFinishedReason(GameInterface::FINISHED_REASON_STALEMATE_FOR_BLACK); break; } $this->setFinished(true); } }