Exemple #1
0
 private void CountPieces()
 {
     for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
     {
         Bitboard occupy = Occupies[(byte)color];
         for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
         {
             Bitboard piece = Pieces[(byte)type];
             PieceCount[(byte)color, (byte)type] = BitBoard.CountSets(occupy & piece);
         }
     }
 }
Exemple #2
0
        public void MovePiece(SquareE origin, SquareE destiny, PieceE promote)
        {
            Debug.Assert(IsLegal());

            Piece movePiece = PickPiece(origin);

            if (movePiece.Color == OnMove)
            {
                RemovePiece(movePiece, origin);

                Piece capturePiece = PickPiece(destiny);
                if (capturePiece.Type != PieceE.NoPiece)
                {
                    RemovePiece(capturePiece, destiny);
                }

                PutPiece(movePiece, destiny);
            }
        }
Exemple #3
0
        private void ClearBitboards()
        {
            for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
            {
                Occupies[(byte)color] = BitBoard.EmptySquares;
            }

            for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
            {
                Pieces[(byte)type] = BitBoard.EmptySquares;
            }

            for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
            {
                for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
                {
                    PieceCount[(byte)color, (byte)type] = 0;
                }
            }
        }
Exemple #4
0
        public Piece PickPiece(SquareE sqr)
        {
            Piece p = new Piece();

            //bool isPiece = false;
            for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
            {
                Bitboard occupy = Occupies[(byte)color];
                if (BitBoard.GetSquare(occupy, sqr))
                {
                    for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
                    {
                        Bitboard piece = Pieces[(byte)type];
                        if (BitBoard.GetSquare(piece, sqr))  // occupy & piece
                        {
                            //Debug.Assert(!isPiece, "Piece Overlaps");
                            //isPiece = true;
                            return(new Piece(color, type));
                        }
                    }
                }
            }
            return(p);
        }
Exemple #5
0
        private void ClearSquare(SquareE square)
        {
            //bool isPiece = false;
            for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
            {
                Bitboard occupy = Occupies[(byte)color];
                if (BitBoard.GetSquare(occupy, square))
                {
                    for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
                    {
                        Bitboard piece = Pieces[(byte)type];
                        if (BitBoard.GetSquare(piece, square))  // occupy & piece
                        {
                            BitBoard.RstSquare(ref Occupies[(byte)color], square);
                            BitBoard.RstSquare(ref Pieces[(byte)type], square);
                            break;

                            //Debug.Assert(!isPiece, "Piece Overlaps");
                            //isPiece = true;
                        }
                    }
                }
            }
        }
Exemple #6
0
 //*********************************************************     
 //
 /// <summary>
 /// Get the number of the specified piece which has been eated
 /// </summary>
 /// <param name="ePiece">   Piece and color</param>
 /// <returns>
 /// Count
 /// </returns>
 //  
 //*********************************************************     
 public int GetEatedPieceCount(PieceE ePiece) {
     int     iRetVal;
     
     switch(ePiece & PieceE.PieceMask) {
     case PieceE.Pawn:
         iRetVal = 8 - m_piPiecesCount[(int)ePiece];
         break;
     case PieceE.Rook:
     case PieceE.Knight:
     case PieceE.Bishop:
         iRetVal = 2 - m_piPiecesCount[(int)ePiece];
         break;
     case PieceE.Queen:
     case PieceE.King:
         iRetVal = 1 - m_piPiecesCount[(int)ePiece];
         break;
     default:
         iRetVal = 0;
         break;
     }
     if (iRetVal < 0) {
         iRetVal = 0;
     }
     return(iRetVal);                
 }
Exemple #7
0
 //*********************************************************     
 //
 /// <summary>
 /// Update the packed board representation and the value of the hash key representing the current board state. Use if two
 /// board positions are changed.
 /// </summary>
 /// <param name="iPos1">        Position of the change</param>
 /// <param name="eNewPiece1">   New piece</param>
 /// <param name="iPos2">        Position of the change</param>
 /// <param name="eNewPiece2">   New piece</param>
 //  
 //*********************************************************     
 private void UpdatePackedBoardAndZobristKey(int iPos1, PieceE eNewPiece1, int iPos2, PieceE eNewPiece2) {
     m_i64ZobristKey = ZobristKey.UpdateZobristKey(m_i64ZobristKey, iPos1, m_pBoard[iPos1], eNewPiece1, iPos2, m_pBoard[iPos2], eNewPiece2);
     m_moveHistory.UpdateCurrentPackedBoard(iPos1, eNewPiece1);
     m_moveHistory.UpdateCurrentPackedBoard(iPos2, eNewPiece2);
 }
