diff --git a/src/bitbase.cpp b/src/bitbase.cpp
index 097da917..8c8c4702 100644
--- a/src/bitbase.cpp
+++ b/src/bitbase.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include
#include
diff --git a/src/bitboard.cpp b/src/bitboard.cpp
index e7430415..e4287f35 100644
--- a/src/bitboard.cpp
+++ b/src/bitboard.cpp
@@ -18,8 +18,8 @@
along with this program. If not, see .
*/
-#include
#include
+#include
#include "bitboard.h"
#include "misc.h"
diff --git a/src/bitboard.h b/src/bitboard.h
index 6907f184..aa29abf2 100644
--- a/src/bitboard.h
+++ b/src/bitboard.h
@@ -249,6 +249,9 @@ 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;
+}
/// attacks_bb() returns a bitboard representing all the squares attacked by a
/// piece of type Pt (bishop or rook) placed on 's'.
diff --git a/src/endgame.cpp b/src/endgame.cpp
index 3e572205..b1b3d664 100644
--- a/src/endgame.cpp
+++ b/src/endgame.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include "bitboard.h"
diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index 99c0cd6e..deb8211a 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include // For std::memset
#include
diff --git a/src/material.cpp b/src/material.cpp
index 773f332f..2e68ee68 100644
--- a/src/material.cpp
+++ b/src/material.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include // For std::min
#include
#include // For std::memset
@@ -130,7 +129,7 @@ Entry* probe(const Position& pos) {
Value npm_w = pos.non_pawn_material(WHITE);
Value npm_b = pos.non_pawn_material(BLACK);
- Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));
+ Value npm = clamp(npm_w + npm_b, EndgameLimit, MidgameLimit);
// Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME]
e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));
diff --git a/src/pawns.cpp b/src/pawns.cpp
index 88474751..c9c9e599 100644
--- a/src/pawns.cpp
+++ b/src/pawns.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include "bitboard.h"
@@ -208,7 +207,7 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
Value safety = (shift(theirPawns) & (FileABB | FileHBB) & BlockRanks & ksq) ?
Value(374) : Value(5);
- File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
+ File center = clamp(file_of(ksq), FILE_B, FILE_G);
for (File f = File(center - 1); f <= File(center + 1); ++f)
{
b = ourPawns & file_bb(f);
diff --git a/src/position.cpp b/src/position.cpp
index 812eabca..2bdf1009 100644
--- a/src/position.cpp
+++ b/src/position.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include // For offsetof()
#include // For std::memset, std::memcmp
diff --git a/src/search.cpp b/src/search.cpp
index 3319ee94..4dd4d789 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include
#include // For std::memset
@@ -461,7 +460,7 @@ void Thread::search() {
&& !mainThread->stopOnPonderhit)
{
double fallingEval = (306 + 9 * (mainThread->previousScore - bestValue)) / 581.0;
- fallingEval = std::max(0.5, std::min(1.5, fallingEval));
+ fallingEval = clamp(fallingEval, 0.5, 1.5);
// If the bestMove is stable over several iterations, reduce time accordingly
timeReduction = lastBestMoveDepth + 10 * ONE_PLY < completedDepth ? 1.95 : 1.0;
diff --git a/src/thread.cpp b/src/thread.cpp
index 6c1d7299..64dd9e18 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include // For std::count
#include
#include "movegen.h"
diff --git a/src/timeman.cpp b/src/timeman.cpp
index 484aaa65..fafde2aa 100644
--- a/src/timeman.cpp
+++ b/src/timeman.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include
diff --git a/src/ucioption.cpp b/src/ucioption.cpp
index 813a0890..54f33c9a 100644
--- a/src/ucioption.cpp
+++ b/src/ucioption.cpp
@@ -18,7 +18,6 @@
along with this program. If not, see .
*/
-#include
#include
#include
#include