else
{
if ( newDepth >= 3*OnePly
- && i >= MultiPV + LMRPVMoves - 2 // Remove -2 and decrease LMRPVMoves instead ?
+ && i >= MultiPV + LMRPVMoves
&& !dangerous
&& !moveIsCapture
&& !move_is_promotion(move)
// Initialize a MovePicker object for the current position, and prepare
// to search all moves
- MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
-
Move move, movesSearched[256];
int moveCount = 0;
Value value, bestValue = -VALUE_INFINITE;
- Bitboard dcCandidates = mp.discovered_check_candidates();
Color us = pos.side_to_move();
bool isCheck = pos.is_check();
bool mateThreat = pos.has_mate_threat(opposite_color(us));
+ MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
+ Bitboard dcCandidates = mp.discovered_check_candidates();
+
// Loop through all legal moves until no moves remain or a beta cutoff
// occurs.
while ( alpha < beta
{
assert(move_is_ok(move));
- bool singleReply = (isCheck && mp.number_of_moves() == 1);
+ bool singleReply = (isCheck && mp.number_of_evasions() == 1);
bool moveIsCheck = pos.move_is_check(move, dcCandidates);
bool moveIsCapture = pos.move_is_capture(move);
bool mateThreat = false;
bool isCheck = pos.is_check();
- bool useNullMove = ( allowNullmove
- //&& depth > OnePly
- && !isCheck
- && !value_is_mate(beta)
- && ok_to_do_nullmove(pos)
- && approximateEval >= beta - NullMoveMargin);
+ // Null move search
+ if ( allowNullmove
+ && depth > OnePly
+ && !isCheck
+ && !value_is_mate(beta)
+ && ok_to_do_nullmove(pos)
+ && approximateEval >= beta - NullMoveMargin)
+ {
+ ss[ply].currentMove = MOVE_NULL;
+
+ StateInfo st;
+ pos.do_null_move(st);
+ int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction
+
+ Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
+
+ pos.undo_null_move();
+ if (nullValue >= beta)
+ {
+ if (depth < 6 * OnePly)
+ return beta;
+
+ // Do zugzwang verification search
+ Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID);
+ if (v >= beta)
+ return beta;
+ } else {
+ // The null move failed low, which means that we may be faced with
+ // some kind of threat. If the previous move was reduced, check if
+ // the move that refuted the null move was somehow connected to the
+ // move which was reduced. If a connection is found, return a fail
+ // low score (which will cause the reduced move to fail high in the
+ // parent node, which will trigger a re-search with full depth).
+ if (nullValue == value_mated_in(ply + 2))
+ mateThreat = true;
+
+ ss[ply].threatMove = ss[ply + 1].currentMove;
+ if ( depth < ThreatDepth
+ && ss[ply - 1].reduction
+ && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove))
+ return beta - 1;
+ }
+ }
// Null move search not allowed, try razoring
- if ( !useNullMove
- && !value_is_mate(beta)
- && depth < RazorDepth
- && approximateEval < beta - RazorApprMargins[int(depth) - 2]
- && ss[ply - 1].currentMove != MOVE_NULL
- && ttMove == MOVE_NONE
- && !pos.has_pawn_on_7th(pos.side_to_move()))
+ else if ( !value_is_mate(beta)
+ && depth < RazorDepth
+ && approximateEval < beta - RazorApprMargins[int(depth) - 2]
+ && ss[ply - 1].currentMove != MOVE_NULL
+ && ttMove == MOVE_NONE
+ && !pos.has_pawn_on_7th(pos.side_to_move()))
{
Value v = qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
if (v < beta - RazorMargins[int(depth) - 2])
// Initialize a MovePicker object for the current position, and prepare
// to search all moves.
- MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply], useNullMove);
+ MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
Move move, movesSearched[256];
int moveCount = 0;
&& (move = mp.get_next_move()) != MOVE_NONE
&& !thread_should_stop(threadID))
{
-
- // Null move search
- if (move == MOVE_NULL)
- {
- ss[ply].currentMove = MOVE_NULL;
-
- StateInfo st;
- pos.do_null_move(st);
- int R = (depth >= 5 * OnePly ? 4 : 3); // Null move dynamic reduction
-
- Value nullValue = -search(pos, ss, -(beta-1), depth-R*OnePly, ply+1, false, threadID);
-
- pos.undo_null_move();
-
- if (nullValue >= beta)
- {
- if (depth < 6 * OnePly)
- return beta;
-
- // Do zugzwang verification search
- Value v = search(pos, ss, beta, depth-5*OnePly, ply, false, threadID);
- if (v >= beta)
- return beta;
- } else {
- // The null move failed low, which means that we may be faced with
- // some kind of threat. If the previous move was reduced, check if
- // the move that refuted the null move was somehow connected to the
- // move which was reduced. If a connection is found, return a fail
- // low score (which will cause the reduced move to fail high in the
- // parent node, which will trigger a re-search with full depth).
- if (nullValue == value_mated_in(ply + 2))
- mateThreat = true;
-
- ss[ply].threatMove = ss[ply + 1].currentMove;
- if ( depth < ThreatDepth
- && ss[ply - 1].reduction
- && connected_moves(pos, ss[ply - 1].currentMove, ss[ply].threatMove))
- return beta - 1;
- }
- continue;
- }
-
assert(move_is_ok(move));
- bool singleReply = (isCheck && mp.number_of_moves() == 1);
+ bool singleReply = (isCheck && mp.number_of_evasions() == 1);
bool moveIsCheck = pos.move_is_check(move, dcCandidates);
bool moveIsCapture = pos.move_is_capture(move);
staticValue = tte->value();
}
else
+ {
staticValue = evaluate(pos, ei, threadID);
+ if (!value_is_mate(staticValue + Value(ply)))
+ staticValue += Value(ply);
+ }
if (ply == PLY_MAX - 1)
return evaluate(pos, ei, threadID);
bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
// Generate all legal moves
- int lm_count = generate_legal_moves(pos, mlist);
+ MoveStack* last = generate_legal_moves(pos, mlist);
// Add each move to the moves[] array
- for (int i = 0; i < lm_count; i++)
+ for (MoveStack* cur = mlist; cur != last; cur++)
{
bool includeMove = includeAllMoves;
for (int k = 0; !includeMove && searchMoves[k] != MOVE_NONE; k++)
- includeMove = (searchMoves[k] == mlist[i].move);
+ includeMove = (searchMoves[k] == cur->move);
if (!includeMove)
continue;
StateInfo st;
SearchStack ss[PLY_MAX_PLUS_2];
- moves[count].move = mlist[i].move;
+ moves[count].move = cur->move;
pos.do_move(moves[count].move, st);
moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, Depth(0), 1, 0);
pos.undo_move(moves[count].move);
// Case 5: Discovered check, checking piece is the piece moved in m1
if ( piece_is_slider(pos.piece_on(t1))
&& bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
- && !bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())), t2))
+ && !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2))
{
Bitboard occ = pos.occupied_squares();
Color us = pos.side_to_move();