Exemple #8
0
 //*********************************************************     
 //
 /// <summary>
 /// Enumerates the attacking position using an array of possible position and one possible enemy piece
 /// </summary>
 /// <param name="arrAttackPos">     Array to fill with the attacking position. Can be null if only the count is wanted</param>
 /// <param name="piCaseMoveList">   Array of position.</param>
 /// <param name="ePiece">           Piece which can possibly attack this position</param>
 /// <returns>
 /// Count of attacker
 /// </returns>
 //  
 //*********************************************************     
 private int EnumTheseAttackPos(List<byte> arrAttackPos, int[] piCaseMoveList, PieceE ePiece) {
     int     iRetVal = 0;
     
     foreach (int iNewPos in piCaseMoveList) {
         if (m_pBoard[iNewPos] == ePiece) {
             iRetVal++;
             if (arrAttackPos != null) {
                 arrAttackPos.Add((byte)iNewPos);
             }
         }
     }
     return(iRetVal);
 }
Exemple #9
0
 //*********************************************************     
 //
 /// <summary>
 /// Enumerates the attacking position using arrays of possible position and two possible enemy pieces
 /// </summary>
 /// <param name="arrAttackPos">     Array to fill with the attacking position. Can be null if only the count is wanted</param>
 /// <param name="ppiCaseMoveList">  Array of array of position.</param>
 /// <param name="ePiece1">          Piece which can possibly attack this position</param>
 /// <param name="ePiece2">          Piece which can possibly attack this position</param>
 /// <returns>
 /// Count of attacker
 /// </returns>
 //  
 //*********************************************************     
 private int EnumTheseAttackPos(List<byte> arrAttackPos, int[][] ppiCaseMoveList, PieceE ePiece1, PieceE ePiece2) {
     int     iRetVal = 0;
     PieceE  ePiece;
     
     foreach (int[] piMoveList in ppiCaseMoveList) {
         foreach (int iNewPos in piMoveList) {
             ePiece = m_pBoard[iNewPos];
             if (ePiece != PieceE.None) {
                 if (ePiece == ePiece1 ||
                     ePiece == ePiece2) {
                     iRetVal++;
                     if (arrAttackPos != null) {
                         arrAttackPos.Add((byte)iNewPos);
                     }
                 }
                 break;
             }                    
         }
     }
     return(iRetVal);
 }
Exemple #10
0
        internal static string ToString(Board board)
        {
            if (board == default(Board))
            {
                Debug.Assert(false, "Null or Empty FEN");
                return(string.Empty);
            }

            StringBuilder fenString = new StringBuilder();

            #region Pieces
            for (RankE rank = RankE.Rank_8; ; --rank)
            {
                byte emptySqr = 0;
                for (FileE file = FileE.File_A; file <= FileE.File_H; ++file)
                {
                    bool isPiece = false;
                    for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
                    {
                        Bitboard occupy = board.Occupies[(byte)color];
                        SquareE  sqr    = Square._Square(file, rank);
                        if (BitBoard.GetSquare(occupy, sqr))
                        {
                            for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
                            {
                                Bitboard piece = board.Pieces[(byte)type];
                                if (BitBoard.GetSquare(piece, sqr))  // occupy & piece
                                {
                                    isPiece = true;
                                    if (emptySqr > 0)
                                    {
                                        fenString.Append(emptySqr);
                                        emptySqr = 0;
                                    }
                                    fenString.Append(Piece.mapPiece[(byte)color, (byte)type]);
                                    break;
                                }
                            }
                        }
                    }
                    if (!isPiece)
                    {
                        ++emptySqr;
                    }
                }
                if (emptySqr > 0)
                {
                    fenString.Append(emptySqr);
                    emptySqr = 0;
                }

                if (rank == RankE.Rank_1)
                {
                    break;
                }

                fenString.Append(rankSep);
            }
            #endregion

            fenString.Append(recordSep);

            #region OnMove
            switch (board.OnMove)
            {
            case ColorE.White: fenString.Append('w'); break;

            case ColorE.Black: fenString.Append('b'); break;

            case ColorE.NoColor:
            default: fenString.Append('-'); break;
            }
            #endregion

            fenString.Append(recordSep);

            #region Castle
            if (board.Castle[(byte)ColorE.White].AnyCastle ||
                board.Castle[(byte)ColorE.Black].AnyCastle)
            {
                if (board.Castle[(byte)ColorE.White].ShortCastle)
                {
                    fenString.Append('K');
                }
                if (board.Castle[(byte)ColorE.White].LongCastle)
                {
                    fenString.Append('Q');
                }
                if (board.Castle[(byte)ColorE.Black].ShortCastle)
                {
                    fenString.Append('k');
                }
                if (board.Castle[(byte)ColorE.Black].LongCastle)
                {
                    fenString.Append('q');
                }
            }
            else
            {
                fenString.Append('-');
            }
            #endregion

            fenString.Append(recordSep);

            #region EnPassant

            SquareE ep = board.EnPassant;
            if (Square.IsValid(ep))
            {
                fenString.Append(ep.ToString().ToLower());
            }
            else
            {
                fenString.Append('-');
            }
            #endregion

            fenString.Append(recordSep);

            #region HalfMove Clock

            fenString.Append(board.HalfMoveClock);
            #endregion

            fenString.Append(recordSep);

            #region FullMove Counter

            fenString.Append(board.FullMoveCount);
            #endregion

            return(fenString.ToString());
        }
