X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=912c05fc8b394942e46a864235dd9c29dda5d8e0;hp=c7fec9131e11ceeef0b1499c92b2ea1c012c0d83;hb=7a1ff6d8ff39bb9e6844d24467899d47e942486f;hpb=03cd049c6858f5d1c4b7e50f08d7ddc45e0a029e diff --git a/src/evaluate.cpp b/src/evaluate.cpp index c7fec913..912c05fc 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -186,12 +186,8 @@ namespace { // based on how many squares inside this area are safe and available for // friendly minor pieces. const Bitboard SpaceMask[] = { - (1ULL << SQ_C2) | (1ULL << SQ_D2) | (1ULL << SQ_E2) | (1ULL << SQ_F2) | - (1ULL << SQ_C3) | (1ULL << SQ_D3) | (1ULL << SQ_E3) | (1ULL << SQ_F3) | - (1ULL << SQ_C4) | (1ULL << SQ_D4) | (1ULL << SQ_E4) | (1ULL << SQ_F4), - (1ULL << SQ_C7) | (1ULL << SQ_D7) | (1ULL << SQ_E7) | (1ULL << SQ_F7) | - (1ULL << SQ_C6) | (1ULL << SQ_D6) | (1ULL << SQ_E6) | (1ULL << SQ_F6) | - (1ULL << SQ_C5) | (1ULL << SQ_D5) | (1ULL << SQ_E5) | (1ULL << SQ_F5) + (FileCBB | FileDBB | FileEBB | FileFBB) & (Rank2BB | Rank3BB | Rank4BB), + (FileCBB | FileDBB | FileEBB | FileFBB) & (Rank7BB | Rank6BB | Rank5BB) }; // King danger constants and variables. The king danger scores are taken @@ -626,11 +622,11 @@ Value do_evaluate(const Position& pos, Value& margin) { // type of attacking piece, from knights to queens. Kings are not // considered because are already handled in king evaluation. if (weakEnemies) - for (PieceType pt1 = KNIGHT; pt1 < KING; pt1++) + for (PieceType pt1 = KNIGHT; pt1 < KING; ++pt1) { b = ei.attackedBy[Us][pt1] & weakEnemies; if (b) - for (PieceType pt2 = PAWN; pt2 < KING; pt2++) + for (PieceType pt2 = PAWN; pt2 < KING; ++pt2) if (b & pos.pieces(pt2)) score += Threat[pt1][pt2]; } @@ -876,9 +872,16 @@ Value do_evaluate(const Position& pos, Value& margin) { { if (pos.non_pawn_material(Them) <= KnightValueMg) ebonus += ebonus / 4; + else if (pos.pieces(Them, ROOK, QUEEN)) ebonus -= ebonus / 4; } + + // Increase the bonus if we have more non-pawn pieces + if (pos.count( Us) - pos.count( Us) > + pos.count(Them) - pos.count(Them)) + ebonus += ebonus / 4; + score += make_score(mbonus, ebonus); } @@ -905,7 +908,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // Step 1. Hunt for unstoppable passed pawns. If we find at least one, // record how many plies are required for promotion. - for (c = WHITE; c <= BLACK; c++) + for (c = WHITE; c <= BLACK; ++c) { // Skip if other side has non-pawn pieces if (pos.non_pawn_material(~c)) @@ -1006,19 +1009,19 @@ Value do_evaluate(const Position& pos, Value& margin) { { b2 = supporters & in_front_bb(winnerSide, rank_of(blockSq + pawn_push(winnerSide))); - while (b2) // This while-loop could be replaced with LSB/MSB (depending on color) + if (b2) { - d = square_distance(blockSq, pop_lsb(&b2)) - 2; + d = square_distance(blockSq, backmost_sq(winnerSide, b2)) - 2; movesToGo = std::min(movesToGo, d); } } // Check pawns that can be sacrificed against the blocking pawn - b2 = pawn_attack_span(winnerSide, blockSq) & candidates & ~(1ULL << s); + b2 = pawn_attack_span(winnerSide, blockSq) & candidates & ~SquareBB[s]; - while (b2) // This while-loop could be replaced with LSB/MSB (depending on color) + if (b2) { - d = square_distance(blockSq, pop_lsb(&b2)) - 2; + d = square_distance(blockSq, backmost_sq(winnerSide, b2)) - 2; movesToGo = std::min(movesToGo, d); } @@ -1037,12 +1040,8 @@ Value do_evaluate(const Position& pos, Value& margin) { kingptg = (minKingDist + blockersCount) * 2; } - // Check if pawn sacrifice plan _may_ save the day - if (pliesToQueen[winnerSide] + 3 > pliesToGo + sacptg) - return SCORE_ZERO; - - // Check if king capture plan _may_ save the day (contains some false positives) - if (pliesToQueen[winnerSide] + 3 > pliesToGo + kingptg) + // Check if pawn sacrifice or king capture plan _may_ save the day + if (pliesToQueen[winnerSide] + 3 > pliesToGo + std::min(kingptg, sacptg)) return SCORE_ZERO; }