Code: Select all
long int chk_hash(int alpha, int beta, int depth, int *type, move_s *move) {
/* see what info we can get from our hash tables for the current
position. This could be a value we can return, a suggested move, or
even just a warning not to use null search in this position */
hash_s *hash_p;
long int score;
s_int h_depth, flag;
d_long hash;
*type = no_info;
*move = dummy;
/* lookup our hash: */
hash_p = hash_table + (hash_mask & cur_pos.x1);
hash = hash_p->hash;
if (hash.x1 == cur_pos.x1 && hash.x2 == cur_pos.x2) {
/* get info from the hash: */
*move = hash_p->move;
score = hash_p->score;
h_depth = hash_p->depth;
flag = hash_p->flag;
/* adjust our score if it is a mate score: */
if (abs(score) > INF - 100) {
if (score > 0)
score -= (ply);
else
score += (ply);
}
/* see if we should avoid null moves: */
if (h_depth >= depth - null_red && score < beta && flag == u_bound)
*type = avoid_null;
/* check what info we can get from our hash: */
if (h_depth >= depth) {
switch (flag) {
case u_bound:
if (score <= alpha) {
*type = u_bound;
return (alpha);
}
break;
case l_bound:
if (score >= beta) {
*type = l_bound;
return (beta);
}
break;
case exact:
*type = exact;
return (score);
break;
}
}
}
return (0);
}