Exemple #11
0
        /// Split Method
        internal static Board ToBoard(string fenString)
        {
            const Board emptyBoard = default(Board);

            if (string.IsNullOrEmpty(fenString))
            {
                return(emptyBoard);
            }

            string[] records   = fenString.Split(new char[] { recordSep }, StringSplitOptions.RemoveEmptyEntries);
            int      numRecord = records.Length;
            // --- full fenString check
            //if( numRecord != 6 ) return emptyBoard;

            Board board = new Board();

            #region Piece placement

            string[] ranks = records[0].Split(rankSep);

            if (ranks.Length != Rank.Ranks)
            {
                return(emptyBoard);
            }

            byte baseSqr = (byte)SquareE.A8;
            foreach (string rank in ranks)
            {
                byte offsetFile = 0;
                foreach (char achar in rank)
                {
                    if (achar >= '1' && achar <= '8')
                    {
                        offsetFile += (byte)(achar - '0');
                    }
                    else
                    {
                        Piece piece = Piece.Parse(achar);

                        if (piece != default(Piece))
                        {// there is a piece
                            ColorE color = piece.Color;
                            PieceE type  = piece.Type;

                            if (color != ColorE.NoColor && type != PieceE.NoPiece)
                            {
                                if (offsetFile >= File.Files)
                                {
                                    return(emptyBoard);
                                }

                                SquareE sqr = (SquareE)(baseSqr + offsetFile);

                                switch (type)
                                {
                                case PieceE.Pawn:
                                    RankE pawnRank = Square._Rank(sqr);
                                    if (pawnRank == RankE.Rank_1 || pawnRank == RankE.Rank_8)
                                    {
                                        return(emptyBoard);
                                    }
                                    if (board.PieceCount[(byte)color, (byte)type] >= 8)
                                    {
                                        return(emptyBoard);
                                    }
                                    break;

                                case PieceE.King:
                                    if (board.PieceCount[(byte)color, (byte)type] >= 1)
                                    {
                                        return(emptyBoard);
                                    }
                                    break;

                                case PieceE.Knight:
                                case PieceE.Bishop:
                                case PieceE.Rook:
                                case PieceE.Queen:
                                    if (board.PieceCount[(byte)color, (byte)PieceE.Pawn] +
                                        board.PieceCount[(byte)color, (byte)PieceE.Knight] +
                                        board.PieceCount[(byte)color, (byte)PieceE.Bishop] +
                                        board.PieceCount[(byte)color, (byte)PieceE.Rook] +
                                        board.PieceCount[(byte)color, (byte)PieceE.Queen]
                                        >= 15)
                                    {
                                        return(emptyBoard);
                                    }
                                    break;
                                }

                                board.PutPiece(piece, sqr);   // put the piece on board
                            }
                        }
                        else
                        {
                            return(emptyBoard);
                        }

                        ++offsetFile;
                    }
                }

                if (offsetFile == 0)  // Allow null lines = /8/
                {
                    offsetFile = File.Files;
                }

                if (offsetFile != File.Files)
                {
                    return(emptyBoard);
                }

                baseSqr -= File.Files;
            }

            for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
            {
                Bitboard occupy = board.Occupies[(byte)color];
                // check too many total pieces
                if (BitBoard.CountSets(occupy) > 16)
                {
                    return(emptyBoard);
                }

                // check if the number of Pawns plus the number of extra Queens, Rooks, Bishops, Knights
                // (which can result only by promotion) exceeds 8

                // check too many color pieces
                if (board.PieceCount[(byte)color, (byte)PieceE.Pawn] +
                    Math.Max(board.PieceCount[(byte)color, (byte)PieceE.Knight] - 2, 0) +
                    Math.Max(board.PieceCount[(byte)color, (byte)PieceE.Bishop] - 2, 0) +
                    Math.Max(board.PieceCount[(byte)color, (byte)PieceE.Rook] - 2, 0) +
                    Math.Max(board.PieceCount[(byte)color, (byte)PieceE.Queen] - 1, 0)
                    > 8)
                {
                    return(emptyBoard);
                }

                if (board.PieceCount[(byte)color, (byte)PieceE.Bishop] > 1)
                {
                    Bitboard bishops = occupy & board.Pieces[(byte)PieceE.Bishop];

                    byte[] bishopCount = new byte[Color.Colors];

                    //SquareE[] square = BitBoard.GetSquares(occupy & board.Pieces[ (byte) PieceE.Bishop ]);
                    //foreach( SquareE sqr in square )
                    //    ++bishopCount[ (byte) Square._Color(sqr) ];

                    bishopCount[(byte)ColorE.White] = BitBoard.CountSets(BitBoard.LightSquares & bishops);
                    bishopCount[(byte)ColorE.Black] = BitBoard.CountSets(BitBoard.DarkSquares & bishops);

                    if (board.PieceCount[(byte)color, (byte)PieceE.Pawn] +
                        Math.Max(bishopCount[(byte)ColorE.White] - 1, 0) +
                        Math.Max(bishopCount[(byte)ColorE.Black] - 1, 0)
                        > 8)
                    {
                        return(emptyBoard);
                    }
                }

                // check for King
                byte king = board.PieceCount[(byte)color, (byte)PieceE.King];
                if (king != 1)  //Illegal King
                {
                    return(emptyBoard);
                }
            }
            #endregion

            if (numRecord > 1)
            {
                #region Active color

                string aColor = records[1];
                if (string.IsNullOrEmpty(aColor) || aColor.Length != 1)
                {
                    return(emptyBoard);
                }

                char activeColor = char.ToLower(aColor[0]);
                if (activeColor == 'w')
                {
                    board.OnMove = ColorE.White;
                }
                else if (activeColor == 'b')
                {
                    board.OnMove = ColorE.Black;
                }
                else
                {
                    board.OnMove = ColorE.NoColor;
                    return(emptyBoard);
                }
                #endregion
            }

            if (numRecord > 2)
            {
                #region Castling privileges

                string castles = records[2];
                if (string.IsNullOrEmpty(castles))
                {
                    return(emptyBoard);
                }

                if (castles == "-")
                {
                    board.Castle[(byte)ColorE.White].AnyCastle = false;
                    board.Castle[(byte)ColorE.Black].AnyCastle = false;
                }
                else
                {
                    int length = castles.Length;
                    if (length > 4)
                    {
                        return(emptyBoard);
                    }

                    for (byte i = 0; i < length - 1; ++i)
                    {
                        for (byte j = (byte)(i + 1); j < length; ++j)
                        {
                            if (castles[i] == castles[j])
                            {
                                return(emptyBoard);
                            }
                        }
                    }

                    foreach (char castle in castles)
                    {
                        switch (castle)
                        {
                        case 'K':
                        {
                            Bitboard occupy = board.Occupies[(byte)ColorE.White];
                            if (BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.King], SquareE.E1) &&
                                BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.Rook], SquareE.H1))
                            {
                                board.Castle[(byte)ColorE.White].ShortCastle = true;
                            }
                            else
                            {
                                return(emptyBoard);
                            }
                        } break;

                        case 'Q':
                        {
                            Bitboard occupy = board.Occupies[(byte)ColorE.White];
                            if (BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.King], SquareE.E1) &&
                                BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.Rook], SquareE.A1))
                            {
                                board.Castle[(byte)ColorE.White].LongCastle = true;
                            }
                            else
                            {
                                return(emptyBoard);
                            }
                        } break;

                        case 'k':
                        {
                            Bitboard occupy = board.Occupies[(byte)ColorE.Black];
                            if (BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.King], SquareE.E8) &&
                                BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.Rook], SquareE.H8))
                            {
                                board.Castle[(byte)ColorE.Black].ShortCastle = true;
                            }
                            else
                            {
                                return(emptyBoard);
                            }
                        } break;

                        case 'q':
                        {
                            Bitboard occupy = board.Occupies[(byte)ColorE.Black];
                            if (BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.King], SquareE.E8) &&
                                BitBoard.GetSquare(occupy & board.Pieces[(byte)PieceE.Rook], SquareE.A8))
                            {
                                board.Castle[(byte)ColorE.Black].LongCastle = true;
                            }
                            else
                            {
                                return(emptyBoard);
                            }
                        } break;

                        default:
                            return(emptyBoard);
                        }
                    }
                }
                #endregion
            }

            if (numRecord > 3)
            {
                #region EnPassant Target square

                string epSqr = records[3];
                if (string.IsNullOrEmpty(epSqr))
                {
                    return(emptyBoard);
                }

                if (epSqr == "-")
                {
                    board.EnPassant = SquareE.NoSquare;
                }
                else
                {
                    if (epSqr.Length != 2)
                    {
                        return(emptyBoard);
                    }

                    char epFile = char.ToLower(epSqr[0]);
                    if (!(epFile >= 'a' && epFile <= 'h'))
                    {
                        return(emptyBoard);
                    }

                    char epRank = epSqr[1];
                    if (!(epRank == '3' || epRank == '6'))
                    {
                        return(emptyBoard);
                    }

                    if (epRank == '3' &&
                        (
                            board.OnMove != ColorE.Black ||
                            !BitBoard.GetSquare(board.Occupies[(byte)ColorE.White] & board.Pieces[(byte)PieceE.Pawn], Square._Square(epFile, (char)(epRank + 1)))
                        )
                        ||
                        epRank == '6' &&
                        (
                            board.OnMove != ColorE.White ||
                            !BitBoard.GetSquare(board.Occupies[(byte)ColorE.Black] & board.Pieces[(byte)PieceE.Pawn], Square._Square(epFile, (char)(epRank - 1)))
                        )
                        )
                    {
                        return(emptyBoard);
                    }

                    board.EnPassant = Square._Square(epFile, epRank);
                }
                #endregion
            }

            if (numRecord > 4)
            {
                #region HalfMove Clock (Ply)

                byte halfMoveClock;
                if (!byte.TryParse(records[4], out halfMoveClock))
                {
                    return(emptyBoard);
                }

                if (halfMoveClock > 100)
                {
                    return(emptyBoard);
                }

                board.HalfMoveClock = halfMoveClock;
                #endregion
            }

            if (numRecord > 5)
            {
                #region FullMove Counter

                ushort fullMoveCount;
                if (!ushort.TryParse(records[5], out fullMoveCount))
                {
                    return(emptyBoard);
                }

                if (fullMoveCount == 0)
                {
                    fullMoveCount = 1;
                }
                board.FullMoveCount = fullMoveCount;
                #endregion
            }

            return(board);
        }
