return alpha;
}
int is_repetition() { return 0; }
int negamax(Stats *stats, const Board *board, int alpha, int beta, int depth) {
U64 bhash = board_hash(board);
int negamax(Stats *stats, int alpha, int beta, int depth) {
int pv_node = (beta - alpha) > 1;
HasheFlag flag = flagAlpha;
Move bestMove = {0};
Board copy;
if (stats->ply && is_repetition()) return 0;
stats->pv_length[stats->ply] = stats->ply;
int pv_node = (beta - alpha) > 1;
int score =
ttable_read(stats->ttable, bhash, alpha, beta, depth, stats->ply);
int score = ttable_read(stats, alpha, beta, depth);
if (stats->ply && score != TTABLE_UNKNOWN && !pv_node) return score;
stats->pv_length[stats->ply] = stats->ply;
if (stats->ply && is_repetition()) return 0;
if (depth == 0) {
int score = quiescence(stats, board, alpha, beta);
ttable_write(stats->ttable, bhash, score, depth, stats->ply, flagExact);
int score = quiescence(stats, alpha, beta);
ttable_write(stats, score, depth, flagExact);
return score;
}
if (alpha < -MATE_VALUE) alpha = -MATE_VALUE;
if (beta > MATE_VALUE - 1) beta = MATE_VALUE - 1;
if (alpha >= beta) return alpha;
if (stats->ply > MAX_PLY - 1) return evaluate(board);
if (stats->ply > MAX_PLY - 1) return evaluate(stats->board);
stats->nodes++;
int isCheck = board_isCheck(board);
int isCheck = board_isCheck(stats->board);
if (isCheck) depth++;
Board copy;
if (depth >= 3 && !isCheck && stats->ply) {
board_copy(board, ©);
board_side_switch(©);
board_enpassant_set(©, no_sq);
stats->ply++;
score = -negamax(stats, ©, -beta, -beta + 1,
depth - 1 - REDUCTION_MOVE);
stats->ply--;
stats_move_make_pruning(stats, ©);
score = -negamax(stats, -beta, -beta + 1, depth - 1 - REDUCTION_MOVE);
stats_move_unmake(stats, ©);
if (score >= beta) return beta;
}
MoveList list;
move_list_generate(&list, board);
move_list_generate(&list, stats->board);
if (stats->follow_pv) enable_pv_scoring(stats, &list);
move_list_sort(stats, &list);