示例#1
0
        /// <summary>
        ///     Decrements or increments the parameter score, in regard to the pieces position on the board.
        ///     Method should be used for pawns.
        /// </summary>
        private static void AddPawnScores(Board.Board board, int colour,
                                          ref int score)
        {
            var pceType = colour == (int)Colour.WHITE ? (int)Piece.wP : (int)Piece.bP;

            for (var i = 0; i < board.PceNum[pceType]; ++i)
            {
                var sq = board.PList[pceType, i];
                Debug.Assert(Validators.SqOnBoard(sq));
                var sq64  = Conversion.getSq120ToSq64(sq);
                var value = colour == (int)Colour.WHITE
                    ? Evaluate.pawnTable[sq64]
                    : -Evaluate.pawnTable[Data.mirror64Table[sq64]];

                score += value;

                // If pawn we need to consider whether it's isolated and on what rank.
                if (colour == (int)Colour.WHITE)
                {
                    if ((EvalBitMask.GetIsolatedMask(sq64) & board.Pawns[(int)Colour.WHITE]) ==
                        0)
                    {
                        score += Evaluate.PAWN_ISOLATED_VAL;
                    }

                    if ((EvalBitMask.GetWhitePassedMask(sq64) &
                         board.Pawns[(int)Colour.BLACK]) == 0)
                    {
                        var rank = Conversion.getRanksBrd(sq);
                        Debug.Assert(Validators.FileOrRankValid(rank));
                        score += Evaluate.PAWN_PASSED_VAL[rank];
                    }
                }
                else
                {
                    if ((EvalBitMask.GetIsolatedMask(sq64) & board.Pawns[(int)Colour.BLACK]) ==
                        0)
                    {
                        score -= Evaluate.PAWN_ISOLATED_VAL;
                    }

                    if ((EvalBitMask.GetBlackPassedMask(sq64) &
                         board.Pawns[(int)Colour.WHITE]) == 0)
                    {
                        var rank = Conversion.getRanksBrd(sq);
                        Debug.Assert(Validators.FileOrRankValid(rank));
                        score -= Evaluate.PAWN_PASSED_VAL[7 - rank];
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Decrements or increments the parameter score, in regard to the pieces position on the board.
        ///     Method should be used for queens and rooks.
        /// </summary>
        private static void AddRookOrQueenScores(Board.Board board, int pceType, ref int score)
        {
            Debug.Assert(Data.IsPieceRookQueen(pceType));
            var colour = (int)Data.PIECE_COLOURS[pceType];

            for (var i = 0; i < board.PceNum[pceType]; ++i)
            {
                var sq = board.PList[pceType, i];
                Debug.Assert(Validators.SqOnBoard(sq));
                var sq64  = Conversion.getSq120ToSq64(sq);
                var value = colour == (int)Colour.WHITE
                    ? Evaluate.pawnTable[sq64]
                    : -Evaluate.pawnTable[Data.mirror64Table[sq64]];

                score += value;

                var file      = Conversion.getFilesBrd(sq);
                var fileValue = 0;
                if ((EvalBitMask.GetFilesMask(file) & board.Pawns[(int)Colour.BOTH]) == 0)
                {
                    // Is piece Rook
                    if (!Data.IsPieceBishopQueen(pceType) && Data.IsPieceRookQueen(pceType))
                    {
                        fileValue = Evaluate.ROOK_OPEN_FILE_VAL;
                    }
                    else
                    {
                        // Else piece is queen
                        fileValue = Evaluate.QUEEN_OPEN_FILE_VAL;
                    }
                }
                else if ((EvalBitMask.GetFilesMask(file) & board.Pawns[colour]) == 0)
                {
                    if (!Data.IsPieceBishopQueen(pceType) && Data.IsPieceRookQueen(pceType))
                    {
                        fileValue = Evaluate.ROOK_SEMI_OPEN_FILE_VAL;
                    }
                    else
                    {
                        // Piece is queen
                        fileValue = Evaluate.QUEEN_SEMI_OPEN_FILE_VAL;
                    }
                }

                fileValue = colour == (int)Colour.WHITE ? fileValue : -fileValue;
                score    += fileValue;
            }
        }