Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: The Old way to detect 3fold repetition (help needed)

Author: Paul

Date: 06:53:55 03/26/01

Go up one level in this thread


And the message you probably mean is 119911 (now isn't that a nice number :),
written by John Stanback:

****************************************************************************
Here is a routine that I used in gnuchess a long time ago.  The
variable "cnt" contains the number of repetitions of the current
position (P).  GameCnt is the ply number of current position, including
game history and current search path.  Game50 is the last irrersable
move.  GameList[] contains all the game+search moves.
Initially the array b[] is zero'd.  Then the GameList[] array is
followed backward until the last non-reversible move
and b[f] is incremented and b[t] is decremented.  Variable c contains
a count of the number squares which are different from board position P.
If c == 0 it means that the board position in the loop matches
position P and *cnt is incremented.  I think there are some rare cases
where this doesn't work quite right, but it worked fine in practice.
It doesn't slow down the search because typically there has been
an irreversible move recently so that GameCnt <= Game50+3.


John



repetition(int *cnt)
{
int i,c,f,t;
unsigned char b[64];
unsigned int m;

  *cnt = c = 0;
  if (GameCnt > Game50+3)
    {
      for (i = 0; i < 64; b[i++] = 0);
      for (i = GameCnt; i > Game50; i--)
        {
          m = GameList[i].gmove;
          f = m>>8;
          t = m&0xFF;
          if (++b[f] == 0) c--; else c++;
          if (--b[t] == 0) c--; else c++;
          if (c == 0) (*cnt)++;
        }
    }
}
****************************************************************************

Hope this is it ...
Paul



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.