/** * @param MoveInterface $move * * @return string */ public static function toNotation(MoveInterface $move) { if (null === $move->getPiece()) { return ''; } $notation = ''; $piece = $move->getPiece(); $toLabel = strtolower($move->getToLabel()); $isPawn = $piece->getType() === PieceInterface::TYPE_PAWN; $pieceLetter = PieceDecorator::toLetter($piece); if (null !== ($capture = $move->getCapture())) { if ($isPawn) { $column = BoardHelper::getColumnFromPosition($move->getFrom()); $pieceLetter = BoardHelper::columnNumberToLetter($column); } $notation .= sprintf('%sx%s', $pieceLetter, $toLabel); if ($isPawn) { if ($move->getType() === MoveInterface::TYPE_CAPTURE_EN_PASSANT) { $notation .= 'e.p.'; } } return $notation; } if ($isPawn) { return $toLabel; } return sprintf('%s%s', $pieceLetter, $toLabel); }
/** * @param MoveInterface $move * * @return GameState */ private function createStateFromMove(MoveInterface $move) { if (!$move->getFrom()) { return null; } $gameState = new GameState(); $gameState->setFrom($move->getFrom()); $gameState->setTo($move->getTo()); $gameState->setPiece($move->getPiece()); $gameState->setCapture($move->getCapture()); $gameState->setMoveType($move->getType()); return $gameState; }