+ // ok_to_use_TT() returns true if a transposition table score
+ // can be used at a given point in search.
+
+ bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply) {
+
+ Value v = value_from_tt(tte->value(), ply);
+
+ return ( tte->depth() >= depth
+ || v >= Max(value_mate_in(100), beta)
+ || v < Min(value_mated_in(100), beta))
+
+ && ( (is_lower_bound(tte->type()) && v >= beta)
+ || (is_upper_bound(tte->type()) && v < beta));
+ }
+
+
+ // ok_to_history() returns true if a move m can be stored
+ // in history. Should be a non capturing move.
+
+ bool ok_to_history(const Position& pos, Move m) {
+
+ return pos.square_is_empty(move_to(m))
+ && !move_promotion(m)
+ && !move_is_ep(m);
+ }
+
+
+ // update_history() registers a good move that produced a beta-cutoff
+ // in history and marks as failures all the other moves of that ply.
+
+ void update_history(const Position& pos, Move m, Depth depth,
+ Move movesSearched[], int moveCount) {
+
+ H.success(pos.piece_on(move_from(m)), m, depth);
+
+ for (int i = 0; i < moveCount - 1; i++)
+ if (ok_to_history(pos, movesSearched[i]) && m != movesSearched[i])
+ H.failure(pos.piece_on(move_from(movesSearched[i])), movesSearched[i]);
+ }
+