Code: Select all
/* check to see if we can get a quick cutoff from our null move: */
if (null_score >= beta)
return beta;
if (null_score < -INF+10*maxdepth)
extensions++;
}
}
/* generate and order moves: */
gen (&moves[0], &num_moves);
order_moves (&moves[0], &move_ordering[0], num_moves, &h_move);
/* loop through the moves at the current node: */
while (remove_one (&i, &move_ordering[0], num_moves)) {
make (&moves[0], i);
assert (cur_pos.x1 == compute_hash ().x1 &&
cur_pos.x2 == compute_hash ().x2);
ply++;
legal_move = FALSE;
if (moves_searched == 0) {
/* go deeper if it's a legal move: */
if (check_legal (&moves[0], i)) {
nodes++;
score = -search (-beta, -alpha, depth-1+extensions, TRUE);
/* Late Move Reductions */
}
else
{
if (moves_searched >= FullDepthMoves && depth >= ReductionLimit) {
score = -search (-alpha-1, -alpha, depth-2, TRUE);
}
else score = alpha+1;
/* PVS */
if (score > alpha) {
score = -search(-alpha-1, -alpha, depth-1+extensions, TRUE);
if (score > alpha && score < beta)
score = -search(-beta, -alpha, depth-1+extensions, TRUE);
}
}
}
else {
if (check_legal (&moves[0], i)) {
nodes++;
score = -search (-beta, -alpha, depth-1+extensions, TRUE);
no_moves = FALSE;
legal_move = TRUE;
}
}
}
moves_searched++;
ply--;
unmake (&moves[0], i);
ep_square = ep_temp;
cur_pos = temp_hash;
/* return if we've run out of time: */
if (time_exit) return 0;
/* check our current score vs. alpha: */
if (score > alpha && legal_move) {
/* update the history heuristic since we have a cutoff: */
history_h[moves[i].from][moves[i].target] += depth;
/* try for an early cutoff: */
if (score >= beta) {
u_killers (moves[i], score);
store_hash (i_alpha, depth, score, l_bound, moves[i]);
return beta;
}
alpha = score;
/* update the pv: */
pv[ply][ply] = moves[i];
for (j = ply+1; j < pv_length[ply+1]; j++)
pv[ply][j] = pv[ply+1][j];
pv_length[ply] = pv_length[ply+1];
}
/* check for mate / stalemate: */
if (no_moves) {
if (in_check ()) {
alpha = -INF+ply;
}
else {
alpha = 0;
}
}
else {
/* check the 50 move rule if no mate situation is on the board: */
if (fifty > 100) {
return 0;
}
}
/* store our hash info: */
if (alpha > i_alpha)
store_hash (i_alpha, depth, alpha, exact, pv[ply][ply]);
else
store_hash (i_alpha, depth, alpha, u_bound, dummy);
return alpha;
}
move_s search_root (int alpha, int beta, int depth) {
/* search the root node using alpha-beta with negamax search */