X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=c7549ce29237d41f8586cf9dab8a03fccbdb435e;hp=02ca6d350402d280770970e40fded39022ad5f1e;hb=6b909b2343190f2989d21c8f69f40e9f09c530c0;hpb=5f5d056c8fb9996748b742c9d5102c9202b0bd2c diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 02ca6d35..c7549ce2 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -138,7 +138,7 @@ namespace { {}, {}, { S(0, 0), S( 7, 39), S( 0, 0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT { S(0, 0), S( 7, 39), S(24, 49), S( 0, 0), S(41,100), S(41,100) }, // BISHOP - { S(0, 0), S(-1, 29), S(15, 49), S(15, 49), S( 0, 0), S(24, 49) }, // ROOK + { S(0, 0), S( 0, 22), S(15, 49), S(15, 49), S( 0, 0), S(24, 49) }, // ROOK { S(0, 0), S(15, 39), S(15, 39), S(15, 39), S(15, 39), S( 0, 0) } // QUEEN }; @@ -153,12 +153,16 @@ namespace { // Bonus for having the side to move (modified by Joona Kiiski) const Score Tempo = make_score(24, 11); - // Rooks and queens on the 7th rank (modified by Joona Kiiski) - const Score RookOn7thBonus = make_score(47, 98); - const Score QueenOn7thBonus = make_score(27, 54); + // Rooks and queens on the 7th rank + const Score RookOn7thBonus = make_score(3, 20); + const Score QueenOn7thBonus = make_score(1, 8); + + // Rooks and queens attacking pawns on the same rank + const Score RookOnPawnBonus = make_score(3, 48); + const Score QueenOnPawnBonus = make_score(1, 40); // Rooks on open files (modified by Joona Kiiski) - const Score RookOpenFileBonus = make_score(43, 21); + const Score RookOpenFileBonus = make_score(43, 21); const Score RookHalfOpenFileBonus = make_score(19, 10); // Penalty for rooks trapped inside a friendly king which has lost the @@ -263,8 +267,6 @@ namespace { namespace Eval { - Color RootColor; - /// evaluate() is the main evaluation function. It always computes two /// values, an endgame score and a middle game score, and interpolates /// between them based on the remaining material. @@ -315,7 +317,7 @@ namespace Eval { Value margin; std::string totals; - RootColor = pos.side_to_move(); + Search::RootColor = pos.side_to_move(); TraceStream.str(""); TraceStream << std::showpoint << std::showpos << std::fixed << std::setprecision(2); @@ -435,8 +437,8 @@ Value do_evaluate(const Position& pos, Value& margin) { && sf == SCALE_FACTOR_NORMAL) { // Only the two bishops ? - if ( pos.non_pawn_material(WHITE) == BishopValueMidgame - && pos.non_pawn_material(BLACK) == BishopValueMidgame) + if ( pos.non_pawn_material(WHITE) == BishopValueMg + && pos.non_pawn_material(BLACK) == BishopValueMg) { // Check for KBP vs KB with only a single pawn that is almost // certainly a draw or at least two pawns. @@ -492,7 +494,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // Init king safety tables only if we are going to use them if ( pos.piece_count(Us, QUEEN) - && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame) + && pos.non_pawn_material(Us) >= QueenValueMg + RookValueMg) { ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8)); b &= ei.attackedBy[Us][PAWN]; @@ -582,7 +584,7 @@ Value do_evaluate(const Position& pos, Value& margin) { assert(b); if (!more_than_one(b) && (b & pos.pieces(Them))) - score += ThreatBonus[Piece][type_of(pos.piece_on(first_1(b)))]; + score += ThreatBonus[Piece][type_of(pos.piece_on(lsb(b)))]; } // Decrease score if we are attacked by an enemy pawn. Remaining part @@ -595,12 +597,18 @@ Value do_evaluate(const Position& pos, Value& margin) { && !(pos.pieces(Them, PAWN) & attack_span_mask(Us, s))) score += evaluate_outposts(pos, ei, s); - // Queen or rook on 7th rank - if ( (Piece == ROOK || Piece == QUEEN) - && relative_rank(Us, s) == RANK_7 - && relative_rank(Us, pos.king_square(Them)) == RANK_8) + if ((Piece == ROOK || Piece == QUEEN) && relative_rank(Us, s) >= RANK_5) { - score += (Piece == ROOK ? RookOn7thBonus : QueenOn7thBonus); + // Major piece on 7th rank + if ( relative_rank(Us, s) == RANK_7 + && relative_rank(Us, pos.king_square(Them)) == RANK_8) + score += (Piece == ROOK ? RookOn7thBonus : QueenOn7thBonus); + + // Major piece attacking pawns on the same rank + Bitboard pawns = pos.pieces(Them, PAWN) & rank_bb(s); + if (pawns) + score += (Piece == ROOK ? RookOnPawnBonus + : QueenOnPawnBonus) * popcount(pawns); } // Special extra evaluation for bishops @@ -843,8 +851,8 @@ Value do_evaluate(const Position& pos, Value& margin) { // value that will be used for pruning because this value can sometimes // be very big, and so capturing a single attacking piece can therefore // result in a score change far bigger than the value of the captured piece. - score -= KingDangerTable[Us == Eval::RootColor][attackUnits]; - margins[Us] += mg_value(KingDangerTable[Us == Eval::RootColor][attackUnits]); + score -= KingDangerTable[Us == Search::RootColor][attackUnits]; + margins[Us] += mg_value(KingDangerTable[Us == Search::RootColor][attackUnits]); } if (Trace) @@ -870,7 +878,7 @@ Value do_evaluate(const Position& pos, Value& margin) { return SCORE_ZERO; do { - Square s = pop_1st_bit(&b); + Square s = pop_lsb(&b); assert(pos.pawn_is_passed(Us, s)); @@ -938,7 +946,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // value if the other side has a rook or queen. if (file_of(s) == FILE_A || file_of(s) == FILE_H) { - if (pos.non_pawn_material(Them) <= KnightValueMidgame) + if (pos.non_pawn_material(Them) <= KnightValueMg) ebonus += ebonus / 4; else if (pos.pieces(Them, ROOK, QUEEN)) ebonus -= ebonus / 4; @@ -976,7 +984,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b) { - s = pop_1st_bit(&b); + s = pop_lsb(&b); queeningSquare = relative_square(c, file_of(s) | RANK_8); queeningPath = forward_bb(c, s); @@ -1017,7 +1025,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b) { - s = pop_1st_bit(&b); + s = pop_lsb(&b); // Compute plies from queening queeningSquare = relative_square(loserSide, file_of(s) | RANK_8); @@ -1039,7 +1047,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b) { - s = pop_1st_bit(&b); + s = pop_lsb(&b); sacptg = blockersCount = 0; minKingDist = kingptg = 256; @@ -1058,7 +1066,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // How many plies does it take to remove all the blocking pawns? while (blockers) { - blockSq = pop_1st_bit(&blockers); + blockSq = pop_lsb(&blockers); movesToGo = 256; // Check pawns that can give support to overcome obstacle, for instance @@ -1069,7 +1077,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b2) // This while-loop could be replaced with LSB/MSB (depending on color) { - d = square_distance(blockSq, pop_1st_bit(&b2)) - 2; + d = square_distance(blockSq, pop_lsb(&b2)) - 2; movesToGo = std::min(movesToGo, d); } } @@ -1079,7 +1087,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b2) // This while-loop could be replaced with LSB/MSB (depending on color) { - d = square_distance(blockSq, pop_1st_bit(&b2)) - 2; + d = square_distance(blockSq, pop_lsb(&b2)) - 2; movesToGo = std::min(movesToGo, d); } @@ -1172,7 +1180,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // A couple of little helpers used by tracing code, to_cp() converts a value to // a double in centipawns scale, trace_add() stores white and black scores. - double to_cp(Value v) { return double(v) / double(PawnValueMidgame); } + double to_cp(Value v) { return double(v) / double(PawnValueMg); } void trace_add(int idx, Score wScore, Score bScore) {