understanding DTZ

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

understanding DTZ

Post by brtzsnr »

I'm trying to understand how DTZ works and I ran into a couple of positions for which Fathom [1] reports a DTZ of 1.

[D] 6r1/7K/8/5k2/8/8/8/7R w - - 0 1

Code: Select all

[Event ""]
[Site ""]
[Date "??"]
[Round "-"]
[White "Syzygy"]
[Black "Syzygy"]
[Result "1-0"]
[FEN "6r1/7K/8/5k2/8/8/8/7R w - - 0 1"]
[WDL "Win"]
[DTZ "1"]
[WinningMoves "Kxg8, Rf1"]
[DrawingMoves "Ra1, Rb1, Rc1, Rd1, Re1, Rh2, Rh3, Rh4, Rh5, Rh6"]
[LosingMoves "Kh6, Rg1"]

1. Kxg8 Ke4 2. Kf7 Kd3 3. Ke6 Ke3 4. Kd5 Kf3 5. Kd4 Kf2 6. Ke4 Kg2 7. Ra1 Kf2 8. Ra3 Ke2 9. Ra2+ Kd1 10. Kd3 Ke1 11. Rb2 Kf1 12. Ke3 Kg1 13. Kf3 Kh1 14. Kg3 Kg1 15. Rb1# 1-0
[D] 8/r2k1R1K/8/8/8/8/8/8 b - - 0 1

Code: Select all

[Event ""]
[Site ""]
[Date "??"]
[Round "-"]
[White "Syzygy"]
[Black "Syzygy"]
[Result "1-0"]
[FEN "8/r2k1R1K/8/8/8/8/8/8 b - - 0 1"]
[WDL "Loss"]
[DTZ "1"]
[WinningMoves ""]
[DrawingMoves ""]
[LosingMoves "Kc6, Kd6, Ke6, Kc8, Kd8, Ke8"]

1... Kc6 2. Rxa7 Kc5 3. Kg6 Kb6 4. Ra1 Kc5 5. Kf5 Kc4 6. Ke4 Kc5 7. Rd1 Kb4 8. Kd4 Kb5 9. Kd5 Kb4 10. Rd3 Kb5 11. Rb3+ Ka4 12. Kc4 Ka5 13. Kc5 Ka6 14. Rb1 Ka7 15. Kc6 Ka8 16. Kc7 Ka7 17. Ra1# 1-0
It's clear that in the first position 1 moves is requiered to convert to a KRK; while in the second 2 moves are needed, including the capture.

Which DTZ value is correct?

[1] https://github.com/jdart1/Fathom
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: understanding DTZ

Post by Robert Pope »

If I recall correctly, Ronald's DTZ values are really DTZ/2 for better compression, so as you convert the position, you will follow a sequence like:

wtm dtz 5
btm dtz 5
wtm dtz 3
btm dtz 3
wtm dtz 1
btm dtz 1
read from next table.
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: understanding DTZ

Post by brtzsnr »

My guess is that since DTZ is based on Fifty-move rule then the capture should not be counted.


[1] https://en.wikipedia.org/wiki/Fifty-move_rule

The fifty-move rule in chess states that a player can claim a draw if no capture has been made and no pawn has been moved in the last fifty moves
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: understanding DTZ

Post by brtzsnr »

For this KRK position, Fathom's reported DTZ is the number of moves till mate. This might be different from what Syzygy stores.

[D] 8/8/8/1r6/3K4/8/k7/8 w - - 0 2

Code: Select all

[Event ""]
[Site ""]
[Date "??"]
[Round "-"]
[White "Syzygy"]
[Black "Syzygy"]
[Result "0-1"]
[FEN "8/8/8/1r6/3K4/8/k7/8 w - - 0 2"]
[WDL "Loss"]
[DTZ "30"]
[WinningMoves ""]
[DrawingMoves ""]
[LosingMoves "Kc3, Kd3, Ke3, Kc4, Ke4"]

