Skip to content

Commit

Permalink
aspiration windows
Browse files Browse the repository at this point in the history
./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
  • Loading branch information
lucasart committed Sep 25, 2015
1 parent 1acba90 commit a406eed
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License along with this program. If
* not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <thread>
#include <vector>
#include <chrono>
Expand Down Expand Up @@ -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<SEARCH>(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++) {
{
Expand All @@ -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<SEARCH>(pos, 0, depth, -INF, +INF, pv);
score = depth <= 1
? recurse<SEARCH>(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
Expand Down

0 comments on commit a406eed

Please sign in to comment.