Repetitions


 * Home * Search * Repetitions**
 * [[image:Reptiles.jpg width="257" height="225" link="http://www.mcescher.com/Gallery/back-bmp/LW327.jpg"]] ||~  || **Repetitions** of positions may happen during game play and inside the search of a chess program due to reversible moves played from both sides, which might be nullified in one or multiple further reversible moves. The player to move **may** claim a draw if the same position occurs **three** times, or will occur after an intended move, in any order, with the same player to move.

Two positions are considered same or equal, if all occupied squares and kind of pieces (not necessarily the same piece) they occupy are the same, the castling rights for both sides did not change, and no en passant capture was possible during the first occurrence, even if obviously not played. || toc =Assigning Draw Score= Threefold repetition implies a position occurred thrice, that is repeated twice. When to score the position as a draw, however, is an entirely different matter. Most programs do this on the first repetition, no matter whether the first occurrence of the repeated position appears in the current search space, or not. Other programs consider that fact, they avoid [|cycles] inside the current search tree to make it a [|directed acyclic graph] (DAG), but allow a one-fold repetition, if the first occurrence appears in the game history before the current root. Anyway, to wait for the second repetition one has its pros and cons. The Repetition score is either zero or the contempt factor.
 * M. C. Escher, Reptiles, 1943 ||~  ||^   ||

=Rules= The rules of chess state a [|threefold repetition] of a position gives the player to move the option to claim a draw, no matter whether the threefold repetition already occurred yet, or is about to occur after declaring the intended move in conjunction with the draw claim. The latter case is a bit tricky for computers, and is/was likely not strictly implemented in most programs or their user interfaces, since a draw message text or box appeared after the repetition occurs but no claim before. Since July 2014 a fivefold repetition is sufficient without any claim.

Fide Rule
> >

||

Since July 01, 2014
> >  ||

Former Rule
A former (German) rule, was believed to be sufficient to make the game of chess finite :



was proved not sufficient by Max Euwe in 1929 by applying the Prouhet–Thue–Morse Sequence, i. e. with following move indices : code 0:  Nb1-c3   Nb8-c6   Nc3-b1   Nc6-b8 1:  Ng1-f3   Ng8-f6   Nf3-g1   Nf6-g8 code Euwe's prove was the reason, two other rules in force each of which guarantees chess to be a finite game, [|threefold repetition] of positions and the fifty-move rule.  =Repetition of Positions= By position we mean the location of all the pieces on the Chessboard as well as castling rights and en passant status. Since the rule speaks about the piece position, and not their identity (i.e. artificially constructed repeated position where the rooks of one player changed places still would be a draw), repetition may be detected by using the Zobrist- or BCH signatures of the position.

Transposition Table
One possible implementation was used by Ken Thompson in Belle, who told Bruce Moreland that he detected repetitions by using the transposition hash table, as follows :

||

List of Keys
Most programs use an array or list of Zobrist- or BCH-keys and compare the current signature with keys 4, 6, 8 and so on plies along the actual variation. This is usually quite cheap, since testing often does not require looking through the entire list, since captures and pawn moves, that reset the halfmove clock for the purpose of enforcing fifty-move rule are known to make a repetition impossible. Since each thread or process may own its own copy of the game-record, this approach has also some merits in parallel search implementations.

John Stanback about his implementation in Zarkov : 

Dedicated Hash Table
Some programs, like Gerbil or Rookie use a separate small hash table, actually an implementation of a [|Bloom filter] revealed by Ronald de Man as mentioned by Marcel van Kervinck in his thesis //The design and implementation of the Rookie 2.0 Chess Playing Program// :  =Repetition of Moves= An alternative, pragmatical approach based on repetitions of moves was proposed by Vladan Vučković and Đorđe Vidanović in 2004, as implemented in Axon and discussed in CCC.

