From a406eed1f64a668ef4ff7f56248be59cb119936d Mon Sep 17 00:00:00 2001 From: lucasart Date: Fri, 25 Sep 2015 18:46:16 +0800 Subject: [PATCH] aspiration windows ./demolito search 3 1 -> 3191829 nodes This exposes a search bug. In its current state, the search should not have any instability: . . . . . . . . . . p . . . . . . . . p . . . . K P . . . . . r . R . . . p . k . . . . . . . . . . . . P . P . . . . . . . . . 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 depth=2 alpha=-16 beta=16 score=71 depth=2 alpha=0 beta=32 score71 depth=2 alpha=16 beta=64 score=71 depth=2 alpha=40 beta=128 score=0 depth=2 alpha=-88 beta=84 score=0 --- src/search.cc | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/search.cc b/src/search.cc index bc78795..7f3818b 100644 --- a/src/search.cc +++ b/src/search.cc @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License along with this program. If * not, see . */ +#include #include #include #include @@ -127,10 +128,35 @@ int recurse(const Position& pos, int ply, int depth, int alpha, int beta, Move * return bestScore; } +int aspirate(const Position& pos, int depth, Move *pv, int score) +{ + int delta = 16; + int alpha = score - delta; + int beta = score + delta; + + for ( ; ; delta += delta) { + score = recurse(pos, 0, depth, alpha, beta, pv); + std::cout << "depth=" << depth + << "\talpha=" << alpha + << "\tbeta=" << beta + << "\tscore" << score + << std::endl; + if (score <= alpha) { + beta = (alpha + beta) / 2; + alpha -= delta; + } else if (score >= beta) { + alpha = (alpha + beta) / 2; + beta += delta; + } else + return score; + } +} + void iterate(const Position& pos, const Limits& lim, UCI::Info& ui, int threadId) { ThreadId = threadId; Move pv[MAX_PLY + 1]; + int score; for (int depth = 1; depth <= lim.depth; depth++) { { @@ -141,9 +167,10 @@ void iterate(const Position& pos, const Limits& lim, UCI::Info& ui, int threadId signal &= ~(1ULL << ThreadId); } - int score; try { - score = recurse(pos, 0, depth, -INF, +INF, pv); + score = depth <= 1 + ? recurse(pos, 0, depth, -INF, +INF, pv) + : aspirate(pos, depth, pv, score); // Iteration was completed normally. Now we need to see who is working on // obsolete iterations, and raise the appropriate signal, to make them move