Skip to content

Commit

Permalink
Singular extension (#2)
Browse files Browse the repository at this point in the history
Winter v0.4.2 vs v0.4a: 4231 - 2903 - 8866 [0.541] 16000
Elo difference: 28.90 +/- 3.59

- Min depth = 9
- In both PV and NW nodes
- Singularity check
-- Separate search from regular AB code
-- search depth = (original depth + 1) / 3
-- Alpha and Beta based on TT entry score - depth * 4
  • Loading branch information
rosenthj authored Feb 1, 2019
1 parent 0b091ec commit f2a9593
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/general/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace settings {

const std::string engine_name = "Winter";
const std::string engine_version = "0.4.1";
const std::string engine_version = "0.4.2";
const std::string engine_author = "Jonathan Rosenthal";

const int kNumClusters = 4;
Expand Down Expand Up @@ -70,6 +70,7 @@ const bool kUseScoreBasedPruning = true;
const bool kUseNullMoves = true && kUseExtensions;
const Depth kRepsForDraw = 2;
const Depth kMaxDepth = 128;
const Depth kSingularExtensionDepth = 9;

const bool kUseQS = true;

Expand Down
39 changes: 36 additions & 3 deletions src/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ inline void bookkeeping_log(int NodeType, const Board &board, Move tt_entry,
}
}

bool move_is_singular(Thread &t, const Depth depth, const std::vector<Move> &moves, const table::Entry &entry);

template<int NodeType, int Mode>
Score AlphaBeta(Thread &t, Score alpha, Score beta, Depth depth, int expected_node = 1) {
assert(beta > alpha);
Expand Down Expand Up @@ -855,6 +857,18 @@ Score AlphaBeta(Thread &t, Score alpha, Score beta, Depth depth, int expected_no
moves_sorted = true;
}
const Move move = moves[i];

Depth e = 0;// Extensions
if (i == 0 && depth >= settings::kSingularExtensionDepth && valid_entry
&& entry.depth >= depth - 3 && !(NodeType == kPV && moves.size() == 1)
&& !is_mate_score(entry.get_score(t.board))) {
SortMovesML(moves, t, tt_entry);
moves_sorted = true;
if (move_is_singular(t, depth, moves, entry)) {
e = 1;
}
}

Depth reduction = 0;

if (!in_check && !(checking_squares[GetPieceType(t.board.get_piece(GetMoveSource(move)))]
Expand Down Expand Up @@ -890,14 +904,14 @@ Score AlphaBeta(Thread &t, Score alpha, Score beta, Depth depth, int expected_no
Score score;
if (i == 0) {
//First move gets searched at full depth and window
score = -AlphaBeta<NodeType, Mode>(t, -beta, -alpha, depth - 1, expected_node ^ 0x1);
score = -AlphaBeta<NodeType, Mode>(t, -beta, -alpha, depth - 1 + e, expected_node ^ 0x1);
}
else {
//Assume we have searched the best move already and search with closed window and possibly reduction
score = -AlphaBeta<kNW, Mode>(t, -(alpha+1), -alpha, depth - 1 - reduction, 1);
score = -AlphaBeta<kNW, Mode>(t, -(alpha+1), -alpha, depth - 1 + e - reduction, 1);
//Research with full depth if our initial search indicates an improvement over Alpha
if (score > alpha && (NodeType == kPV || reduction > 0)) {
score = -AlphaBeta<NodeType, Mode>(t, -beta, -alpha, depth - 1, 0);
score = -AlphaBeta<NodeType, Mode>(t, -beta, -alpha, depth - 1 + e, 0);
}
}
assert(score >= kMinScore && score <= kMaxScore);
Expand Down Expand Up @@ -948,6 +962,25 @@ Score AlphaBeta(Thread &t, Score alpha, Score beta, Depth depth, int expected_no
return alpha;
}

bool move_is_singular(Thread &t, const Depth depth, const std::vector<Move> &moves, const table::Entry &entry) {
const Score rBeta = entry.get_score(t.board) - 4 * depth;
const Score rAlpha = rBeta - 1;
const Depth rDepth = (depth + 1) / 3;
assert(!is_mate_score(rAlpha));
assert(entry.get_best_move() == moves[0]);
assert(entry.bound != kUpperBound);

for(size_t i = 1; i < moves.size(); i++) {
t.board.Make(moves[i]);
Score score = -AlphaBeta<kNW, kNormalSearchMode>(t, -rBeta, -rAlpha, rDepth);
t.board.UnMake();
if (score >= rBeta) {
return false;
}
}
return true;
}

template<int Mode>
Score RootSearchLoop(Thread &t, Score original_alpha, Score beta, Depth current_depth,
std::vector<Move> &moves) {
Expand Down

0 comments on commit f2a9593

Please sign in to comment.