The algorithm needs a move list containing the game record including the variation actually searched, 16-bit entries with origin and target square, and a flag whether a move is irreversible, as only information required. Starting with the last move made, the list is scanned backwards as long there are reversible moves. A local concatenating list of up to 24 entries (one entry for each piece able to make reversible moves) is used to determine cycles per piece, where consecutive moves on their target squares are merged to one "pseudo" move, using the earliest origin and the latest target square. If all distinct white and black moving pieces in the chain list contain equal from- and to coordinates, all cycles of moves are closed and a move repetition is detected. This is how the algorithm as given in the paper in 8086 assembly looks in pseudo C++, square coordinates are offset from a 12*12 mailbox approach, so that empty entries have no valid square index. code format="cpp" bool repetition(SMove *pVariant) { SMove chainList[24], m;  short c = 0, i;

for (i=0; i < 24; ++i) { chainList[i].setEmpty; }

l: m = *pVariant--; /* fetch move and decrement move list pointer */ if ( m.isReversible ) { /* lookup chain list for from-coordinate that match current to coordinate */ for (i=0; i < 24; ++i) { if ( m.to == chainList[i].from ) { if ( m.from == chainList[i].to ) { if ( --c == 0 ) return true; /* repetition detected */ chainList[i].setEmpty; goto l;           } chainList[i].from = m.from; /* concatenate moves */ goto l;        } }     /* lookup for next empty slot, to add the current move in the chain list */ for (i=0; i < 24; ++i) { if ( chainList[i].isEmpty ) { chainList[i] = m;           ++c; goto l;        } }  }   return false; } code

=See also=
 * Contempt Factor
 * Desperado
 * Draw
 * Fifty-move Rule
 * Graph History Interaction (GHI)
 * Path-Dependency
 * Perpetual Check
 * Pursuit
 * Repetitions in Belzebub
 * Repetitions in SCP
 * Transposition
 * Transposition Table
 * Vice Video on Repetition

=Publications=

1929

 * Max Euwe (**1929**). //Mengentheoretische Betrachtungen über das Schachspiel//. Proc. Konin. Akad. Wetenschappen (Amsterdam)

1980 ...

 * Murray Campbell (**1985**). //[|The graph-history interaction: on ignoring position history]//. Computer Science Department, Carnegie Mellon University, Proceedings of the 1985 ACM annual conference, [|pdf]
 * Harry Nelson, Robert Hyatt (**1988**). //The Draw Heuristic of Cray Blitz//. ICCA Journal, Vol. 11, No. 1 » Cray Blitz

1990 ...

 * Dennis Breuker, Jaap van den Herik, Jos Uiterwijk, Victor Allis (**1999**). //A Solution to the GHI Problem for Best-First Search//. CG 1998 » Graph History Interaction, Best-First

2000 ...

 * Thomas Lincke (**2002**). //Exploring the Computational Limits of Large Exhaustive Search Problems//. Ph.D thesis, ETH Zurich, [|pdf], Chapter 4.3 Cycles
 * Vladan Vučković, Đorđe Vidanović (**2004**). //A New Approach to Draw Detection by Move Repetition in Computer Chess Programming.// [|CoRR arXiv:cs/0406038]
 * Akihiro Kishimoto, Martin Müller (**2004**). //A General Solution to the Graph History Interaction Problem//. AAAI National Conference, [|pdf]
 * Akihiro Kishimoto (**2005**). //Correct and Efficient Search Algorithms in the Presence of Repetitions//. Ph.D. thesis, University of Alberta, Received the 2005 ChessBase Best-Publication Award, [|pdf] » Proof-Number Search
 * Akihiro Kishimoto, Martin Müller (**2005**). //A Solution to the GHI Problem for Depth-First Proof-Number Search//. 7th Joint Conference on Information Sciences (JCIS2003), pp. 489 - 492, [|pdf] » Graph History Interaction
 * Daniel Andersson (**2009**). //Perfect-Information Games with Cycles//. Ph.D. thesis, [|Aarhus University], advisor Peter Bro Miltersen, [|pdf]

2010 ...

 * Marcel van Kervinck (**2013**). //A fast software-based method for upcoming cycle detection in search trees//. [|pdf preview]

=Forum Posts=

1990 ...

 * [|Repetition detection w/hash tables] by Bruce Moreland, rec.games.chess, August 14, 1993

1995 ...

 * [|Draw by Repetition Code] by cmayer, rgcc, December 31, 1996
 * [|Repetitions in Crafty] by Martin Borriss, rgcc, January 30, 1997 » Crafty
 * [|Perpetual check] by Ian Kennedy, rgcc, May 19, 1997
 * [|Handling of repetition (draw) in transposition table] by Bjarke Dahl Ebert, rgcc, June 9, 1997
 * [|triple repetition] by Daniel Kang, rgcc, October 26, 1997
 * [|draw by repetition and hash tables] by Werner Inmann, CCC, July 24, 1998
 * [|Problem with draws by rep and hash table] by James Robertson, CCC, October 07, 1999

