From: Marco Costalba Date: Sat, 25 May 2013 10:18:58 +0000 (+0200) Subject: Re-add "Pawn Structure" UCI option X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=7222f47350591190a97508f84131d80046f340ce Re-add "Pawn Structure" UCI option And reshuffle the code to not special case this parameter. No functional change. --- diff --git a/polyglot.ini b/polyglot.ini index 86c8c7ca..58ddb3c7 100644 --- a/polyglot.ini +++ b/polyglot.ini @@ -19,9 +19,9 @@ Search Log Filename = SearchLog.txt Book File = book.bin Best Book Move = false Contempt Factor = 0 -Mobility (Middle Game) = 100 +Mobility (Midgame) = 100 Mobility (Endgame) = 100 -Passed Pawns (Middle Game) = 100 +Passed Pawns (Midgame) = 100 Passed Pawns (Endgame) = 100 Space = 100 Aggressiveness = 100 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index be76fe33..4b1862db 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -75,7 +75,7 @@ namespace { const int GrainSize = 4; // Evaluation weights, initialized from UCI options - enum { Mobility, PassedPawns, Space, KingDangerUs, KingDangerThem }; + enum { Mobility, PawnStructure, PassedPawns, Space, KingDangerUs, KingDangerThem }; Score Weights[6]; typedef Value V; @@ -88,7 +88,7 @@ namespace { // // Values modified by Joona Kiiski const Score WeightsInternal[] = { - S(289, 344), S(221, 273), S(46, 0), S(271, 0), S(307, 0) + S(289, 344), S(233, 201), S(221, 273), S(46, 0), S(271, 0), S(307, 0) }; // MobilityBonus[PieceType][attacked] contains mobility bonuses for middle and @@ -240,15 +240,16 @@ namespace { template Score evaluate_threats(const Position& pos, EvalInfo& ei); - template - int evaluate_space(const Position& pos, EvalInfo& ei); - template Score evaluate_passed_pawns(const Position& pos, EvalInfo& ei); + template + int evaluate_space(const Position& pos, EvalInfo& ei); + Score evaluate_unstoppable_pawns(const Position& pos, EvalInfo& ei); Value interpolate(const Score& v, Phase ph, ScaleFactor sf); + Score apply_weight(Score v, Score w); Score weight_option(const std::string& mgOpt, const std::string& egOpt, Score internalWeight); double to_cp(Value v); void trace_add(int idx, Score term_w, Score term_b = SCORE_ZERO); @@ -272,8 +273,9 @@ namespace Eval { void init() { - Weights[Mobility] = weight_option("Mobility (Middle Game)", "Mobility (Endgame)", WeightsInternal[Mobility]); - Weights[PassedPawns] = weight_option("Passed Pawns (Middle Game)", "Passed Pawns (Endgame)", WeightsInternal[PassedPawns]); + Weights[Mobility] = weight_option("Mobility (Midgame)", "Mobility (Endgame)", WeightsInternal[Mobility]); + Weights[PawnStructure] = weight_option("Pawn Structure (Midgame)", "Pawn Structure (Endgame)", WeightsInternal[PawnStructure]); + Weights[PassedPawns] = weight_option("Passed Pawns (Midgame)", "Passed Pawns (Endgame)", WeightsInternal[PassedPawns]); Weights[Space] = weight_option("Space", "Space", WeightsInternal[Space]); Weights[KingDangerUs] = weight_option("Cowardice", "Cowardice", WeightsInternal[KingDangerUs]); Weights[KingDangerThem] = weight_option("Aggressiveness", "Aggressiveness", WeightsInternal[KingDangerThem]); @@ -374,7 +376,7 @@ Value do_evaluate(const Position& pos, Value& margin) { // Probe the pawn hash table ei.pi = Pawns::probe(pos, th->pawnsTable); - score += ei.pi->pawns_value(); + score += apply_weight(ei.pi->pawns_value(), Weights[PawnStructure]); // Initialize attack and king safety bitboards init_eval_info(pos, ei); @@ -1119,6 +1121,11 @@ Value do_evaluate(const Position& pos, Value& margin) { return Value((result + GrainSize / 2) & ~(GrainSize - 1)); } + // apply_weight() weights score v by score w trying to prevent overflow + Score apply_weight(Score v, Score w) { + return make_score((int(mg_value(v)) * mg_value(w)) / 0x100, + (int(eg_value(v)) * eg_value(w)) / 0x100); + } // weight_option() computes the value of an evaluation weight, by combining // two UCI-configurable weights (midgame and endgame) with an internal weight. diff --git a/src/pawns.cpp b/src/pawns.cpp index 5b64ac61..3b04515f 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -62,8 +62,6 @@ namespace { S(34,68), S(83,166), S(0, 0), S( 0, 0) }; - const Score PawnStructureWeight = S(233, 201); - // Weakness of our pawn shelter in front of the king indexed by [king pawn][rank] const Value ShelterWeakness[2][RANK_NB] = { { V(141), V(0), V(38), V(102), V(128), V(141), V(141) }, @@ -215,9 +213,6 @@ Entry* probe(const Position& pos, Table& entries) { e->value = evaluate_pawns(pos, wPawns, bPawns, e) - evaluate_pawns(pos, bPawns, wPawns, e); - - e->value = apply_weight(e->value, PawnStructureWeight); - return e; } diff --git a/src/types.h b/src/types.h index 1e036e89..c21b55be 100644 --- a/src/types.h +++ b/src/types.h @@ -325,12 +325,6 @@ inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); } -/// Weight score v by score w trying to prevent overflow -inline Score apply_weight(Score v, Score w) { - return make_score((int(mg_value(v)) * mg_value(w)) / 0x100, - (int(eg_value(v)) * eg_value(w)) / 0x100); -} - #undef ENABLE_OPERATORS_ON #undef ENABLE_SAFE_OPERATORS_ON diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 4bb4369f..3afa59d3 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -65,9 +65,11 @@ void init(OptionsMap& o) { o["Book File"] = Option("book.bin"); o["Best Book Move"] = Option(false); o["Contempt Factor"] = Option(0, -50, 50); - o["Mobility (Middle Game)"] = Option(100, 0, 200, on_eval); + o["Mobility (Midgame)"] = Option(100, 0, 200, on_eval); o["Mobility (Endgame)"] = Option(100, 0, 200, on_eval); - o["Passed Pawns (Middle Game)"] = Option(100, 0, 200, on_eval); + o["Pawn Structure (Midgame)"] = Option(100, 0, 200, on_eval); + o["Pawn Structure (Endgame)"] = Option(100, 0, 200, on_eval); + o["Passed Pawns (Midgame)"] = Option(100, 0, 200, on_eval); o["Passed Pawns (Endgame)"] = Option(100, 0, 200, on_eval); o["Space"] = Option(100, 0, 200, on_eval); o["Aggressiveness"] = Option(100, 0, 200, on_eval);