示例#1
0
        public static void parseHeader(string line, PGN pgn)
        {
            var parsed = parseHeaderFormat(line);

            switch (parsed.key)
            {
            case "Event":
                pgn.Event = parsed.value;
                break;

            case "Date":
                pgn.Date = parsed.value;
                break;

            case "Site":
                pgn.Site = parsed.value;
                break;

            case "FEN":
                pgn.FEN = parsed.value;
                break;

            case "Round":
                pgn.Round = parsed.value;
                break;

            case "White":
                pgn.White = parsed.value;
                break;

            case "Black":
                pgn.Black = parsed.value;
                break;

            case "Result":
                pgn.Result = parsed.value;
                break;

            default:
                break;
            }
        }
示例#2
0
        public static ChessGame parse(string pgnString)
        {
            var       pgn   = new PGN();
            var       lines = pgnString.Split("\n");
            ChessGame game  = null;

            bool headerSection = true;
            var  body          = "";

            foreach (var line in lines)
            {
                if (line.Trim() == "")
                {
                    if (headerSection == false)
                    {
                        return(game);
                    }
                    headerSection = false;
                    game          = ChessGame.ContinueFromFEN(pgn.FEN);
                    game.pgn      = pgn;
                    continue;
                }
                if (headerSection)
                {
                    parseHeader(line, pgn);
                }
                else
                {
                    body += line + "\n";
                }
            }

            parseBody(body, game);


            return(game);
        }