コード例 #1
0
ファイル: Stringify.cs プロジェクト: mdelgert/absolute-zero
        /// <summary>
        /// Returns the text representation of the given move in coordinate notation.
        /// </summary>
        /// <param name="move">The move to identify.</param>
        /// <returns>The text representation of the given move in coordinate notation.</returns>
        public static String Move(Int32 move)
        {
            String coordinates = Stringify.Square(MoveClass.From(move)) + Stringify.Square(MoveClass.To(move));
            Int32  special     = MoveClass.Special(move);

            switch (special & PieceClass.Mask)
            {
            default:
                return(coordinates);

            case PieceClass.Queen:
            case PieceClass.Rook:
            case PieceClass.Bishop:
            case PieceClass.Knight:
                return(coordinates + PieceInitial(special).ToLowerInvariant());
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns the FEN string that describes the position.
        /// </summary>
        /// <returns>The FEN string that describes the position.</returns>
        public String GetFEN()
        {
            StringBuilder sb = new StringBuilder();

            for (Int32 rank = 0; rank < 8; rank++)
            {
                Int32 spaces = 0;
                for (Int32 file = 0; file < 8; file++)
                {
                    Int32 square = file + rank * 8;
                    if (Square[square] == Piece.Empty)
                    {
                        spaces++;
                    }
                    else
                    {
                        if (spaces > 0)
                        {
                            sb.Append(spaces);
                            spaces = 0;
                        }
                        String piece = Stringify.PieceInitial(Square[square]);
                        if ((Square[square] & Colour.Mask) == Colour.Black)
                        {
                            piece = piece.ToLowerInvariant();
                        }
                        sb.Append(piece);
                    }
                }
                if (spaces > 0)
                {
                    sb.Append(spaces);
                }
                if (rank < 7)
                {
                    sb.Append('/');
                }
            }

            sb.Append(' ');
            sb.Append(SideToMove == Colour.White ? 'w' : 'b');
            sb.Append(' ');

            if (CastleKingside[Colour.White] > 0)
            {
                sb.Append('K');
            }
            if (CastleQueenside[Colour.White] > 0)
            {
                sb.Append('Q');
            }
            if (CastleKingside[Colour.Black] > 0)
            {
                sb.Append('k');
            }
            if (CastleQueenside[Colour.Black] > 0)
            {
                sb.Append('q');
            }
            if (sb[sb.Length - 1] == ' ')
            {
                sb.Append('-');
            }
            sb.Append(' ');

            if (EnPassantSquare != InvalidSquare)
            {
                sb.Append(Stringify.Square(EnPassantSquare));
            }
            else
            {
                sb.Append('-');
            }
            sb.Append(' ');

            sb.Append(FiftyMovesClock);
            sb.Append(' ');
            sb.Append(HalfMoves / 2 + 1);

            return(sb.ToString());
        }