2. Kc4 Ra5 3. Kb4 Rd5 4. Kc3 Ka3 5. Kc4 Rd6 6. Kc3 Ka4 7. Kc4 Rd1 8. Kc3 Kb5 9. Kc2 Rd4 10. Kc3 Rd5 11. Kb2 Kb4 12. Kc2 Rd4 13. Kb2 Rc4 14. Ka1 Ka3 15. Kb1 Kb3 16. Ka1 Rc1# 0-1
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: understanding DTZ

Post by brtzsnr »

This is a bit more obvious. One extra white move increases DTZ by 2.

https://syzygy-tables.info/?fen=8/r3k2K ... _w_-_-_0_1

[D] 8/r3k1RK/8/8/8/8/8/8 b - - 0 1

Code: Select all

[Event ""]
[Site ""]
[Date "??"]
[Round "-"]
[White "Syzygy"]
[Black "Syzygy"]
[Result "1-0"]
[FEN "8/r3k1RK/8/8/8/8/8/8 b - - 0 1"]
[WDL "Loss"]
[DTZ "1"]
[WinningMoves ""]
[DrawingMoves ""]
[LosingMoves "Kd6, Ke6, Kf6, Kd8, Ke8, Kf8"]

1... Kd6 2. Rxa7 Kc5 3. Kg6 Kb6 4. Ra1 Kc5 5. Kf5 Kc4 6. Ke4 Kc5 7. Rd1 Kb4 8. Kd4 Kb5 9. Kd5 Kb4 10. Rd3 Kb5 11. Rb3+ Ka4 12. Kc4 Ka5 13. Kc5 Ka6 14. Rb1 Ka7 15. Kc6 Ka8 16. Kc7 Ka7 17. Ra1# 1-0

[D] 8/r3k2K/8/8/8/6R1/8/8 w - - 0 1

Code: Select all

[Event ""]
[Site ""]
[Date "??"]
[Round "-"]
[White "Syzygy"]
[Black "Syzygy"]
[Result "1-0"]
[FEN "8/r3k2K/8/8/8/6R1/8/8 w - - 0 1"]
[WDL "Win"]
[DTZ "3"]
[WinningMoves "Rg7"]
[DrawingMoves "Kg6, Kh6, Kg7, Kg8, Kh8, Rg1, Rg2, Rb3, Rc3, Rd3, Re3, Rf3, Rh3, Rg4, Rg5, Rg6, Rg8"]
[LosingMoves "Ra3"]

1. Rg7+ Kd6 2. Rxa7 Kc5 3. Kg6 Kb6 4. Ra1 Kc5 5. Kf5 Kc4 6. Ke4 Kc5 7. Rd1 Kb4 8. Kd4 Kb5 9. Kd5 Kb4 10. Rd3 Kb5 11. Rb3+ Ka4 12. Kc4 Ka5 13. Kc5 Ka6 14. Rb1 Ka7 15. Kc6 Ka8 16. Kc7 Ka7 17. Ra1# 1-0
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: understanding DTZ

Post by brtzsnr »

A few more positions with wrong DTZ.

[D] 8/r3k1RK/8/8/8/8/8/8 b - - 0 1

[D] 8/8/8/4K3/8/5k2/6R1/4r3 w - - 0 1

[D] 8/8/8/1k6/8/8/R3K2r/8 w - - 0 1

[D] 3K4/8/8/8/8/2k5/1R6/3r4 w - - 0 1
syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: understanding DTZ

Post by syzygy »

https://github.com/syzygy1/Cfish/blob/1 ... #L684-L711

Code: Select all

// The return value is from the point of view of the side to move:
//         n < -100 &#58; loss, but draw under 50-move rule
// -100 <= n < -1   &#58; loss in n ply &#40;assuming 50-move counter == 0&#41;
//         0        &#58; draw
//     1 < n <= 100 &#58; win in n ply &#40;assuming 50-move counter == 0&#41;
//   100 < n        &#58; win, but draw under 50-move rule
//
// If the position mate, -1 is returned instead of 0.
//
// The return value n can be off by 1&#58; a return value -n can mean a loss
// in n+1 ply and a return value +n can mean a win in n+1 ply. This
// cannot happen for tables with positions exactly on the "edge" of
// the 50-move rule.
http://talkchess.com/forum/viewtopic.php?t=58488