X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=70c91f8ae7a877d2ffdf6efbf6395120835c2ce9;hp=652fb386683c13deeef0e82cd134f6403661b157;hb=15616ad19965444ea66896a0511f2a4d48745110;hpb=46409a7852ae22abf9c32cbcfe3b35f164ae8ec5 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 652fb386..70c91f8a 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -372,7 +372,7 @@ Value do_evaluate(const Position& pos, Value& margin) { if (ei.mi->space_weight()) { int s = evaluate_space(pos, ei) - evaluate_space(pos, ei); - score += apply_weight(make_score(s * ei.mi->space_weight(), 0), Weights[Space]); + score += apply_weight(s * ei.mi->space_weight(), Weights[Space]); } // Scale winning side if position is more drawish that what it appears @@ -391,7 +391,7 @@ Value do_evaluate(const Position& pos, Value& margin) { { // Check for KBP vs KB with only a single pawn that is almost // certainly a draw or at least two pawns. - bool one_pawn = (pos.piece_count(WHITE, PAWN) + pos.piece_count(BLACK, PAWN) == 1); + bool one_pawn = (pos.count(WHITE) + pos.count(BLACK) == 1); sf = one_pawn ? ScaleFactor(8) : ScaleFactor(32); } else @@ -410,8 +410,8 @@ Value do_evaluate(const Position& pos, Value& margin) { Tracing::add(IMBALANCE, ei.mi->material_value()); Tracing::add(PAWN, ei.pi->pawns_value()); Tracing::add(UNSTOPPABLE, evaluate_unstoppable_pawns(pos, ei)); - Score w = make_score(ei.mi->space_weight() * evaluate_space(pos, ei), 0); - Score b = make_score(ei.mi->space_weight() * evaluate_space(pos, ei), 0); + Score w = ei.mi->space_weight() * evaluate_space(pos, ei); + Score b = ei.mi->space_weight() * evaluate_space(pos, ei); Tracing::add(SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space])); Tracing::add(TOTAL, score); Tracing::stream << "\nUncertainty margin: White: " << to_cp(margins[WHITE]) @@ -433,16 +433,16 @@ Value do_evaluate(const Position& pos, Value& margin) { template void init_eval_info(const Position& pos, EvalInfo& ei) { - const Color Them = (Us == WHITE ? BLACK : WHITE); + const Color Them = (Us == WHITE ? BLACK : WHITE); + const Square Down = (Us == WHITE ? DELTA_S : DELTA_N); Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from(pos.king_square(Them)); ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us); // Init king safety tables only if we are going to use them - if ( pos.piece_count(Us, QUEEN) - && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg) + if (pos.count(Us) && pos.non_pawn_material(Us) > QueenValueMg + PawnValueMg) { - ei.kingRing[Them] = (b | (Us == WHITE ? b >> 8 : b << 8)); + ei.kingRing[Them] = b | shift_bb(b); b &= ei.attackedBy[Us][PAWN]; ei.kingAttackersCount[Us] = b ? popcount(b) / 2 : 0; ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0; @@ -468,7 +468,7 @@ Value do_evaluate(const Position& pos, Value& margin) { if (bonus && (ei.attackedBy[Us][PAWN] & s)) { if ( !pos.pieces(Them, KNIGHT) - && !(same_color_squares(s) & pos.pieces(Them, BISHOP))) + && !(squares_of_color(s) & pos.pieces(Them, BISHOP))) bonus += bonus + bonus / 2; else bonus += bonus / 2; @@ -487,7 +487,7 @@ Value do_evaluate(const Position& pos, Value& margin) { Score score = SCORE_ZERO; const Color Them = (Us == WHITE ? BLACK : WHITE); - const Square* pl = pos.piece_list(Us, Piece); + const Square* pl = pos.list(Us); ei.attackedBy[Us][Piece] = 0; @@ -509,7 +509,9 @@ Value do_evaluate(const Position& pos, Value& margin) { ei.kingAdjacentZoneAttacksCount[Us] += popcount(bb); } - int mob = popcount(b & mobilityArea); + int mob = Piece != QUEEN ? popcount(b & mobilityArea) + : popcount(b & mobilityArea); + mobility += MobilityBonus[Piece][mob]; // Decrease score if we are attacked by an enemy pawn. Remaining part @@ -530,7 +532,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // Bishop and knight outposts squares if ( (Piece == BISHOP || Piece == KNIGHT) - && !(pos.pieces(Them, PAWN) & attack_span_mask(Us, s))) + && !(pos.pieces(Them, PAWN) & pawn_attack_span(Us, s))) score += evaluate_outposts(pos, ei, s); if ( (Piece == ROOK || Piece == QUEEN) @@ -541,8 +543,8 @@ Value do_evaluate(const Position& pos, Value& margin) { && relative_rank(Us, pos.king_square(Them)) == RANK_8) score += Piece == ROOK ? RookOn7th : QueenOn7th; - // Major piece attacking enemy pawns on the same rank - Bitboard pawns = pos.pieces(Them, PAWN) & rank_bb(s); + // Major piece attacking enemy pawns on the same rank/file + Bitboard pawns = pos.pieces(Them, PAWN) & PseudoAttacks[ROOK][s]; if (pawns) score += popcount(pawns) * (Piece == ROOK ? RookOnPawn : QueenOnPawn); } @@ -554,7 +556,7 @@ Value do_evaluate(const Position& pos, Value& margin) { if (ei.pi->semiopen(Us, file_of(s))) score += ei.pi->semiopen(Them, file_of(s)) ? RookOpenFile : RookSemiopenFile; - if (mob > 6 || ei.pi->semiopen(Us, file_of(s))) + if (mob > 3 || ei.pi->semiopen(Us, file_of(s))) continue; Square ksq = pos.king_square(Us); @@ -821,7 +823,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // If there is an enemy rook or queen attacking the pawn from behind, // add all X-ray attacks by the rook or queen. Otherwise consider only // the squares in the pawn's path attacked or occupied by the enemy. - if ( (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN)) + if ( unlikely(forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN)) && (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN) & pos.attacks_from(s))) unsafeSquares = squaresToQueen; else @@ -990,7 +992,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // black pawns: a4, b4 white: b2 then pawn in b4 is giving support. if (!opposed) { - b2 = supporters & in_front_bb(winnerSide, blockSq + pawn_push(winnerSide)); + 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) { @@ -1000,7 +1002,7 @@ Value do_evaluate(const Position& pos, Value& margin) { } // Check pawns that can be sacrificed against the blocking pawn - b2 = attack_span_mask(winnerSide, blockSq) & candidates & ~(1ULL << s); + b2 = pawn_attack_span(winnerSide, blockSq) & candidates & ~(1ULL << s); while (b2) // This while-loop could be replaced with LSB/MSB (depending on color) { @@ -1081,7 +1083,7 @@ Value do_evaluate(const Position& pos, Value& margin) { int ev = (eg_value(v) * int(sf)) / SCALE_FACTOR_NORMAL; int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128; - return Value((result + GrainSize / 2) & ~(GrainSize - 1)); + return Value((result / GrainSize) * GrainSize); // Sign independent } // apply_weight() weights score v by score w trying to prevent overflow @@ -1138,11 +1140,9 @@ Value do_evaluate(const Position& pos, Value& margin) { std::string Tracing::do_trace(const Position& pos) { - Search::RootColor = pos.side_to_move(); - stream.str(""); stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2); - memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score)); + std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score)); Value margin; do_evaluate(pos, margin);