/** * @param BoardInterface $board * @param bool $flipped * * @return string */ public static function toAscii(BoardInterface $board, $flipped = false) { $squaresByRow = $board->getIndexedSquares('row'); $ascii = ''; if ($flipped !== true) { $squaresByRow = array_reverse($squaresByRow, true); } $previousRow = null; foreach ($squaresByRow as $row => $squares) { if ($previousRow !== $row) { if ($previousRow !== null) { $ascii .= "\n"; } $ascii .= sprintf('%d ║', $row); } /** @var Square[] $squares */ foreach ($squares as $square) { if (null !== ($piece = $square->getPiece())) { $ascii .= PieceDecorator::toAscii($piece); } else { $ascii .= '…'; } $ascii .= ' '; } $ascii = rtrim($ascii); $previousRow = $row; } $ascii .= "\n"; $columnLabels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; $ascii .= ' ╚' . str_repeat('═', count($columnLabels) * 2 - 1) . "\n"; $ascii .= ' '; foreach ($columnLabels as $columnLabel) { $ascii .= $columnLabel . ' '; } $ascii .= "\n"; return $ascii; }