2

I am developing a program that analyzes games sequentially, i.e. one game after another.

Below are the parameters.


Engine: Stockfish 10

Threads: 2

Hash Table: 4000

Depth: 30


My question is about when to use the command: "setoption name Clear Hash."

Should it be used after each position is analysed? This means that each position would have a "fresh" hash at the beginning of the analysis.

Or should it be used after each game is analysed? What are the differences?

3 Answers 3

4

If your goal is to get the highest quality of analysis, then the short answer is "never".

The reason is that if you analyze similar positions within a game, then the existing hash table entries can still be valuable for move ordering and evaluation, because the same positions might be encountered somewhere in the search tree again.

If you switch to a new game, then the hash should be cleared, but in that case Stockfish already does it implicitly when it receives the ucinewgame command. In fact, in Stockfish ucinewgame does exactly the same as setoption name Clear Hash.

1

A hash table is used to store evaluations/information for a position, so that evaluating it later is either instantaneous or much more efficient. If you let your engine think on a certain position for a while, the positions it thinks of when searching ahead are stored in its table. This is useful when you make a move on the current position and reach a new position for Stockfish to analyse (since its already "seen" it in its analysis).

So when analyzing a certain game, do not reset the hash table. You could reset it when moving on to a new game though, especially if the new game starts off with different opening moves than the previous game. This is because most/all of the positions analysed in the previous game will be irrelevant, and will just take up space in the hash table.

2
  • The hash table should be cleared when performing benchmarks, so previous tests do not affect future tests?
    – qwr
    Sep 19, 2022 at 3:46
  • @qwr I think that depends. E.g., if you're benchmarking individual moves, then clearing and initializing the hash table on each move could take up a chunk of the measured time. But if each run of your test is fairly long, then resetting the TT makes sense (although even then Stockfish should, on its own, get rid of data it no longer needs in the TT quite fast). Sep 19, 2022 at 8:10
1

If you want to analyze a single game, IMHO the cleanest and best solution is to do that, as if stockfish would play a game against some other opponent, apart from the time control. Since this resembles the way, stockfish is tested and will always work. Note that it is important to command

position startpos moves  .... 

and not

 position <fen>  

since the latter form messes up repetitions and the 50 move rule (UCI is stateless). If you are unsure, simple let Arena or cutechess-cli play a single game for you with stockfish having logging enabled and then inspect the head of that logfile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.