Following the suggestion from @Oliver, I used Overlay
to create some kind of a solid white piece.
Also I used ItemSize -> All
as a grid option to make sure all squares have the same size.
I'm quite happy with the result.
showChessPosition[
fen_String :
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
] := Grid[
Partition[Partition[
Riffle[
Flatten@Characters[
StringSplit[StringExtract[fen, 1], "/"]
] /. {
"K" -> \[WhiteKing], "Q" -> \[WhiteQueen],
"R" -> \[WhiteRook], "B" -> \[WhiteBishop],
"N" -> \[WhiteKnight], "P" -> \[WhitePawn],
"k" -> \[BlackKing], "q" -> \[BlackQueen],
"r" -> \[BlackRook], "b" -> \[BlackBishop],
"n" -> \[BlackKnight], "p" -> \[BlackPawn],
n_String /; DigitQ[n] :>
Splice@ConstantArray[" ", ToExpression[n]]
}
/. {
p : \[WhiteKing] | \[WhiteQueen] | \[WhiteBishop] | \
\[WhiteKnight] | \[WhiteRook] | \[WhitePawn] :> Overlay[
{
Style[p /. {
\[WhiteKing] -> \[BlackKing], \[WhiteQueen] -> \
\[BlackQueen], \[WhiteBishop] -> \[BlackBishop], \[WhiteKnight] -> \
\[BlackKnight], \[WhiteRook] -> \[BlackRook], \[WhitePawn] -> \
\[BlackPawn]
}, White],
p
}
]
},
Flatten@Table[If[EvenQ[i + j], White, LightGray], {i, 8}, {j, 8}]
],
2
] /. {p_ , c : White | LightGray} :> Item[p, Background -> c], 8],
Alignment -> Center,
Frame -> True,
ItemSize -> All
]
Export[
"fool's mate.svg",
showChessPosition@
"rnb1kbnr/pppp1ppp/8/4p3/5PPq/8/PPPPP2P/RNBQKBNR w KQkq - 0 1",
"SVG"
]
PS. Here's an other rewrite.
showChessPosition[
fen_String :
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
] := Grid[
MapThread[
{piece, color} |-> Item[piece, Background -> color],
{
Characters[
StringReplace[
StringSplit[StringExtract[fen, 1], "/"],
MapThread[
Rule,
Characters /@ {
"KQRBNPkqrbnp",
"\[WhiteKing]\[WhiteQueen]\[WhiteRook]\[WhiteBishop]\
\[WhiteKnight]\[WhitePawn]\[BlackKing]\[BlackQueen]\[BlackRook]\
\[BlackBishop]\[BlackKnight]\[BlackPawn]"
}
]
]
] /. MapThread[
{w, b} |-> Rule[w, Overlay[{Style[b, White], w}]],
Characters /@ {"\[WhiteKing]\[WhiteQueen]\[WhiteRook]\
\[WhiteBishop]\[WhiteKnight]\[WhitePawn]",
"\[BlackKing]\[BlackQueen]\[BlackRook]\[BlackBishop]\
\[BlackKnight]\[BlackPawn]"}
]
/. n_String /; DigitQ[n] :>
Splice@ConstantArray["", ToExpression[n]],
Table[If[EvenQ[i + j], LightGray, Gray], {i, 8}, {j, 8}]
},
2
],
Frame -> True, ItemSize -> All
]