Next: Ko, Previous: Hashing, Up: Tactical Reading
Some calculations can be safely saved from move to move. If the opponent's move is not close to our worm or dragon, we do not have to reconsider the life or death of that group on the next move. So the result is saved in a persistent cache. Persistent caches are used for are used in the engine for several types of read results.
In this section we will discuss the persistent caching of tactical reading but the same principles apply to the other persistent caches.
Persistent caching is an important performance feature. However it can lead to mistakes and debugging problems—situations where GNU Go generates the right move during debugging but plays a wrong move during a game. If you suspect a persistent cache effect you may try loading the sgf file with the --replay option and see if the mistake is repeated (see Invoking GNU Go).
The function store_persistent_cache()
is called only
by attack
and find_defense
, never from their
static recursive counterparts do_attack
and do_defend
.
The function store_persistent_reading_cache()
attempts to
cache the most expensive reading results. The function
search_persistent_reading_cache
attempts to retrieve a
result from the cache.
If all cache entries are occupied, we try to replace the least useful one. This is indicated by the score field, which is initially the number of nodes expended by this particular reading, and later multiplied by the number of times it has been retrieved from the cache.
Once a (permanent) move is made, a number of cache entries immediately become
invalid. These are cleaned away by the function
purge_persistent_reading_cache().
To have a criterion
for when a result may be purged, the function
store_persistent_cache()
computes the
reading shadow and active area. If a permanent
move is subsequently played in the active area, the cached
result is invalidated. We now explain this algorithm in detail.
The reading shadow is the concatenation of all moves in all variations, as well as locations where an illegal move has been tried.
Once the read is finished, the reading shadow is expanded to the active area which may be cached. The intention is that as long as no stones are played in the active area, the cached value may safely be used.
Here is the algorithm used to compute the active area.
This algorithm is in the function store_persistent_reading_cache()
.
The most expensive readings so far are stored in the persistent cache.
attack1()
.