Skip to content

Commit

Permalink
Use special rule for BlockedByKing
Browse files Browse the repository at this point in the history
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 #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 :-)
  • Loading branch information
protonspring authored and snicolet committed May 1, 2018
1 parent 5a7cdad commit 12ef8f7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/pawns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -228,16 +224,20 @@ 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);
Bitboard theirPawns = b & pos.pieces(Them);

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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 12ef8f7

Please sign in to comment.