コード例 #1
0
        public static string ExtractDisambiguationRank(string moveText)
        {
            if (PgnMoveTextParser.ExtractMoveTypeFromMove(moveText) == MoveType.GameEnd)
            {
                return("");
            }

            char[] filterForText = moveText.Where(char.IsLetterOrDigit).ToArray();
            char[] withoutSquare = filterForText.Take(filterForText.Length - 2).Where(x => x != 'x' && (char.IsLower(x) || char.IsDigit(x))).ToArray();
            char   letter        = withoutSquare.Where(char.IsDigit).FirstOrDefault();

            if (letter != default(char))
            {
                return(letter.ToString());
            }

            return("");
        }
コード例 #2
0
        public PgnTurnMove(string moveText, Color color)
        {
            Result = PlayResult.InProgress;

            var endPosition = PgnMoveTextParser.ExtractSquareFromMove(moveText, color);

            Color    = color;
            MoveType = PgnMoveTextParser.ExtractMoveTypeFromMove(moveText);

            if (MoveType == MoveType.GameEnd)
            {
                Result = PgnMoveTextParser.ExtractGameEndingResultFromMove(moveText);
                return;
            }

            if (MoveType == MoveType.Castling)
            {
                // HANDLE CASTLING
                Piece        = Piece.King;
                CastlingInfo = new PgnTurnMoveCastle(endPosition);
            }

            Piece       = PieceParser.Parse(moveText.Substring(0, 1));
            EndPosition = endPosition;
            PieceTaken  = moveText.Contains("x");

            if (moveText.Contains("+"))
            {
                Result = PlayResult.Check;
            }

            if (moveText.Contains("="))
            {
                MoveType      = MoveType.Promotion;
                PromotionInfo = new PgnTurnMovePromotion(moveText);
            }

            DisambiguationFile = ExtractDisambiguationFile(moveText);
            DisambiguationRank = ExtractDisambiguationRank(moveText);
        }