Exemple #1
0
        static Zero()
        {
            // Initialize piece values. The king's value is only used for static
            // exchange evaluation.
            PieceValue[Piece.King]   = 3000;
            PieceValue[Piece.Queen]  = 1025;
            PieceValue[Piece.Rook]   = 575;
            PieceValue[Piece.Bishop] = 370;
            PieceValue[Piece.Knight] = 350;
            PieceValue[Piece.Pawn]   = 100;
            for (Int32 piece = Piece.Min; piece <= Piece.Max; piece += 2)
            {
                PieceValue[Colour.Black | piece] = PieceValue[piece];
            }
            PieceValue[Piece.Empty] = 0;

            PhaseCoefficient += PieceValue[Piece.Queen];
            PhaseCoefficient += 2 * PieceValue[Piece.Rook];
            PhaseCoefficient += 2 * PieceValue[Piece.Bishop];
            PhaseCoefficient += 2 * PieceValue[Piece.Knight];
            PhaseCoefficient += 8 * PieceValue[Piece.Pawn];
            PhaseCoefficient  = 1 / PhaseCoefficient;

            for (Int32 square = 0; square < 64; square++)
            {
                // Initialize piece square tables.
                Int32 reflected = Position.File(square) + (7 - Position.Rank(square)) * 8;
                KingOpeningPositionValue[Colour.Black][square]       = KingOpeningPositionValue[Colour.White][reflected];
                KingEndgamePositionValue[Colour.Black][square]       = KingEndgamePositionValue[Colour.White][reflected];
                QueenOpeningPositionValue[Colour.Black][square]      = QueenOpeningPositionValue[Colour.White][reflected];
                RookPositionValue[Colour.Black][square]              = RookPositionValue[Colour.White][reflected];
                BishopPositionValue[Colour.Black][square]            = BishopPositionValue[Colour.White][reflected];
                KnightOpeningPositionValue[Colour.Black][square]     = KnightOpeningPositionValue[Colour.White][reflected];
                PawnPositionValue[Colour.Black][square]              = PawnPositionValue[Colour.White][reflected];
                PassedPawnEndgamePositionValue[Colour.Black][square] = PassedPawnEndgamePositionValue[Colour.White][reflected];

                // Initialize pawn shield bitboard table.
                PawnShieldBitboard[square] = Bit.File[square];
                if (Position.File(square) > 0)
                {
                    PawnShieldBitboard[square] |= Bit.File[square - 1];
                }
                if (Position.File(square) < 7)
                {
                    PawnShieldBitboard[square] |= Bit.File[square + 1];
                }
                PawnShieldBitboard[square] &= Bit.FloodFill(square, 2);

                // Initialize short adjacent files bitboard table.
                if (Position.File(square) > 0)
                {
                    ShortAdjacentFilesBitboard[square] |= Bit.File[square - 1] & Bit.FloodFill(square - 1, 3);
                }
                if (Position.File(square) < 7)
                {
                    ShortAdjacentFilesBitboard[square] |= Bit.File[square + 1] & Bit.FloodFill(square + 1, 3);
                }

                // Initialize pawn blockade bitboard table.
                PawnBlockadeBitboard[Colour.White][square] = Bit.RayN[square];
                if (Position.File(square) > 0)
                {
                    PawnBlockadeBitboard[Colour.White][square] |= Bit.RayN[square - 1];
                }
                if (Position.File(square) < 7)
                {
                    PawnBlockadeBitboard[Colour.White][square] |= Bit.RayN[square + 1];
                }
                PawnBlockadeBitboard[Colour.Black][square] = Bit.RayS[square];
                if (Position.File(square) > 0)
                {
                    PawnBlockadeBitboard[Colour.Black][square] |= Bit.RayS[square - 1];
                }
                if (Position.File(square) < 7)
                {
                    PawnBlockadeBitboard[Colour.Black][square] |= Bit.RayS[square + 1];
                }

                // Initialize short forward file bitboard table.
                ShortForwardFileBitboard[Colour.White][square] = Bit.RayN[square] & Bit.FloodFill(square, 3);
                ShortForwardFileBitboard[Colour.Black][square] = Bit.RayS[square] & Bit.FloodFill(square, 3);

                // Initialize rectilinear distance table.
                RectilinearDistance[square] = new Int32[64];
                for (Int32 to = 0; to < 64; to++)
                {
                    RectilinearDistance[square][to] = Math.Abs(Position.File(square) - Position.File(to)) + Math.Abs(Position.Rank(square) - Position.Rank(to));
                }

                // Initialize chebyshev distance table.
                ChebyshevDistance[square] = new Int32[64];
                for (Int32 to = 0; to < 64; to++)
                {
                    ChebyshevDistance[square][to] = Math.Max(Math.Abs(Position.File(square) - Position.File(to)), Math.Abs(Position.Rank(square) - Position.Rank(to)));
                }

                // Initialize knight move distance table.
                KnightMoveDistance[square] = new Int32[64];
                for (Int32 i = 0; i < KnightMoveDistance[square].Length; i++)
                {
                    KnightMoveDistance[square][i] = 6;
                }
                for (Int32 moves = 1; moves <= 5; moves++)
                {
                    UInt64 moveBitboard = Attack.KnightFill(square, moves);
                    for (Int32 to = 0; to < 64; to++)
                    {
                        if ((moveBitboard & (1UL << to)) != 0 && moves < KnightMoveDistance[square][to])
                        {
                            KnightMoveDistance[square][to] = moves;
                        }
                    }
                }
            }
        }