From: Fabian Fichter Date: Thu, 27 Aug 2020 20:45:45 +0000 (+0200) Subject: Consider material density in king safety X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=a0c5de35a2b0cc6bc80f8a397c708ac5485cf63a;p=fairystockfish.git Consider material density in king safety Scale king danger of drop variants by material density and thereby remove magic correction factors. euroshogi STC LLR: 2.97 (-2.94,2.94) [0.00,10.00] Total: 2735 W: 1417 L: 1276 D: 42 http://www.variantfishtest.org:6543/tests/view/5f3fd4266e23db221d9e902e euroshogi LTC LLR: 2.95 (-2.94,2.94) [0.00,10.00] Total: 1427 W: 760 L: 639 D: 28 http://www.variantfishtest.org:6543/tests/view/5f46e1076e23db221d9e9045 shogi STC LLR: 2.95 (-2.94,2.94) [0.00,10.00] Total: 6037 W: 3098 L: 2909 D: 30 http://www.variantfishtest.org:6543/tests/view/5f3fabca6e23db221d9e9013 shogi LTC LLR: 2.98 (-2.94,2.94) [-10.00,5.00] Total: 917 W: 487 L: 425 D: 5 http://www.variantfishtest.org:6543/tests/view/5f46b5236e23db221d9e9043 judkins STC LLR: 2.96 (-2.94,2.94) [0.00,10.00] Total: 2936 W: 1430 L: 1292 D: 214 http://www.variantfishtest.org:6543/tests/view/5f3fd48d6e23db221d9e9030 --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index eba72b0..fcecece 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -616,9 +616,10 @@ namespace { if (pos.king_type() == WAZIR) score += make_score(0, mg_value(score) / 2); - // For drop games, king danger is independent of game phase + // For drop games, king danger is independent of game phase, but dependent on material density if (pos.captures_to_hand() || pos.two_boards()) - score = make_score(mg_value(score), mg_value(score)) * 2 / (2 + 16 / pos.max_rank() * !pos.shogi_doubled_pawn()); + score = make_score(mg_value(score) * me->material_density() / 11000, + mg_value(score) * me->material_density() / 11000); if (T) Trace::add(KING, Us, score); diff --git a/src/material.cpp b/src/material.cpp index a01e24a..8afe7cc 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -141,12 +141,14 @@ Entry* probe(const Position& pos) { Value npm = Utility::clamp(npm_w + npm_b, EndgameLimit, MidgameLimit); // Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME] - if (pos.captures_to_hand()) + if (pos.captures_to_hand() || pos.two_boards()) { Value npm2 = VALUE_ZERO; for (PieceType pt : pos.piece_types()) npm2 += (pos.count_in_hand(WHITE, pt) + pos.count_in_hand(BLACK, pt)) * PieceValue[MG][make_piece(WHITE, pt)]; e->gamePhase = Phase(PHASE_MIDGAME * npm / std::max(int(npm + npm2), 1)); + int countAll = pos.count_with_hand(WHITE, ALL_PIECES) + pos.count_with_hand(BLACK, ALL_PIECES); + e->materialDensity = (npm + npm2 + pos.count() * PawnValueMg) * countAll / ((pos.max_file() + 1) * (pos.max_rank() + 1)); } else e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit)); diff --git a/src/material.h b/src/material.h index 9ab1d81..076f078 100644 --- a/src/material.h +++ b/src/material.h @@ -41,6 +41,7 @@ struct Entry { Score imbalance() const { return make_score(value, value); } Phase game_phase() const { return gamePhase; } + int material_density() const { return materialDensity; } bool specialized_eval_exists() const { return evaluationFunction != nullptr; } Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); } @@ -62,6 +63,7 @@ struct Entry { int16_t value; uint8_t factor[COLOR_NB]; Phase gamePhase; + int materialDensity; }; typedef HashTable Table;