diff options
Diffstat (limited to 'DotnetPgn/PieceParser.cs')
-rw-r--r-- | DotnetPgn/PieceParser.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/DotnetPgn/PieceParser.cs b/DotnetPgn/PieceParser.cs new file mode 100644 index 0000000..5ea9402 --- /dev/null +++ b/DotnetPgn/PieceParser.cs @@ -0,0 +1,22 @@ +using System;
+using DotnetPgn.Models;
+
+namespace DotnetPgn
+{
+ public static class PieceParser
+ {
+ public static Piece ParsePiece(string sanPiece)
+ {
+ return sanPiece switch
+ {
+ "P" or "p" or "" => Piece.Pawn,
+ "N" or "n" => Piece.Knight,
+ "B" or "b" => Piece.Bishop,
+ "R" or "r" => Piece.Rook,
+ "Q" or "q" => Piece.Queen,
+ "K" or "k" => Piece.King,
+ _ => throw new ArgumentException($"'{sanPiece} is not a valid piece.'"),
+ };
+ }
+ }
+}
|