From 8a4821923ac6860c791185a6d25c60ad0391739f Mon Sep 17 00:00:00 2001 From: protonspring Date: Mon, 20 Aug 2018 10:29:46 -0600 Subject: [PATCH 1/1] make DistanceRing more consistent This is a non-functional change. By pre-incrementing minKingPawnDistance instead of post-incrementing, we can remove this -1. This also makes DistanceRing more consistent with the rest of stockfish since it now holds an actual "distance" instead of a less natural distance-1. In current master, PseudoAttacks[KING][ksq] == DistanceRingBB[ksq][0] With this patch, it will be PseudoAttacks[KING][ksq] == DistanceRingBB[ksq][1] ie squares at distance 1 from the king. This is more natural use of distance. The current array size DistanceRingBB[SQUARE_NB][8] is still OK with the new definition, because maximum distance between two squares on a chess board is seven (for example Kh1 and a8). No functional change. --- src/bitboard.cpp | 2 +- src/pawns.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index b3aeed85..4e2778a9 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -116,7 +116,7 @@ void Bitboards::init() { if (s1 != s2) { SquareDistance[s1][s2] = std::max(distance(s1, s2), distance(s1, s2)); - DistanceRingBB[s1][SquareDistance[s1][s2] - 1] |= s2; + DistanceRingBB[s1][SquareDistance[s1][s2]] |= s2; } int steps[][5] = { {}, { 7, 9 }, { 6, 10, 15, 17 }, {}, {}, {}, { 1, 7, 8, 9 } }; diff --git a/src/pawns.cpp b/src/pawns.cpp index 7cc71ca6..5048d4f1 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -245,7 +245,7 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) { Bitboard pawns = pos.pieces(Us, PAWN); if (pawns) - while (!(DistanceRingBB[ksq][minKingPawnDistance++] & pawns)) {} + while (!(DistanceRingBB[ksq][++minKingPawnDistance] & pawns)) {} Value bonus = evaluate_shelter(pos, ksq); -- 2.39.2