From df8253dbf6cb09093018333f99dd9c19ba0ff02b Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Sat, 28 Nov 2020 21:24:40 -0500 Subject: Initial commit `Tokenizer` can _just barely_ parse a basic, well-formed move list. Initially, I wanted to provide the movetext as a `Stream` rather than a string, the idea being that it could be processed as it was being read from a file without having to read the entire file into memory first. I had difficulties with the stream being unreadable in `Tokenizer.ParseMoves()`, so I switched to a string in order to get the actual parsing logic down first. Because of the `yield return` strategy, the debug console output includes all of the expected halfmoves multiple times in various orders. After running a test, generally the full, in-order list seems to exist at the bottom of the output. --- DotnetPgn/PieceParser.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 DotnetPgn/PieceParser.cs (limited to 'DotnetPgn/PieceParser.cs') 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.'"), + }; + } + } +} -- cgit v1.2.3