Fifty move counter and Null move

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tomitank
Posts: 276
Joined: Sat Mar 04, 2017 12:24 pm
Location: Hungary

Fifty move counter and Null move

Post by tomitank »

Hi!

Senpai and Fruit set the fifty move counter = 0 before null move and copy from history after null move.

Code: Select all

   void move_null() {
     //..........
      p_copy.moves = 0; // HACK: conversion
     //..........
   }
So not detecting draw.

Code: Select all

      for &#40;int i = 4; i < p_copy.moves; i += 2&#41; &#123;
         if &#40;p_stack&#91;p_sp - i&#93;.copy.key == key&#41; &#123;
            return true;
         &#125;
      &#125;
Stockfish and Sungorus increase the fifty move counter by 1 before null move and decrease after null move.

Code: Select all

void Position&#58;&#58;do_null_move&#40;StateInfo& newSt&#41; &#123;
    //..........
  ++st->rule50;
   //...........
&#125;

Code: Select all

  for &#40;int i = 2, e = std&#58;&#58;min&#40;st->rule50, st->pliesFromNull&#41;; i <= e; i += 2&#41;
  &#123;
      stp = stp->previous->previous;

      if &#40;stp->key == st->key&#41;
          return true; // Draw at first repetition
  &#125;

Which one is correct?

I think stockfish and sungorus good, but then "Senpai" is wrong?

Apropo: I do not see this in many engines.

-Tamas
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Fifty move counter and Null move

Post by Robert Pope »

Personally, I don't think it makes a lot of sense to zero it with a null move. You haven't done something irreversible like capturing a piece.

However, since null-moves aren't legal and won't happen in the game, I think it just comes down to which gives better results in matches.
syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: Fifty move counter and Null move

Post by syzygy »

Robert Pope wrote:However, since null-moves aren't legal and won't happen in the game, I think it just comes down to which gives better results in matches.
I fully agree.

The Stockfish approach makes the most sense to me:
- do not detect draw-by-repetiion across a nullmove, but
- do detect draw by 50-move rule if no progress is being made even if the current branch includes nullmoves.

But, as already stated, what is best depends on how well it works in real games.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Fifty move counter and Null move

Post by hgm »

I guess the resetting of the 50-move counter on null move was originally done in engines where this counter also decided how far back in the move history it looks for repetitions. With normal moves you cannot repeat positions from before the last irreversible move. Resetting the counter on null move was just a kludge to use this mechanism for ignoring null-move-spanning repeats. It was not really intended to fool the engine into thinking it could dodge 50-move draws by null-moving.