2000 ...
> [|Re: Detecting three-fold repetition?] by John Stanback, CCC, July 17, 2000 » SCP Repetition detection
 * [|Detecting three-fold repetition?] by Tom Kerrigan, CCC, July 17, 2000
 * 2001**
 * [|The Old way to detect 3fold repetition (help needed)] by Gianluigi Masciulli, CCC, March 26, 2001
 * [|"Don't trust draw score" <=Is it true?] by Teerapong Tovirat, CCC, August 08, 2001 » Transposition Table, Path-Dependency
 * 2002**
 * [|Detecting Draws using a Small Hash Table?] by Steve Maughan, CCC, February 20, 2002
 * [|3 fold repetiton (Seacher v Postmodernist)] by Frank Phillips, CCC, March 02, 2002
 * [|A new(?) technique to recognize draws] by Heiner Marxen, CCC, June 01, 2002 » Perpetual Check, Corresponding Squares
 * [|Repetitions: is this code correct?] by Vladimir Medvedev, CCC, July 12, 2002
 * 2003**
 * [|Draw claims] by Thomas Mayer, CCC, June 17, 2003
 * [|In computer games 3-fold repetition should be AUTOMATICALLY draw!] by Jouni Uski, CCC, November 30, 2003
 * 2004**
 * [|perpetual check recognition] by Andreas Herrmann, CCC, January 30, 2004
 * [|A New Approach to Draw Detection by Move Repetition] by Gian-Carlo Pascutto, CCC, July 29, 2004
 * [|Draw Detection by Move Repetition Procedure - Comments] by Đorđe Vidanović, CCC, August 01, 2004
 * [|How to handle the first repetition correctly? (long)] by Sven Schüle, Winboard Forum, August 10, 2004
 * [|Repetition Detection] by Renze Steenhuisen, CCC, December 01, 2004
 * [|Perpetual check] by Alessandro Scotti, Winboard Forum, December 03, 2004

2005 ...

 * [|When to claim repetition and 50 move draws?] by Peter Hughes, Winboard Forum, March 26, 2005
 * [|draw by repetition] by Harm Geert Muller, Winboard Forum, November 21, 2005
 * 2007**
 * [|Handling 3-rep/50-move in hash tables] by Pradu Kannan, Winboard Forum, February 19, 2007
 * [|avoidrep-pruning] by Gerd Isenberg, CCC, May 15, 2007 » Pruning
 * 2008**
 * [|Problem with Transposition Table and Repitition-Draw] by Oliver Brausch, CCC, January 11, 2008 » Transposition Table
 * [|Again, rep-draws (and score aging)] by Harm Geert Muller, Winboard Forum, January 28, 2008
 * [|Repetition detection question] by Robert Hyatt, CCC, January 28, 2008
 * [|Repetition detection structure] by Mathieu Pagé, CCC, February 23, 2008
 * [|Semi-Path Dependent Hashing: a semi-useless idea] by Zach Wegner, CCC, May 24, 2008
 * [|Repetition Detection] by Colin, CCC, August 13, 2008
 * [|When and how to return a draw evaluation?] by Mathieu Pagé, CCC, August 26, 2008 » Draw
 * [|Draw by repetition when mate is possible] by Mathieu Pagé, CCC, December 30, 2008 » Checkmate
 * 2009**
 * [|wrong draw claim or right?] by Will Singleton, CCC, December 03, 2009
 * [|Stupid Extension Problem/Question] by John Merlino, CCC, December 23, 2009 » Extensions

