PLEASE HELP with MATING scores adjustments in TT
Posted: Sun Sep 20, 2020 3:37 pm
Hi guys
I'm incredibly suffering from a dumbness to understand how the mating scores
are handled within a TT. Here's the implementation I came up with.
QUESTION 1: Is this correct? (It seems like it's working, at least finds mates)
...
so
INFINITY = 50000
MATED_VALUE = 49000
MATE_SCORE = 48000
and the values for mating scores are within a range from 48000 to 49000
I'm using FAIL-HARD framework.
I'm confused by the logic of adding and substracting plies.
I'm referencig this post by Harald as a source of theory:
49000 - mate in 0
48999 - mate in 1
...
48992 - mate in 8
than instead of storing 48992 we actually store 48992 - 5 = 48987
and then restore it back when reading TT via 48987 + 5 = 48992
QUESTION 2: If above is TRUE (it seems for it works) then WHY this works??????
Please explain as if you were explaining to idiot.
I'm incredibly suffering from a dumbness to understand how the mating scores
are handled within a TT. Here's the implementation I came up with.
QUESTION 1: Is this correct? (It seems like it's working, at least finds mates)
Code: Select all
// read hash entry data
static inline int read_hash_entry(int alpha, int beta, int depth)
{
// create a TT instance pointer to particular hash entry storing
// the scoring data for the current board position if available
tt *hash_entry = &hash_table[hash_key % hash_size];
// extract current score from hash entry
int score = hash_entry->score;
// make sure we're dealing with the exact position we need
if (hash_entry->hash_key == hash_key)
{
// make sure that we match the exact depth our search is now at
if (hash_entry->depth >= depth)
{
int score = hash_entry->score;
if (score < -48000) score += ply;
if (score > 48000) score -= ply;
// match the exact (PV node) score
if (hash_entry->flag == hash_flag_exact)
// return exact (PV node) score
return score;
// match alpha (fail-low node) score
if ((hash_entry->flag == hash_flag_alpha) &&
(score <= alpha))
// return alpha (fail-low node) score
return alpha;
// match beta (fail-high node) score
if ((hash_entry->flag == hash_flag_beta) &&
(score >= beta))
// return beta (fail-high node) score
return beta;
}
}
// if hash entry doesn't exist
return no_hash_entry;
}
// write hash entry data
static inline void write_hash_entry(int score, int depth, int hash_flag)
{
// create a TT instance pointer to particular hash entry storing
// the scoring data for the current board position if available
tt *hash_entry = &hash_table[hash_key % hash_size];
if (score > 48000) score -= ply;
if (score < -48000) score += ply;
// write hash entry data
hash_entry->hash_key = hash_key;
hash_entry->score = score;
hash_entry->flag = hash_flag;
hash_entry->depth = depth;
}
...
// here's how I score mated value
if (legal_moves == 0)
{
// king is in check
if (in_check)
// return mating score (assuming closest distance to mating position)
return -49000 + ply;
// king is not in check
else
// return stalemate score
return 0;
}
so
INFINITY = 50000
MATED_VALUE = 49000
MATE_SCORE = 48000
and the values for mating scores are within a range from 48000 to 49000
I'm using FAIL-HARD framework.
I'm confused by the logic of adding and substracting plies.
I'm referencig this post by Harald as a source of theory:
It seems like if we have a score of say mate in 8 at ply 5Writing TT:
if current score > MATE_SCORE store score - ply
if current score < -MATE_SCORE store score + ply
Reading TT:
if stored score > MATE_SCORE return score + ply
if stored score < -MATE_SCORE return score - ply
49000 - mate in 0
48999 - mate in 1
...
48992 - mate in 8
than instead of storing 48992 we actually store 48992 - 5 = 48987
and then restore it back when reading TT via 48987 + 5 = 48992
QUESTION 2: If above is TRUE (it seems for it works) then WHY this works??????
Please explain as if you were explaining to idiot.