How to test 3rd repetition rule?

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

This should be in the wiki

Post by sje » Wed Apr 13, 2016 3:05 pm

This should be in the wiki, if it's not already there.

The easiest way to test game termination detection is to add a chunk of code to generate lots of games, each made from randomly selected moves, and keep track of the counts of the different game termination kinds.

Generate a million such games, and the counts should be fairly close to:

Code: Select all

[] rg 1000000
   Checkmate   152806 0.152806
  FiftyMoves   223350 0.22335
Insufficient   536842 0.536842
  Repetition    25374 0.025374
   Stalemate    61628 0.061628
Average ply length: 341.998
Maximum ply length: 922
Which shows that repetition draws should occur about 2.54% of the time.

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

And some examples

Post by sje » Wed Apr 13, 2016 3:14 pm

And some examples:

To assist with testing, I've produced a PGN file of a thousand random games, of which 24 are repetition draws.

In each game, note the Termination tag pair which indicates the game termination kind.

https://dl.dropboxusercontent.com/u/316 ... 000.pgn.gz

jswaff
Posts: 50
Joined: Sun Jun 08, 2014 10:22 pm
Contact:

Re: How to test 3rd repetition rule?

Post by jswaff » Thu Apr 14, 2016 12:12 am

In my Java engine chess4j, I pulled this logic out into a separate class and wrote a unit test to ensure that it works.

https://sourceforge.net/p/chess4j/code/ ... .java#l244

See 'testDrawRep()' at the bottom. It basically just starts with the opening position and plays through some moves, checking after each move whether it's a draw by rep or not.

I don't think I have anything that checks for a draw by rep within the context of a search but that satisfies me that the logic works, if I can manage to plug it in correctly.

User avatar
Luis Babboni
Posts: 422
Joined: Sat Feb 28, 2015 3:37 pm
Location: Argentina

Re: This should be in the wiki

Post by Luis Babboni » Thu Apr 14, 2016 1:15 am

sje wrote:This should be in the wiki, if it's not already there.

The easiest way to test game termination detection is to add a chunk of code to generate lots of games, each made from randomly selected moves, and keep track of the counts of the different game termination kinds.

Generate a million such games, and the counts should be fairly close to:

Code: Select all

[] rg 1000000
   Checkmate   152806 0.152806
  FiftyMoves   223350 0.22335
Insufficient   536842 0.536842
  Repetition    25374 0.025374
   Stalemate    61628 0.061628
Average ply length: 341.998
Maximum ply length: 922
Which shows that repetition draws should occur about 2.54% of the time.
Nice idea!!

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Ten million

Post by sje » Thu Apr 14, 2016 2:38 am

Code: Select all

[] rg 10000000
   Checkmate  1530488 0.153049
  FiftyMoves  2240233 0.224023
Insufficient  5358465 0.535847
  Repetition   258098 0.0258098
   Stalemate   612716 0.0612716
Average ply length: 342.005
Maximum ply length: 1017

User avatar
Werner Taelemans
Posts: 103
Joined: Mon Feb 03, 2014 10:57 am
Location: Belgium
Contact:

Re: How to test 3rd repetition rule?

Post by Werner Taelemans » Thu Apr 14, 2016 1:18 pm

flok wrote:The int is a counter and when that reaches 3 at some point in the search-tree...
It is OK to use the draw score when the counter reaches 2, as explained in this thread:
http://www.talkchess.com/forum/viewtopic.php?t=51000

Post Reply