|
21 | 21 | #include <cassert> |
22 | 22 | #include <cmath> |
23 | 23 | #include <cstring> |
24 | | -#include <exception> |
25 | 24 | #include <iostream> |
26 | 25 | #include <sstream> |
27 | 26 |
|
@@ -105,8 +104,6 @@ namespace { |
105 | 104 | bool refutes(const Position& pos, Move first, Move second); |
106 | 105 | string uci_pv(const Position& pos, int depth, Value alpha, Value beta); |
107 | 106 |
|
108 | | - class stop : public std::exception {}; |
109 | | - |
110 | 107 | struct Skill { |
111 | 108 | Skill(int l) : level(l), best(MOVE_NONE) {} |
112 | 109 | ~Skill() { |
@@ -359,9 +356,7 @@ namespace { |
359 | 356 | // research with bigger window until not failing high/low anymore. |
360 | 357 | while (true) |
361 | 358 | { |
362 | | - try { |
363 | | - bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false); |
364 | | - } catch (stop&) {} |
| 359 | + bestValue = search<Root>(pos, ss, alpha, beta, depth * ONE_PLY, false); |
365 | 360 |
|
366 | 361 | // Bring to front the best move. It is critical that sorting is |
367 | 362 | // done with a stable algorithm because all the values but the first |
@@ -546,13 +541,10 @@ namespace { |
546 | 541 | if (PvNode && thisThread->maxPly < ss->ply) |
547 | 542 | thisThread->maxPly = ss->ply; |
548 | 543 |
|
549 | | - if (Signals.stop || thisThread->cutoff_occurred()) |
550 | | - throw stop(); |
551 | | - |
552 | 544 | if (!RootNode) |
553 | 545 | { |
554 | 546 | // Step 2. Check for aborted search and immediate draw |
555 | | - if (pos.is_draw() || ss->ply > MAX_PLY) |
| 547 | + if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) |
556 | 548 | return DrawValue[pos.side_to_move()]; |
557 | 549 |
|
558 | 550 | // Step 3. Mate distance pruning. Even if we mate at the next move our score |
@@ -1007,6 +999,13 @@ namespace { |
1007 | 999 | alpha = splitPoint->alpha; |
1008 | 1000 | } |
1009 | 1001 |
|
| 1002 | + // Finished searching the move. If Signals.stop is true, the search |
| 1003 | + // was aborted because the user interrupted the search or because we |
| 1004 | + // ran out of time. In this case, the return value of the search cannot |
| 1005 | + // be trusted, and we don't update the best move and/or PV. |
| 1006 | + if (Signals.stop || thisThread->cutoff_occurred()) |
| 1007 | + return value; // To avoid returning VALUE_INFINITE |
| 1008 | + |
1010 | 1009 | if (RootNode) |
1011 | 1010 | { |
1012 | 1011 | RootMove& rm = *std::find(RootMoves.begin(), RootMoves.end(), move); |
@@ -1697,27 +1696,22 @@ void Thread::idle_loop() { |
1697 | 1696 |
|
1698 | 1697 | activePosition = &pos; |
1699 | 1698 |
|
1700 | | - try { |
1701 | | - switch (sp->nodeType) { |
1702 | | - case Root: |
1703 | | - search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
1704 | | - break; |
1705 | | - case PV: |
1706 | | - search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
1707 | | - break; |
1708 | | - case NonPV: |
1709 | | - search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
1710 | | - break; |
1711 | | - default: |
1712 | | - assert(false); |
1713 | | - } |
1714 | | - |
1715 | | - assert(searching); |
1716 | | - } |
1717 | | - catch (stop&) { |
1718 | | - sp->mutex.lock(); // Exception is thrown out of lock |
| 1699 | + switch (sp->nodeType) { |
| 1700 | + case Root: |
| 1701 | + search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
| 1702 | + break; |
| 1703 | + case PV: |
| 1704 | + search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
| 1705 | + break; |
| 1706 | + case NonPV: |
| 1707 | + search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode); |
| 1708 | + break; |
| 1709 | + default: |
| 1710 | + assert(false); |
1719 | 1711 | } |
1720 | 1712 |
|
| 1713 | + assert(searching); |
| 1714 | + |
1721 | 1715 | searching = false; |
1722 | 1716 | activePosition = NULL; |
1723 | 1717 | sp->slavesMask &= ~(1ULL << idx); |
|
0 commit comments