Repetition detection question

Discussion of chess software programming and technical issues.

Moderator: Ras

bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Repetition detection question

Post by bob »

Gerd Isenberg wrote:
bob wrote:
Gerd Isenberg wrote:
bob wrote: I simply set the 50 move counter back to zero after a null. I use this counter to limit how far back I search when looking for repetitions, and setting it to zero does not let me look back beyond the null-move to compare against positions that occurred prior to that point... It has always seemed to be the right way to do this, but it did get me to thinking about it...
I use following avoid repetition idea:
Before I start the usual repetition check at the very beginning of the search, I look whether the weaker side to move (beta <= DRAWSCORE) may force a direct repetition of moves by "unmaking" the last reversible move (ply-2) - while the stronger side already unmade move ply-3 at ply-1. That usually covers much more hits than the usual repetition test, also due detection of reps at horizon-nodes.

Code: Select all

if (   move50cnt >= 3
    && beta <= DRAW_SCORE
    && ply >= 3

    && move[ply-3].from == move[ply-1].to
    && move[ply-1].from == move[ply-3].to
    && move[ply-1].to isNotElement obstructed[move[ply-2].from][move[ply-2].to]
   )
       return DRAW_SCORE; // beta
The question is whether we can treat two consecutive nullmoves of the stronger side like making/unmaking a reversible move. It might be worth a try to avoid NULL by the stronger side if alfa >= DRAW_SCORE, after NULL and reversible move of the weaker side.
I've never tried imprecise repetition avoidance as you mention. The best counter example is two rooks on the 7th chasing the king back and forth. There the move two plies back does not necessarily get undone at the current ply, as the sequence could go rh7 Kg7 rg7 kf8 rf7 Ke8 Re8 Kd8 and that could repeat this same position reached several moves ago...

My repetition check takes no measurable amount of time, particularly when the loop is limited by the 50 move counter, so that I have simply never been inclined to add special-case code to avoid doing that which has no cost anyway...
This is a kind of redundant "pre"-make repetition detection. It is far from imprecise - if you accept rep-draws at second occurence with first occurence already inside the search tree. The additional precondition covers the most common rep-cases in search. Playing reversible 2. Rb1-a1 after 1. Ra1-b1 Ra8-b8 will not improve alfa, if already greater/equal draw score, since black has at least Rb8-a8. Interactions are covered by checking the obstruction as you may prove. The method might be redundant - but as said it get's draw-scores already the ply before making Rb8-a8, which one does not try at the horizon.

I mentioned it, because of the idea to treat pairs of consecutive nullmoves in the same way as making/unmaking reversible moves of the stronger side.
I understood the idea. My point was that I didn't see any advantage (for me) to add something that is less accurate (but frequent I agree) as a pre-condition to prevent me from entering the main rep check code. my RepetitionCheck() doesn't show up on the profile radar at present...
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Repetition detection question

Post by bob »

Gerd Isenberg wrote:
Gerd Isenberg wrote: The question is whether we can treat two consecutive nullmoves of the stronger side like making/unmaking a reversible move. It might be worth a try to avoid NULL by the stronger side if alfa >= DRAW_SCORE, after NULL and reversible move of the weaker side.
Alternately, instead of setting count50 to zero after NULL, one may xor hashkey accordantly so that only even numbers of nullmoves per side cancel each other.
I've used the 50 move rule counter since that is more efficient because I don't have to search backward thru the repetition list beyond the last null-move played...