src/Engine/Utilities/ChessFormatter.cs
/// <summary>
/// Converts a chess piece into a string representation.
/// </summary>
/// <param name="piece">The piece to convert to a string.</param>
/// <param name="fenStyle">True to use lower-case characters for black pieces.</param>
/// <param name="pForPawn">True to use 'P' for pawns, otherwise pawns convert to empty strings.</param>
/// <returns>A string representation of the chess piece.</returns>
Converts a chess piece into a string representation.
Converts a chess piece into a string representation .
public static string PieceToString(ChessPieces piece, bool fenStyle = false, bool pForPawn = false)
        {
            var ret = piece switch
            {
                ChessPieces.WhiteKing => "K",
                ChessPieces.BlackKing => "k",
                ChessPieces.WhiteQueen => "Q",
                ChessPieces.BlackQueen => "q",
                ChessPieces.WhiteRook => "R",
                ChessPieces.BlackRook => "r",
                ChessPieces.WhiteBishop => "B",
                ChessPieces.BlackBishop => "b",
                ChessPieces.WhiteKnight => "N",
                ChessPieces.BlackKnight => "n",
                ChessPieces.WhitePawn => pForPawn ? "P" : string.Empty,
                ChessPieces.BlackPawn => pForPawn ? "p" : string.Empty,
                _ => "\uFFFD",
            };
            if (!fenStyle)
            {
                ret = ret.ToUpperInvariant();
            }
            return ret;
        }
public static string PieceToString ( ChessPieces piece , bool fenStyle = false , bool pForPawn = false ) { var ret = piece switch { ChessPieces . WhiteKing => " " , ChessPieces . BlackKing => " " , ChessPieces . WhiteQueen => " " , ChessPieces . BlackQueen => " " , ChessPieces . WhiteRook => " " , ChessPieces . BlackRook => " " , ChessPieces . WhiteBishop => " " , ChessPieces . BlackBishop => " " , ChessPieces . WhiteKnight => " " , ChessPieces . BlackKnight => " " , ChessPieces . WhitePawn => pForPawn ? " " : string . Empty , ChessPieces . BlackPawn => pForPawn ? " " : string . Empty , _ => " \uFFFD " , } ; if ( ! fenStyle ) { ret = ret . ToUpperInvariant ( ) ; } return ret ; }
Converts a chess piece into a string representation.
Converts a chess piece into a string representation .
A string representation of the chess piece.
A string representation of the chess piece .
piece
ChessPieces
The piece to convert to a string.
The piece to convert to a string .
fenStyle
bool
True to use lower-case characters for black pieces.
True to use lower - case characters for black pieces .
pForPawn
bool
True to use 'P' for pawns, otherwise pawns convert to empty strings.
True to use ' P ' for pawns otherwise pawns convert to empty strings .