2010 ...

 * [|Repetition Detection Without Hashing] by Levi Aho, CCC, February 13, 2010
 * [|nullmove and repetitive draw detection] by Edward Yu, CCC, June 20, 2010 » Null Move Pruning
 * [|bizarre repetition detection issue] by Robert Hyatt, CCC, November 04, 2010
 * 2011**
 * [|Repetitions/50 moves and TT] by Sergei Markoff, CCC, September 13, 2011
 * [|repetition detection] by Edmund Moshammer, CCC, October 29, 2011
 * 2012**
 * [|Draw by 3-fold repetition?] by Andy Duplain, CCC, January 06, 2012
 * [|Aquarium IDEA, repetitions, and minimax over cycles] by kevinfat, OpenChess Forum, September 17, 2012 » Aquarium
 * [|Why is this game not a draw?] by Carlos Pagador, CCC, October 29, 2012
 * [|Re: Move Tables - explain as if I'm five] by Karlo Bala Jr., CCC, November 05, 2012 » Repetitions in Belzebub
 * [|FIDE Rules] by crystalclear, Winboard Forum, December 11, 2012
 * 2013**
 * [|Half Move Clock Confusion] by HumbleProgrammer, OpenChess Forum, January 10, 2013 » Fifty-move Rule, Halfmove Clock
 * [|Repetition check] by Harm Geert Muller, CCC, March 29, 2013
 * [|Upcoming repetition detection] by Marcel van Kervinck, OpenChess Forum, April 06, 2013
 * [|Stockfish bug] by Steven Atkinson, CCC, May 30, 2013 » Stockfish
 * [|Repetition check] by Harm Geert Muller, CCC, July 20, 2013
 * [|UCI protocol issue] by Jon Dart, CCC, July 27, 2013 » UCI
 * [|ep and castle rights hashing] by Natale Galioto, CCC, September 15, 2013 » Castling rights, En passant, Transposition Table
 * 2014**
 * [|Two fold repetition rule] by Michel Van den Bergh, CCC, January 22, 2014
 * [|FIDE's new rules for chess] by Mark Lefler, CCC, July 20, 2014

2015 ...
> [|This should be in the wiki] by Steven Edwards, CCC, April 13, 2016
 * [|Using TT for detecting repetitions] by thevinenator, OpenChess Forum, August 18, 2015
 * 2016**
 * [|Simple triple repetition handler] by Stefano Gemma, CCC, February 21, 2016
 * [|How to test 3rd repetition rule?] by Luis Babboni, CCC, April 12, 2016
 * [|3rd repetition, a case where not cause castle rights... but] by Luis Babboni, CCC, April 14, 2016 » Castling rights
 * [|Triple Repitition: Is this considered a repitition or not?] by Jayakiran Akurathi, CCC, May 07, 2016 » En passant
 * [|Repetitions in the Search Tree] by Jayakiran Akurathi, CCC, May 29, 2016
 * [|Syzygy and draw by repetition] by Jon Dart, CCC, July 22, 2016 » Syzygy Bases
 * [|perpetual check position] by Erin Dame, CCC, August 16, 2016 » Perpetual Check
 * [|Hashed repetition table] by J. Wesley Cleveland, CCC, September 04, 2016 » Repetition Hash Table
 * [|transposition tables and three-fold repetition] by Erin Dame, CCC, September 10, 2016 » Transposition Table
 * [|The new chess rules (5-fold repetition and 75-move draw)] by Lyudmil Antonov, FishCooking, November 29, 2016 » Stockfish, Fifty-move Rule
 * 2017**
 * [|Have engines updated for fide 2014 draw rules?] by Norm Pollock, CCC, January 28, 2017
 * [|Reporting a draw in UCI] by Vince Sempronio, CCC, May 05, 2017 » Draw, UCI
 * 2018**
 * [|3-fold repetition and cutechess-cli] by Lars Mathiesen, CCC, January 14, 2018 » En passant

=External Links= > featuring [|Kristina Koropecki], [|Charlotte Danhier], [|Catherine De Biasio] > media type="youtube" key="1zED62IYPe4"
 * [|Cycle detection (graph theory) from Wikipedia]
 * [|Cycle detection from Wikipedia]
 * [|Repetition Detection] from Bruce Moreland's [|Programming Topics]
 * [|Threefold repetition from Wikipedia]
 * [|Perpetual check from Wikipedia]
 * [|Fide Handbook - E.I.01A. Laws of Chess]
 * [|A Chess Firewall at Zero?] by Ken Regan, [|Gödel's Lost Letter and P=NP], January 21, 2016
 * Agnes Obel - [|It's Happening Again] (2016), [|BBC 6 Music Live Room], [|YouTube] Video

=References= =What links here?= include page="Repetitions" component="backlinks" limit="180"
 * Up one Level**