Exemple #12
0
        //internal virtual ColorE Color { get { return ColorE.NoColor;} }

        internal Piece(ColorE color, PieceE type)
        {
            Color = color;
            Type  = type;
        }
Exemple #13
0
        // TODO::
        //internal Bitboard AttacksTo( Bitboard occupied, SquareE sqr, ColorE side )
        //{
        //    //Bitboard knights, kings, bishopsQueens, rooksQueens;
        //    //knights = pieceBB[ nWhiteKnight ] | pieceBB[ nBlackKnight ];
        //    //kings = pieceBB[ nWhiteKing ] | pieceBB[ nBlackKing ];
        //    //rooksQueens =
        //    //bishopsQueens = pieceBB[ nWhiteQueen ] | pieceBB[ nBlackQueen ];
        //    //rooksQueens |= pieceBB[ nWhiteRook ] | pieceBB[ nBlackRook ];
        //    //bishopsQueens |= pieceBB[ nWhiteBishop ] | pieceBB[ nBlackBishop ];

        //    //return (arrPawnAttacks[ nWhite ][ sqr ] & pieceBB[ nBlackPawn ])
        //    //     | (arrPawnAttacks[ nBlack ][ sqr ] & pieceBB[ nWhitePawn ])
        //    //     | (arrKnightAttacks[ sqr ] & knights)
        //    //     | (arrKingAttacks[ sqr ] & kings)
        //    //     | (bishopAttacks(occupied, sqr) & bishopsQueens)
        //    //     | (rookAttacks(occupied, sqr) & rooksQueens)
        //    //     ;

        //    ColorE oppside = ColorE.NoColor;
        //    if( side == ColorE.White )
        //    {
        //        oppside = ColorE.Black;
        //    }
        //    else if( side == ColorE.Black )
        //    {
        //        oppside = ColorE.White;
        //    }

        //    Bitboard sideOccupied = Occupies[ (byte) side ];

        //    Bitboard rooksQueens = Pieces[ (byte) PieceE.Rook ] | Pieces[ (byte) PieceE.Queen ];
        //    Bitboard bishopsQueens = Pieces[ (byte) PieceE.Bishop ] | Pieces[ (byte) PieceE.Queen ];

        //    return (MoveAttack._PawnAttacks[ (byte) sqr, (byte) side ] & (Pieces[ (byte) PieceE.Pawn ] & Occupies[ (byte) oppside ]))
        //        | (MoveAttack._PawnAttacks[ (byte) sqr, (byte) oppside ] & (Pieces[ (byte) PieceE.Pawn ] & Occupies[ (byte) side ]))
        //        | (MoveAttack._KnightMoves[ (byte) sqr ] & Pieces[ (byte) PieceE.Knight ])
        //        | (MoveAttack._KingMoves[ (byte) sqr ] & Pieces[ (byte) PieceE.King ])
        //        | (MoveAttack._RookMoves[ (byte) sqr ] & rooksQueens)
        //        | (MoveAttack._BishopMoves[ (byte) sqr ] & bishopsQueens);
        //}


        public override string ToString()
        {
            StringBuilder sboard = new StringBuilder();

            sboard.AppendLine(" +-+-+-+-+-+-+-+-+");


            //SquareE begSqr = SquareE.A8;
            //SquareE endSqr = SquareE.H1;
            //for( SquareE sqr = begSqr; ; Square.BackwardInc(ref sqr) )
            //{
            //    if( (byte) sqr % File.Files == 0 )
            //    {
            //        if( sqr != begSqr ) sboard.AppendLine();
            //        sboard.Append(Rank.mapRank[ (byte) sqr / File.Files ]);
            //    }
            //    bool isPiece = false;
            //    sboard.Append(" ");
            //    for( ColorE color = ColorE.White; color <= ColorE.Black; ++color )
            //    {
            //        Bitboard occupy = Occupies[ (byte) color ];
            //        for( PieceE type = PieceE.Pawn; type <= PieceE.King; ++type )
            //        {
            //            Bitboard piece = Pieces[ (byte) type ];
            //            if( BitBoard.GetSquare(occupy & piece, sqr) )
            //            {
            //                //if( isPiece ) sboard.Append('x'); // '*'
            //                isPiece = true;
            //                sboard.Append(Piece.mapPiece[ (byte) color, (byte) type ]);
            //                break;
            //            }
            //        }
            //    }
            //    if( !isPiece )
            //        sboard.Append(".");
            //    if( sqr == endSqr )
            //        break;
            //}


            for (RankE rank = RankE.Rank_8; ; --rank)
            {
                sboard.Append(Rank.mapRank[(byte)rank]);
                for (FileE file = FileE.File_A; file <= FileE.File_H; ++file)
                {
                    bool isPiece = false;
                    sboard.Append(" ");
                    for (ColorE color = ColorE.White; color <= ColorE.Black; ++color)
                    {
                        Bitboard occupy = Occupies[(byte)color];
                        SquareE  sqr    = Square._Square(file, rank);
                        if (BitBoard.GetSquare(occupy, sqr))
                        {
                            for (PieceE type = PieceE.Pawn; type <= PieceE.King; ++type)
                            {
                                Bitboard piece = Pieces[(byte)type];
                                if (BitBoard.GetSquare(piece, sqr))  // occupy & piece
                                {
                                    //if( isPiece ) sboard.Append('x'); // '*'
                                    isPiece = true;
                                    sboard.Append(Piece.mapPiece[(byte)color, (byte)type]);
                                    break;
                                }
                            }
                        }
                    }
                    if (!isPiece)
                    {
                        sboard.Append(".");
                    }
                }
                if (rank == RankE.Rank_1)
                {
                    break;
                }
                sboard.AppendLine();
            }


            sboard.AppendLine().Append(" +-+-+-+-+-+-+-+-+").AppendLine();
            sboard.Append(" ");
            foreach (char file in File.mapFile)
            {
                sboard.Append(" " + file);
            }
            return(sboard.ToString());
        }