mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Use special rule for BlockedByKing
Simplification: remove BlockedByKing from storm array and use a special rule. The BlockedByKing section in the storm array is substantially similar to the Unopposed section except for two extreme values V(-290), V(-274). Turns out removing BlockedByKing and using a special rule for these two values shows no Elo loss. All the other values in the BlockedByKing section are apparently irrelevant. BlockedByKing now falls under unopposed which (to me) is a bit more logical since there is no defending pawn on this file. Also, retuning the Unopposed section may be another improvement. GOOD) This is a simplification because the entire BlockedByKing section of the storm array goes away reducing a few lines of code (and less values to tune). This also brings clarity because the special rule is self documenting. BAD) It takes execution time to apply the special rule. This should be negli- gible because it is based on a template parameter and is boiled down to two bitwise AND's. STC: LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 33470 W: 6820 L: 6721 D: 19929 http://tests.stockfishchess.org/tests/view/5ae7b6e60ebc5926dba90e13 LTC: LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 47627 W: 7045 L: 6963 D: 33619 http://tests.stockfishchess.org/tests/view/5ae859ff0ebc5926dba90e85 Closes https://github.com/official-stockfish/Stockfish/pull/1574 Bench: 5512000 ----------- How to continue after this patch? This patch may open the possibility to move the special rule to evaluate.cpp in the evaluate::king() function, where we could refine the rule using king danger information. For instance, with a king in H2 blocking an opponent pawn in H3, it may be critical to know that the opponent has no safe check in G2 before giving the bonus :-)
This commit is contained in:
parent
5a7cdadfb3
commit
12ef8f71a2
1 changed files with 9 additions and 11 deletions
|
@ -56,10 +56,6 @@ namespace {
|
|||
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
||||
// no pawn on the given file, or their pawn is behind our king.
|
||||
constexpr Value StormDanger[][4][RANK_NB] = {
|
||||
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
||||
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
||||
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
||||
{ V( 0), V( 53), V( 127), V(56), V(14) } },
|
||||
{ { V( 4), V( 73), V( 132), V(46), V(31) }, // Unopposed
|
||||
{ V( 1), V( 64), V( 143), V(26), V(13) },
|
||||
{ V( 1), V( 47), V( 110), V(44), V(24) },
|
||||
|
@ -228,9 +224,10 @@ Entry* probe(const Position& pos) {
|
|||
template<Color Us>
|
||||
Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||
|
||||
enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked };
|
||||
enum { Unopposed, BlockedByPawn, Unblocked };
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
||||
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||
constexpr Bitboard BlockRanks = (Us == WHITE ? Rank2BB | Rank3BB : Rank7BB | Rank6BB);
|
||||
|
||||
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
|
||||
Bitboard ourPawns = b & pos.pieces(Us);
|
||||
|
@ -238,6 +235,9 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
|||
|
||||
Value safety = (ourPawns & file_bb(ksq)) ? Value(5) : Value(-5);
|
||||
|
||||
if ((theirPawns & (FileABB | FileHBB) & BlockRanks) & (ksq + Up))
|
||||
safety += 374;
|
||||
|
||||
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
|
||||
for (File f = File(center - 1); f <= File(center + 1); ++f)
|
||||
{
|
||||
|
@ -249,11 +249,9 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
|||
|
||||
int d = std::min(f, ~f);
|
||||
safety += ShelterStrength[d][rkUs]
|
||||
- StormDanger
|
||||
[(shift<Down>(b) & ksq) ? BlockedByKing :
|
||||
rkUs == RANK_1 ? Unopposed :
|
||||
rkThem == (rkUs + 1) ? BlockedByPawn : Unblocked]
|
||||
[d][rkThem];
|
||||
- StormDanger[rkUs == RANK_1 ? Unopposed :
|
||||
rkUs == rkThem - 1 ? BlockedByPawn : Unblocked]
|
||||
[d][rkThem];
|
||||
}
|
||||
|
||||
return safety;
|
||||
|
|
Loading…
Add table
Reference in a new issue