Skip to content

Commit 7dea305

Browse files
late move reductions
1 parent 56d2848 commit 7dea305

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Move.h

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ namespace Moves {
4040
if (promotionType != Pieces::EMPTY) str += Util::pieceToString(promotionType, Color::BLACK);
4141
return str;
4242
}
43+
44+
bool tactical() const {
45+
return (flag > 0 && flag < 7) || promotionType != Pieces::EMPTY;
46+
}
4347
};
4448

4549
inline std::ostream& operator<<(std::ostream&os, const Move&move) {

src/Search.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int Search::alphaBeta(const int depth, int alpha, int beta, const int ply) {
114114
if (alpha >= beta) return alpha;
115115
}
116116

117-
if (depth == 0) return quiesce(alpha, beta, ply, 0);
117+
if (depth < 1) return quiesce(alpha, beta, ply, 0);
118118

119119
Move hashMove = NULL_MOVE;
120120
int positionScore = 0;
@@ -139,19 +139,23 @@ int Search::alphaBeta(const int depth, int alpha, int beta, const int ply) {
139139
continue;
140140
}
141141
logger.logToFile(move.toString() + " begin\n");
142-
if (ply == 0) {
143-
logger.sendString("moveStart", move.toString());
144-
}
145142

146143
hasLegalMoves = true;
147144

148-
const int score = -alphaBeta(depth - 1, -beta, -alpha, ply + 1);
145+
int score = 0;
146+
147+
// late move reductions
148+
bool shouldFullSearch = true;
149+
if (i > 2 && depth > 3 && !move.tactical()) {
150+
score = -alphaBeta(depth - 2, -alpha - 1, -alpha, ply + 1);
151+
152+
shouldFullSearch = score > alpha;
153+
}
154+
155+
if (shouldFullSearch) score = -alphaBeta(depth - 1, -beta, -alpha, ply + 1);
149156
board.unMakeMove();
150157

151158
logger.logToFile(std::format("{} end score : {}\n", move.toString(), score));
152-
if (ply == 0) {
153-
logger.sendString("moveEnd", move.toString());
154-
}
155159

156160
if (stop) return 0;
157161

0 commit comments

Comments
 (0)