Casper W. Berg wrote:The fact that many of the legal moves on one side of the board are the same between turns has made me wonder if it could payoff to keep track of which ones could be reused and thereby save some computation time.
I figure it might be dependant on the engine, e.g. if you use rotated bitboards or a more primitive data structure.
I keep track of all threatened squares in my own program, and I reuse that information in situations where the threats haven't changed for the player who didn't make the last move, i.e. the pieces haven't moved. This gave me a significant speedup!
I imagine something like ruling out files and diagonals (including the kings' to avoid checking problems) for reuse for each move made on the board. That combined with keeping track of each piece's legal moves could make up such an algorithm, but the question is if the bookkeeping is worth it...
Does anyone have any experiences with something like that?
It sounds like you want to implement something like I heard about which is a set of rules that determine for any given board position after the last move which pieces (for both sides) have to have their moves and/or attack maps updated.
The point being that you run these rules, determine the affected pieces,
delete their moves and entries from the move list and attack maps
and then regenerate both for just those pieces.
This seemed to me like a good idea when I first heard of it. I don't
recall if it was Slate/Atkin in Chess 4.x or Frey/Slate in Chess 0.5
or whatever, but it seemed decent.
I know of no published papers that compares the cost of such
(re) generation with a standard move generator searching through
the piecelist and regenerating the move list and attack maps fresh
each time.
Some choose instead to just generate a few moves at a time and
see if a cutoff can be achieved before more moves need to be
generated.
Again, I know of no studies comparing incremental update/downdate
of movelists/attackmaps with non-incremental with simply partially
generating moves in a fragmented series with searches inbetween.
Part of the issue is the complexity of doing the comparison, choosing
how to compare, since the search would be involved in the last of
the three above.
Stuart