Example #1
0
        private static string ToRan(Move move, IPosition pos)
        {
            var from = move.GetFromSquare();
            var to   = move.GetToSquare();

            var notation = new StringBuilder(12);

            if (move.IsCastlelingMove())
            {
                notation.Append(ECastlelingExtensions.GetCastlelingString(to, from));
            }
            else
            {
                var pt = move.GetMovingPieceType();

                if (pt != EPieceType.Pawn)
                {
                    notation.Append(pt.GetPieceChar());
                }

                notation.Append(from.ToString());

                if (move.IsEnPassantMove())
                {
                    notation.Append("ep");
                    notation.Append(from.FileChar());
                }
                else if (move.IsCaptureMove())
                {
                    if (pt == EPieceType.Pawn)
                    {
                        notation.Append(from.FileChar());
                    }

                    notation.Append('x');
                    notation.Append(move.GetCapturedPiece().Type().GetPieceChar());
                }
                else
                {
                    notation.Append('-');
                }

                notation.Append(to.ToString());

                if (move.IsPromotionMove())
                {
                    notation.Append('=');
                    notation.Append(move.GetPromotedPiece().GetUnicodeChar());
                }
            }

            if (pos.InCheck)
            {
                notation.Append(pos.GetCheckChar());
            }

            return(notation.ToString());
        }
Example #2
0
        private static string ToSan(this Move move, MoveGenerator moveGenerator)
        {
            var from = move.GetFromSquare();
            var to   = move.GetToSquare();

            var notation = new StringBuilder(12);

            if (move.IsCastlelingMove())
            {
                notation.Append(ECastlelingExtensions.GetCastlelingString(to, from));
            }
            else
            {
                var pt = move.GetMovingPieceType();

                if (pt != EPieceType.Pawn)
                {
                    notation.Append(move.GetMovingPiece().GetPgnChar());
                    move.Disambiguation(from, moveGenerator.Position, notation);
                }

                if (move.IsEnPassantMove())
                {
                    notation.Append("ep");
                    notation.Append(from.FileChar());
                }
                else if (move.IsCaptureMove())
                {
                    if (pt == EPieceType.Pawn)
                    {
                        notation.Append(from.FileChar());
                    }

                    notation.Append('x');
                }

                notation.Append(to.ToString());

                if (move.IsPromotionMove())
                {
                    notation.Append('=');
                    notation.Append(move.GetPromotedPiece().GetPgnChar());
                }
            }

            if (moveGenerator.InCheck)
            {
                notation.Append(moveGenerator.GetCheckChar());
            }

            return(notation.ToString());
        }