src/Engine/Utilities/ChessFormatter.cs
/// <summary>
/// Get a chess piece from a string descrption.
/// </summary>
/// <param name="piece">A string representing a chess piece.</param>
/// <returns>A chess piece.</returns>
/// <remarks>Capital letters are interpreted as white pieces and lower case letters as black pieces (as in FEN notation).</remarks>
Get a chess piece from a string descrption.
Get a chess piece from a string descrption .
public static ChessPieces PieceFromString(string piece)
        {
            return piece switch
            {
                "K" => ChessPieces.WhiteKing,
                "k" => ChessPieces.BlackKing,
                "Q" => ChessPieces.WhiteQueen,
                "q" => ChessPieces.BlackQueen,
                "R" => ChessPieces.WhiteRook,
                "r" => ChessPieces.BlackRook,
                "B" => ChessPieces.WhiteBishop,
                "b" => ChessPieces.BlackBishop,
                "N" => ChessPieces.WhiteKnight,
                "n" => ChessPieces.BlackKnight,
                "P" => ChessPieces.WhitePawn,
                "p" => ChessPieces.BlackPawn,
                _ => throw new ArgumentException("Invalid piece identifier", nameof(piece))
            };
        }
public static ChessPieces PieceFromString ( string piece ) { return piece switch { " " => ChessPieces . WhiteKing , " " => ChessPieces . BlackKing , " " => ChessPieces . WhiteQueen , " " => ChessPieces . BlackQueen , " " => ChessPieces . WhiteRook , " " => ChessPieces . BlackRook , " " => ChessPieces . WhiteBishop , " " => ChessPieces . BlackBishop , " " => ChessPieces . WhiteKnight , " " => ChessPieces . BlackKnight , " " => ChessPieces . WhitePawn , " " => ChessPieces . BlackPawn , _ => throw new ArgumentException ( " " , nameof ( piece ) ) } ; }
Get a chess piece from a string descrption.
Get a chess piece from a string descrption .
A chess piece.
A chess piece .
piece
string
A string representing a chess piece.
A string representing a chess piece .
remarks
Capital letters are interpreted as white pieces and lower case letters as black pieces (as in FEN notation).
Capital letters are interpreted as white pieces and lower case letters as black pieces ( as in FEN notation ) .