X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=85665a4344de241382f68210b31041eeee1d01fb;hp=7f7df3c5465e491bc78775338f12de908fd3d6ab;hb=a7cb05b1eba0114dfc4dd666b15c245d73a4bcd4;hpb=080a4995a3977a0fe7071e62151dc4d716a13302 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7f7df3c5..85665a43 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -43,7 +43,7 @@ namespace { const int Sign[2] = { 1, -1 }; // Evaluation grain size, must be a power of 2 - const int GrainSize = 4; + const int GrainSize = 8; // Evaluation weights, initialized from UCI options int WeightMobilityMidgame, WeightMobilityEndgame; @@ -342,14 +342,14 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) { ei.egValue += apply_weight(ei.pi->eg_value(), WeightPawnStructureEndgame); // Initialize king attack bitboards and king attack zones for both sides - ei.attackedBy[WHITE][KING] = pos.piece_attacks(pos.king_square(WHITE)); - ei.attackedBy[BLACK][KING] = pos.piece_attacks(pos.king_square(BLACK)); + ei.attackedBy[WHITE][KING] = pos.attacks_from(pos.king_square(WHITE)); + ei.attackedBy[BLACK][KING] = pos.attacks_from(pos.king_square(BLACK)); ei.kingZone[WHITE] = ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8); ei.kingZone[BLACK] = ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8); // Initialize pawn attack bitboards for both sides - ei.attackedBy[WHITE][PAWN] = ((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB); - ei.attackedBy[BLACK][PAWN] = ((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB); + ei.attackedBy[WHITE][PAWN] = ((pos.pieces(PAWN, WHITE) << 9) & ~FileABB) | ((pos.pieces(PAWN, WHITE) << 7) & ~FileHBB); + ei.attackedBy[BLACK][PAWN] = ((pos.pieces(PAWN, BLACK) >> 7) & ~FileABB) | ((pos.pieces(PAWN, BLACK) >> 9) & ~FileHBB); Bitboard b1 = ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING]; Bitboard b2 = ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING]; if (b1) @@ -590,10 +590,10 @@ namespace { // Increase bonus if supported by pawn, especially if the opponent has // no minor piece which can exchange the outpost piece - if (bonus && (p.pawn_attacks(them, s) & p.pawns(us))) + if (bonus && (p.attacks_from(s, them) & p.pieces(PAWN, us))) { - if ( p.knights(them) == EmptyBoardBB - && (SquaresByColorBB[square_color(s)] & p.bishops(them)) == EmptyBoardBB) + if ( p.pieces(KNIGHT, them) == EmptyBoardBB + && (SquaresByColorBB[square_color(s)] & p.pieces(BISHOP, them)) == EmptyBoardBB) bonus += bonus + bonus / 2; else bonus += bonus / 2; @@ -620,11 +620,11 @@ namespace { s = pos.piece_list(us, Piece, i); if (Piece == KNIGHT || Piece == QUEEN) - b = pos.piece_attacks(s); + b = pos.attacks_from(s); else if (Piece == BISHOP) - b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.queens(us)); + b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, us)); else if (Piece == ROOK) - b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.rooks_and_queens(us)); + b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, us)); else assert(false); @@ -773,7 +773,7 @@ namespace { if (QueenContactMates && !p.is_check()) { Bitboard escapeSquares = - p.piece_attacks(s) & ~p.pieces_of_color(us) & ~attackedByOthers; + p.attacks_from(s) & ~p.pieces_of_color(us) & ~attackedByOthers; while (b) { @@ -785,10 +785,10 @@ namespace { for (int i = 0; i < p.piece_count(them, QUEEN); i++) { from = p.piece_list(them, QUEEN, i); - if ( bit_is_set(p.piece_attacks(from), to) + if ( bit_is_set(p.attacks_from(from), to) && !bit_is_set(p.pinned_pieces(them), from) - && !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & p.rooks_and_queens(us)) - && !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & p.bishops_and_queens(us))) + && !(rook_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(ROOK, QUEEN, us)) + && !(bishop_attacks_bb(to, occ & ClearMaskBB[from]) & p.pieces(BISHOP, QUEEN, us))) ei.mateThreat[them] = make_move(from, to); } @@ -801,7 +801,7 @@ namespace { // Analyse safe distance checks if (QueenCheckBonus > 0 || RookCheckBonus > 0) { - b = p.piece_attacks(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); + b = p.attacks_from(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); // Queen checks b2 = b & ei.attacked_by(them, QUEEN); @@ -815,7 +815,7 @@ namespace { } if (QueenCheckBonus > 0 || BishopCheckBonus > 0) { - b = p.piece_attacks(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); + b = p.attacks_from(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); // Queen checks b2 = b & ei.attacked_by(them, QUEEN); @@ -829,7 +829,7 @@ namespace { } if (KnightCheckBonus > 0) { - b = p.piece_attacks(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); + b = p.attacks_from(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); // Knight checks b2 = b & ei.attacked_by(them, KNIGHT); @@ -841,7 +841,7 @@ namespace { // adding pawns later). if (DiscoveredCheckBonus) { - b = p.discovered_check_candidates(them) & ~p.pawns(); + b = p.discovered_check_candidates(them) & ~p.pieces(PAWN); if (b) attackUnits += DiscoveredCheckBonus * count_1s_max_15(b) * (sente? 2 : 1); } @@ -889,7 +889,7 @@ namespace { Color them = opposite_color(us); Square ourKingSq = pos.king_square(us); Square theirKingSq = pos.king_square(them); - Bitboard b = ei.pi->passed_pawns() & pos.pawns(us), b2, b3, b4; + Bitboard b = ei.pi->passed_pawns() & pos.pieces(PAWN, us), b2, b3, b4; while (b) { @@ -923,14 +923,14 @@ namespace { // If there is an enemy rook or queen attacking the pawn from behind, // add all X-ray attacks by the rook or queen. if ( bit_is_set(ei.attacked_by(them,ROOK) | ei.attacked_by(them,QUEEN),s) - && (squares_behind(us, s) & pos.rooks_and_queens(them))) + && (squares_behind(us, s) & pos.pieces(ROOK, QUEEN, them))) b3 = b2; // Squares attacked or occupied by enemy pieces b3 |= (b2 & pos.pieces_of_color(them)); // There are no enemy pawns in the pawn's path - assert((b2 & pos.pieces_of_color_and_type(them, PAWN)) == EmptyBoardBB); + assert((b2 & pos.pieces(PAWN, them)) == EmptyBoardBB); // Are any of the squares in the pawn's path attacked or occupied by the enemy? if (b3 == EmptyBoardBB) @@ -951,10 +951,10 @@ namespace { } // If the pawn is supported by a friendly pawn, increase bonus - b2 = pos.pawns(us) & neighboring_files_bb(s); + b2 = pos.pieces(PAWN, us) & neighboring_files_bb(s); if (b2 & rank_bb(s)) ebonus += Value(r * 20); - else if (pos.pawn_attacks(them, s) & b2) + else if (pos.attacks_from(s, them) & b2) ebonus += Value(r * 12); // If the other side has only a king, check whether the pawn is @@ -993,7 +993,7 @@ namespace { if ( pos.non_pawn_material(them) <= KnightValueMidgame && pos.piece_count(them, KNIGHT) <= 1) ebonus += ebonus / 4; - else if (pos.rooks_and_queens(them)) + else if (pos.pieces(ROOK, QUEEN, them)) ebonus -= ebonus / 4; } @@ -1115,13 +1115,13 @@ namespace { // pawn, or if it is undefended and attacked by an enemy piece. Bitboard safeSquares = SpaceMask[us] - & ~pos.pawns(us) + & ~pos.pieces(PAWN, us) & ~ei.attacked_by(them, PAWN) & ~(~ei.attacked_by(us) & ei.attacked_by(them)); // Find all squares which are at most three squares behind some friendly // pawn. - Bitboard behindFriendlyPawns = pos.pawns(us); + Bitboard behindFriendlyPawns = pos.pieces(PAWN, us); if (us == WHITE) { behindFriendlyPawns |= (behindFriendlyPawns >> 8);