From f21b50398231b4846c364e23bfeeab314c7731ea Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Thu, 18 Apr 2019 16:53:52 +0200 Subject: [PATCH] Simplify distance (#2109) Only called with Squares as argument, so remove unused variants. As this is just syntax changes, only verified bench at high depth. No functional change. --- src/bitboard.h | 10 ++++------ src/endgame.cpp | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/bitboard.h b/src/bitboard.h index b1d961f4..6f99ef19 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -237,15 +237,13 @@ inline bool aligned(Square s1, Square s2, Square s3) { /// distance() functions return the distance between x and y, defined as the -/// number of steps for a king in x to reach y. Works with squares, ranks, files. +/// number of steps for a king in x to reach y. -template inline int distance(T x, T y) { return std::abs(x - y); } +template inline int distance(Square x, Square y); +template<> inline int distance(Square x, Square y) { return std::abs(file_of(x) - file_of(y)); } +template<> inline int distance(Square x, Square y) { return std::abs(rank_of(x) - rank_of(y)); } template<> inline int distance(Square x, Square y) { return SquareDistance[x][y]; } -template inline int distance(T2 x, T2 y); -template<> inline int distance(Square x, Square y) { return distance(file_of(x), file_of(y)); } -template<> inline int distance(Square x, Square y) { return distance(rank_of(x), rank_of(y)); } - template constexpr const T& clamp(const T& v, const T& lo, const T& hi) { return v < lo ? lo : v > hi ? hi : v; } diff --git a/src/endgame.cpp b/src/endgame.cpp index efc41a98..5958e633 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -635,8 +635,6 @@ ScaleFactor Endgame::operator()(const Position& pos) const { Square ksq = pos.square(weakSide); Square psq1 = pos.squares(strongSide)[0]; Square psq2 = pos.squares(strongSide)[1]; - Rank r1 = rank_of(psq1); - Rank r2 = rank_of(psq2); Square blockSq1, blockSq2; if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2)) @@ -670,7 +668,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && opposite_colors(ksq, wbsq) && ( bbsq == blockSq2 || (pos.attacks_from(blockSq2) & pos.pieces(weakSide, BISHOP)) - || distance(r1, r2) >= 2)) + || distance(psq1, psq2) >= 2)) return SCALE_FACTOR_DRAW; else if ( ksq == blockSq2 -- 2.39.2