- // check_is_dangerous() tests if a checking move can be pruned in qsearch().
- // bestValue is updated only when returning false because in that case move
- // will be pruned.
+ // value_to_tt() adjusts a mate score from "plies to mate from the root" to
+ // "plies to mate from the current position". Non-mate scores are unchanged.
+ // The function is called before storing a value to the transposition table.
+
+ Value value_to_tt(Value v, int ply) {
+
+ assert(v != VALUE_NONE);
+
+ return v >= VALUE_MATE_IN_MAX_PLY ? v + ply
+ : v <= VALUE_MATED_IN_MAX_PLY ? v - ply : v;
+ }
+
+
+ // value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
+ // from the transposition table (where refers to the plies to mate/be mated
+ // from current position) to "plies to mate/be mated from the root".
+
+ Value value_from_tt(Value v, int ply) {
+
+ return v == VALUE_NONE ? VALUE_NONE
+ : v >= VALUE_MATE_IN_MAX_PLY ? v - ply
+ : v <= VALUE_MATED_IN_MAX_PLY ? v + ply : v;
+ }
+
+
+ // check_is_dangerous() tests if a checking move can be pruned in qsearch()