## Natural TB

Discussion of anything and everything relating to chess playing software and machines.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
syzygy
Posts: 4720
Joined: Tue Feb 28, 2012 10:56 pm

### Re: Natural TB (take 2)

Michel wrote:
Another interesting thing that you do is to save with LOWER / BOUND_UPPER instead of always BOUND_EXACT as it is usually done. Can you pelase elaborate on that?
The TB scores are saved as bounds because they are bounds.... as has been pointed out time and time again. This is not rocket science.
Indeed. Marco's "surprise" confirms that he is not even reading the posts here.

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

### Re: Natural TB (take 2)

jhellis3 wrote: Well, Bound Exact is only correct for draws, the result will never be greater than or less than a draw. But in the case of a TB win, that DTZ result implies mate eventually. To me, it certainly makes sense to treat a mate in X number of moves as greater value than mate eventually (and indeed this is the way they are actually scored in the engine), so use Bound Lower. Same principle applies to being mated.
Thanks.

I have tested with both the ideas I saw in your code:

Code: Select all

``````1. Save in TT with bounds instead of exact scores
2. Always save in TT even if search is continued &#40;as in the case of winning position&#41;``````
But only the first seems good, the second one introduced search instabilities in the form of fluctuating scores.

This is a 3minutes game SF Natural against itself with 5-men TB starting form this position

[D]8/8/4r3/4k3/8/1K2P3/3P4/6R1 w - - 1 46

This is the game with both above ideas applied:

Code: Select all

``````    1. d4+ +3.75/23 7.4s Kf6 -4.58/27 13s
2. Rg3 +4.00/23 1.4s Ke7 -5.42/26 11s
3. Kc4 +4.14/23 1.3s Kd6 -6.05/27 5.3s
4. Kd3 +5.07/24 3.0s Kd5 -7.87/28 11s
5. e4+ +6.14/23 1.3s Kd6 -9.70/24 4.0s
6. Rg7 +6.61/20 0.48s Rh6 -10.97/25 4.1s
7. Kc4 +8.73/22 1.9s Rh1 -12.15/26 12s
8. e5+ +10.97/22 3.1s Ke6 -21.19/24 6.7s
9. Rg6+ +11.76/19 1.4s Kf7 -47.50/24 5.9s
10. Ra6 +21.08/20 1.8s Rc1+ -128.72/24 10s
11. Kd5 +132.62/21 2.7s Rc8 -132.65/26 5.0s
12. Ra7+ +132.63/22 2.3s Kg6 -132.66/25 9.5s
13. e6 +132.65/22 2.6s Re8 -132.64/23 1.8s
14. e7 +132.65/21 4.3s Kf7 -132.66/23 2.0s
15. Kd6 +132.65/24 9.4s Kf6 -132.68/21 0.39s
16. Ra6 +132.69/18 0.78s Kf7 -132.57/23 8.9s
17. Ra4 +132.69/23 6.7s Rb8 -132.62/19 2.0s
18. e8=Q+ +132.77/24 15s Rxe8 -2.63/16 1.0s
19. d5 +5.76/17 4.8s Rg8 -10.73/17 5.3s
20. Ra7+ +132.71/18 13s Kf6 -2.70/15 1.3s
21. Ra2 +4.29/18 12s Rg4 -47.46/17 5.5s
22. Rf2+ +57.90/15 3.0s Kg7 -58.03/17 2.8s
23. Kc6 +132.70/16 2.1s Ra4 -58.11/16 2.1s
24. d6 +132.69/17 2.6s Rg4 -132.71/16 2.4s
25. Rc2 +132.68/17 3.6s Re4 -52.81/16 3.6s
26. Rg2+ +132.69/15 2.4s Kf6 -132.67/19 5.1s
27. d7 +132.62/16 3.3s Rd4 -47.63/15 0.64s
28. Kc7 +132.70/17 6.9s Rc4+ -52.95/16 5.4s
29. Kd6 +64.45/18 8.6s Rd4+ -132.78/21 4.7s
30. Kc7 +132.52/19 7.5s Rc4+ -132.68/15 0.52s
31. Kd6 +132.70/18 0.88s Rd4+ -59.68/19 4.1s
32. Kc6 +132.69/18 1.9s Ke6 -132.69/17 1.2s
33. Re2+ +132.69/17 1.9s Kf6 -132.70/14 0.10s
34. Kc7 +132.72/15 1.1s Rc4+ -132.62/17 2.7s
35. Kb6 +132.71/17 1.7s Rd4 -64.57/19 3.0s
36. Kc6 +48.33/20 5.8s Kg7 -52.65/15 0.42s
37. Rg2+ +132.72/16 1.3s Kf6 -47.80/16 0.43s
38. Re2 +132.70/17 2.0s Rd3 -132.56/19 2.5s
39. Re3 +47.75/17 4.6s Rxd7 -132.68/17 1.1s
40. Kxd7 +132.70/19 1.7s Kf5 -132.69/17 0.48s
41. Kd8 +132.71/17 3.6s Kf4 -47.63/15 1.0s
42. Ra3 +132.70/15 0.69s Ke4 -132.67/17 0.77s
43. Kc7 +47.83/16 2.9s Kd4 -47.80/14 0.25s
44. Kb7 +132.69/15 0.65s Kc4 -48.16/17 1.6s
45. Rg3 +47.71/15 2.4s Kd5 -132.70/17 0.40s
46. Rf3 +132.73/14 0.25s Ke4 -48.08/17 1.3s
47. Rf1 +132.70/15 1.0s Ke3 -47.80/12 0.13s
48. Ra1 +132.70/17 1.8s Kd2 -132.71/14 0.42s
49. Ka7 +47.71/13 0.83s Ke2 -132.70/14 0.21s
50. Ra2+ +132.72/15 0.29s Ke1 -47.80/14 0.27s
51. Kb7 +47.67/14 0.77s Kd1 -47.71/14 0.60s
52. Kc6 +47.67/13 0.44s Ke1 -132.71/15 0.22s
53. Rc2 +132.68/13 0.13s Kf1 -48.33/17 0.76s
54. Kd6 +132.66/15 0.37s Ke1 -132.70/14 0.27s
55. Kd5 +132.70/14 0.93s Kd1 -47.80/13 0.096s
56. Ra2 +M17/15 0.11s Kc1 -M14/32 0.15s
57. Kd4 +M13/29 0.10s Kd1 -M12/33 0.075s
58. Kc3 +M11/27 0.022s Ke1 -M10/36 0.080s
59. Kd3 +M9/35 0.11s Kf1 -M8/37 0.016s
60. Ke3 +M7/37 0.022s Kg1 -M6/92 0.070s
61. Kf3 +M5/127 0.061s Kh1 -M4/127 0.005s
62. Kg3 +M3/127 0.005s Kg1 -M2/1 0s
63. Ra1#
+M1/127 0.003s, White mates
``````
As you can see scores are fluctuating a lot going to +132 and back. Instead this is the game with only the first idea applied (saving in TT of bounds instead of exact).

Code: Select all

``````    1. Kc4 +2.59/23 6.3s Rc6+ -2.42/21 4.0s
2. Kd3 +2.68/23 1.3s Ra6 -2.67/28 4.7s
3. Rg5+ +2.82/24 0.59s Kf6 -2.80/29 0.86s
4. Rc5 +2.92/27 1.4s Ke7 -3.47/25 5.3s
5. e4 +3.75/22 1.7s Kd6 -3.72/24 1.0s
6. Kd4 +5.12/24 2.2s Ke6 -6.04/25 6.1s
7. e5 +7.15/26 5.1s Ra4+ -7.94/27 7.6s
8. Rc4 +7.16/25 0.57s Ra2 -8.58/25 1.3s
9. Rc6+ +7.25/32 1.4s Ke7 -10.55/30 14s
10. d3 +9.11/25 3.3s Ra3 -11.08/26 6.7s
11. Ke4 +10.02/22 1.5s Kf7 -12.16/26 13s
12. d4 +11.16/21 1.7s Rh3 -21.60/24 12s
13. Rc7+ +14.20/21 2.8s Kg6 -47.63/25 7.3s
14. e6 +21.19/21 1.4s Rh5 -52.81/27 5.9s
15. Rf7 +47.55/22 2.7s Rh1 -52.77/25 8.4s
16. Ke5 +132.50/21 2.7s Rh5+ -132.64/21 3.2s
17. Kd6 +132.65/21 2.9s Rh4 -52.81/19 4.3s
18. d5 +132.60/23 6.0s Ra4 -M44/30 4.0s
19. Ke5 +132.60/24 3.0s Ra6 -M40/29 1.4s
20. Rf8 +132.64/20 8.3s Ra7 -M36/30 0.40s
21. Rf6+ +M47/22 0.59s Kg7 -M32/31 1.6s
22. Rf7+ +M27/44 1.4s Rxf7 -M30/33 0.24s
23. exf7 +M25/44 0.44s Kxf7 -M26/38 1.5s
24. d6 +M23/50 3.0s Kf8 -M22/44 1.5s
25. Kf6 +M21/51 0.58s Ke8 -M20/44 0.35s
26. Ke6 +M19/55 2.3s Kd8 -M18/50 1.4s
27. d7 +M17/55 1.3s Kc7 -M16/1 0s
28. Ke7 +M15/55 2.6s Kb6 -M14/51 2.2s
29. d8=Q+ +M13/56 2.4s Kc5 -M12/46 0.24s
30. Qd3 +M11/56 0.45s Kc6 -M10/59 1.4s
31. Qc4+ +M9/87 2.2s Kb7 -M8/127 1.1s
32. Kd6 +M7/127 0.80s Kb8 -M6/127 0.087s
33. Qb4+ +M5/127 0.050s Ka7 -M4/127 0.067s
34. Kc6 +M3/127 0.004s Ka6 -M2/127 0.003s
35. Qa3#
+M1/127 0.003s, White mates``````
Definitely much better game!

BTW the second idea "Always save in TT even if search is continued" it is a pattern completely new to me, I never saw such a pattern before in a chess engine.

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

### Re: Natural TB (take 2)

As a reference, this is the TB code as of today:

Code: Select all

``````    // Step 4a. Tablebase probe
if (!PvNode && ss->tbCardinality&#41;
&#123;
int piecesCount = pos.count<ALL_PIECES>();

if (    piecesCount <= ss->tbCardinality
&& &#40;piecesCount <  ss->tbCardinality || depth >= TB&#58;&#58;ProbeDepth&#41;
&& !pos.can_castle&#40;ANY_CASTLING&#41;)
&#123;
TB&#58;&#58;ProbeState err;
TB&#58;&#58;WDLScore wdl = Tablebases&#58;&#58;probe_wdl&#40;pos, &err&#41;;

if &#40;err != TB&#58;&#58;ProbeState&#58;&#58;FAIL&#41;
&#123;

int drawScore = TB&#58;&#58;UseRule50 ? 1 &#58; 0;

value =  wdl < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
&#58; wdl >  drawScore ?  VALUE_MATE - MAX_PLY - ss->ply
&#58;  VALUE_DRAW + 2 * wdl * drawScore;

// Use TB scores win/loss as bounds &#40;like TT upperbound and
// lowerbound scores&#41;, a draw score is always considered.
if &#40;value >= beta ? wdl >= TB&#58;&#58;WDLDraw &#58; wdl <= TB&#58;&#58;WDLDraw&#41;
&#123;
Bound b =  wdl > TB&#58;&#58;WDLDraw ? BOUND_LOWER
&#58; wdl < TB&#58;&#58;WDLDraw ? BOUND_UPPER &#58; BOUND_EXACT;

// In case of a draw or a loss, save TB score in TT and return
// In case of a winning position keep searching the sub-tree
// with a much reduced depth and do not probe TB anymore.
if &#40;value <= VALUE_DRAW&#41;
&#123;
tte->save&#40;posKey, value_to_tt&#40;value, ss->ply&#41;, b,
std&#58;&#58;min&#40;DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY&#41;,
MOVE_NONE, VALUE_NONE, TT.generation&#40;));
return value;
&#125;

depth = std&#58;&#58;max&#40;depth / 2, ONE_PLY&#41;;
ss->tbCardinality = 0;
&#125;
&#125;
&#125;
&#125;
``````

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

### Re: Natural TB (take 2)

Here is the result of this test set:

https://chessprogramming.wikispaces.com ... dgame+Test

5-men, 15 sec per position, single core Intel-i5 2.6 Ghz

Code: Select all

``````stockfish&#58; Found 145 tablebases
Solving&#58; D&#58;\Documents\chess tests\endgame\Eigenmann Endgame Test.cbh
Maximum time = 15s.

2. E_E_T 003 - B vs B,  Eigenmann Endgame Test   Solved in 1.59s/22; Solved&#58; 1
3. E_E_T 006 - B vs L,  Eigenmann Endgame Test   Solved in 0.28s/18; Solved&#58; 2
4. E_E_T 007 - B vs L,  Eigenmann Endgame Test   Solved in 0.50s/23; Solved&#58; 3
5. E_E_T 008 - B vs S,  Eigenmann Endgame Test   Solved in 0.30s/17; Solved&#58; 4
6. E_E_T 009 - B vs S,  Eigenmann Endgame Test   Solved in 0.42s/17; Solved&#58; 5
7. E_E_T 010 - B vs S,  Eigenmann Endgame Test   Solved in 1.05s/23; Solved&#58; 6
8. E_E_T 011 - D vs D,  Eigenmann Endgame Test   Solved in 0.20s/11; Solved&#58; 7
9. E_E_T 012 - D vs D,  Eigenmann Endgame Test   Solved in 0.08s/14; Solved&#58; 8
10. E_E_T 013 - D vs D&S,  Eigenmann Endgame Test   Solved in 11.31s/43; Solved&#58; 9
11. E_E_T 014 - D&L vs D&T,  Eigenmann Endgame Test   Solved in 0.36s/16; Solved&#58; 10
12. E_E_T 015 - D&L&L vs D&L&S,  Eigenmann Endgame Test   Solved in 4.49s/34; Solved&#58; 11
13. E_E_T 017 - D&T&L vs D&L&L,  Eigenmann Endgame Test   Solved in 3.03s/22; Solved&#58; 12
14. E_E_T 018 - D&T&S vs D&T&T,  Eigenmann Endgame Test   Solved in 0.05s/11; Solved&#58; 13
15. E_E_T 019 - D&T&T vs D&T&T,  Eigenmann Endgame Test   Solved in 0.59s/17; Solved&#58; 14
16. E_E_T 020 - L vs B,  Eigenmann Endgame Test   Solved in 0.08s/13; Solved&#58; 15
17. E_E_T 021 - L vs B,  Eigenmann Endgame Test   Solved in 0.33s/19; Solved&#58; 16
18. E_E_T 022 - L vs L,  Eigenmann Endgame Test   Solved in 5.09s/26; Solved&#58; 17
19. E_E_T 023 - L vs L,  Eigenmann Endgame Test   Solved in 0.06s/14; Solved&#58; 18
20. E_E_T 024 - L vs L,  Eigenmann Endgame Test   Solved in 3.18s/25; Solved&#58; 19
21. E_E_T 025 - L vs L,  Eigenmann Endgame Test   Solved in 0.53s/17; Solved&#58; 20
22. E_E_T 027 - L vs L,  Eigenmann Endgame Test   Solved in 0s/8; Solved&#58; 21
23. E_E_T 028 - L vs L,  Eigenmann Endgame Test   Solved in 2.67s/42; Solved&#58; 22
24. E_E_T 029 - L vs S,  Eigenmann Endgame Test   Solved in 3.20s/27; Solved&#58; 23
25. E_E_T 030 - L vs S,  Eigenmann Endgame Test   Solved in 0.11s/15; Solved&#58; 24
26. E_E_T 031 - L vs S,  Eigenmann Endgame Test   Solved in 0.13s/14; Solved&#58; 25
27. E_E_T 032 - L&L&S vs T&L&L,  Eigenmann Endgame Test   Solved in 2.47s/19; Solved&#58; 26
28. E_E_T 033 - L&S vs D,  Eigenmann Endgame Test   > 15s.
29. E_E_T 034 - L&S vs L&B,  Eigenmann Endgame Test   > 15s.
30. E_E_T 035 - L&S vs L&S,  Eigenmann Endgame Test   Solved in 11.92s/34; Solved&#58; 27
31. E_E_T 036 - L&S vs T&B,  Eigenmann Endgame Test   Solved in 6.97s/40; Solved&#58; 28
32. E_E_T 037 - L&S&S vs T&B,  Eigenmann Endgame Test   > 15s.
33. E_E_T 038 - S vs B,  Eigenmann Endgame Test   Solved in 0.03s/13; Solved&#58; 29
34. E_E_T 039 - S vs D,  Eigenmann Endgame Test   > 15s.
35. E_E_T 040 - S vs L,  Eigenmann Endgame Test   Solved in 0.17s/16; Solved&#58; 30
36. E_E_T 041 - S vs L,  Eigenmann Endgame Test   Solved in 0.45s/21; Solved&#58; 31
37. E_E_T 042 - S vs L,  Eigenmann Endgame Test   Solved in 3.82s/24; Solved&#58; 32
38. E_E_T 043 - S vs L,  Eigenmann Endgame Test   Solved in 0.06s/17; Solved&#58; 33
39. E_E_T 044 - S vs S,  Eigenmann Endgame Test   Solved in 0.39s/20; Solved&#58; 34
40. E_E_T 045 - S vs S,  Eigenmann Endgame Test   Solved in 1.12s/23; Solved&#58; 35
41. E_E_T 046 - S vs S,  Eigenmann Endgame Test   Solved in 0.05s/13; Solved&#58; 36
42. E_E_T 047 - S vs T,  Eigenmann Endgame Test   Solved in 3.59s/27; Solved&#58; 37
43. E_E_T 048 - S vs T,  Eigenmann Endgame Test   Solved in 3.32s/26; Solved&#58; 38
44. E_E_T 049 - T vs B,  Eigenmann Endgame Test   Solved in 1.97s/24; Solved&#58; 39
45. E_E_T 050 - T vs B,  Eigenmann Endgame Test   Solved in 0.86s/16; Solved&#58; 40
46. E_E_T 051 - T vs L,  Eigenmann Endgame Test   Solved in 0.23s/16; Solved&#58; 41
47. E_E_T 052 - T vs L,  Eigenmann Endgame Test   Solved in 0.23s/16; Solved&#58; 42
48. E_E_T 053 - T vs S,  Eigenmann Endgame Test   Solved in 0.03s/12; Solved&#58; 43
49. E_E_T 054 - T vs T,  Eigenmann Endgame Test   Solved in 1.42s/22; Solved&#58; 44
50. E_E_T 055 - T vs T,  Eigenmann Endgame Test   Solved in 10.53s/29; Solved&#58; 45
51. E_E_T 056 - T vs T,  Eigenmann Endgame Test   Solved in 0.94s/19; Solved&#58; 46
52. E_E_T 057 - T vs T,  Eigenmann Endgame Test   Solved in 0.17s/14; Solved&#58; 47
53. E_E_T 058 - T vs T,  Eigenmann Endgame Test   Solved in 4.79s/27; Solved&#58; 48
54. E_E_T 059 - T vs T,  Eigenmann Endgame Test   Solved in 0.23s/15; Solved&#58; 49
55. E_E_T 060 - T vs T,  Eigenmann Endgame Test   Solved in 6.58s/37; Solved&#58; 50
56. E_E_T 061 - T vs T,  Eigenmann Endgame Test   Solved in 0.05s/13; Solved&#58; 51
57. E_E_T 062 - T vs T,  Eigenmann Endgame Test   Solved in 4.07s/30; Solved&#58; 52
58. E_E_T 063 - T vs T,  Eigenmann Endgame Test   Solved in 4.45s/30; Solved&#58; 53
59. E_E_T 064 - T vs T,  Eigenmann Endgame Test   Solved in 4.24s/24; Solved&#58; 54
60. E_E_T 065 - T vs T,  Eigenmann Endgame Test   > 15s.
61. E_E_T 066 - T vs T,  Eigenmann Endgame Test   Solved in 2.09s/22; Solved&#58; 55
62. E_E_T 067 - T vs T,  Eigenmann Endgame Test   Solved in 0.09s/12; Solved&#58; 56
63. E_E_T 068 - T vs T,  Eigenmann Endgame Test   > 15s.
64. E_E_T 069 - T vs T,  Eigenmann Endgame Test   Solved in 0.59s/17; Solved&#58; 57
65. E_E_T 071 - T&L vs D,  Eigenmann Endgame Test   Solved in 0.89s/15; Solved&#58; 58
66. E_E_T 072 - T&L vs L&B,  Eigenmann Endgame Test   Solved in 0.58s/17; Solved&#58; 59
67. E_E_T 073 - T&L vs T&B,  Eigenmann Endgame Test   Solved in 0.02s/10; Solved&#58; 60
68. E_E_T 074 - T&L vs T&B,  Eigenmann Endgame Test   Solved in 3.60s/22; Solved&#58; 61
69. E_E_T 075 - T&L vs T&L,  Eigenmann Endgame Test   Solved in 0s/6; Solved&#58; 62
70. E_E_T 076 - T&L vs T&L,  Eigenmann Endgame Test   Solved in 3.07s/23; Solved&#58; 63
71. E_E_T 077 - T&L vs T&L,  Eigenmann Endgame Test   > 15s.
72. E_E_T 078 - T&L vs T&S,  Eigenmann Endgame Test   Solved in 4.52s/27; Solved&#58; 64
73. E_E_T 079 - T&L&L vs T&L&S,  Eigenmann Endgame Test   Solved in 0.14s/14; Solved&#58; 65
74. E_E_T 080 - T&L&S vs D&L,  Eigenmann Endgame Test   Solved in 8.75s/27; Solved&#58; 66
75. E_E_T 081 - T&L&S vs L&B,  Eigenmann Endgame Test   Solved in 4.51s/42; Solved&#58; 67
76. E_E_T 082 - T&L&S vs T&L&L,  Eigenmann Endgame Test   Solved in 12.14s/27; Solved&#58; 68
77. E_E_T 083 - T&L&S vs T&L&S,  Eigenmann Endgame Test   Solved in 0s/7; Solved&#58; 69
78. E_E_T 084 - T&S vs T&L,  Eigenmann Endgame Test   Solved in 0.03s/12; Solved&#58; 70
79. E_E_T 085 - T&S vs T&L,  Eigenmann Endgame Test   Solved in 15.24s/27; Solved&#58; 71
80. E_E_T 086 - T&S vs T&L,  Eigenmann Endgame Test   Solved in 0.06s/11; Solved&#58; 72
81. E_E_T 087 - T&S vs T&S,  Eigenmann Endgame Test   Solved in 0.25s/15; Solved&#58; 73
82. E_E_T 088 - T&S vs T&S,  Eigenmann Endgame Test   > 15s.
83. E_E_T 089 - T&S vs T&T,  Eigenmann Endgame Test   Solved in 3.49s/19; Solved&#58; 74
84. E_E_T 090 - T&S&B vs T&T&L,  Eigenmann Endgame Test   Solved in 0s/3; Solved&#58; 75
85. E_E_T 090 - T&T vs D,  Eigenmann Endgame Test   Solved in 0.02s/9; Solved&#58; 76
86. E_E_T 092 - T&T vs T&L,  Eigenmann Endgame Test   Solved in 0.51s/18; Solved&#58; 77
87. E_E_T 093 - T&T vs T&L&S,  Eigenmann Endgame Test   Solved in 1.17s/16; Solved&#58; 78
88. E_E_T 094 - T&T vs T&T,  Eigenmann Endgame Test   Solved in 0.05s/10; Solved&#58; 79
89. E_E_T 095 - T&T vs T&T,  Eigenmann Endgame Test   Solved in 3.54s/24; Solved&#58; 80
90. E_E_T 096 - T&T&L vs D&L&L,  Eigenmann Endgame Test   Solved in 6.57s/22; Solved&#58; 81
91. E_E_T 097 - T&T&L vs T&S&B,  Eigenmann Endgame Test   Solved in 1.98s/20; Solved&#58; 82
92. E_E_T 098 - T&T&L vs T&T&L,  Eigenmann Endgame Test   > 15s.
93. E_E_T 099 - T&T&S vs T&T&L,  Eigenmann Endgame Test   Solved in 0.09s/12; Solved&#58; 83
94. E_E_T 100 - T&T&S vs T&T&L,  Eigenmann Endgame Test   Solved in 3.35s/21; Solved&#58; 84
95. E_E_T 16b -  T&S vs T&S,  Eigenmann Endgame Test   Solved in 3.67s/22; Solved&#58; 85
96. E_E_T 26b -  L vs L,  Eigenmann Endgame Test   Solved in 0.41s/17; Solved&#58; 86
97. E_E_T 70b - D vs T&L&B,  Eigenmann Endgame Test   Solved in 0s/4; Solved&#58; 87
98. E_E_T 001 - B vs B,  Eigenmann Endgame Test   Solved in 0.30s/18; Solved&#58; 88
99. E_E_T 002 - B vs B,  Eigenmann Endgame Test   Solved in 0.70s/17; Solved&#58; 89
100. E_E_T 004 - B vs B,  Eigenmann Endgame Test   Solved in 0.42s/16; Solved&#58; 90
101. E_E_T 005 - B vs B,  Eigenmann Endgame Test   > 15s.

Result&#58; 90 out of 100 = 90.0%. Average time = 2.19s / 19.62
``````

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

### Re: Natural TB (take 2)

As a reference current version under same conditions did:

Code: Select all

``````stockfish&#58; Found 145 tablebases
Solving&#58; D&#58;\Documents\chess tests\endgame\Eigenmann Endgame Test.cbh
Maximum time = 15s.

Result&#58; 88 out of 100 = 88.0%. Average time = 1.61s / 18.61
``````

jhellis3
Posts: 485
Joined: Fri Aug 16, 2013 10:36 pm

### Re: Natural TB (take 2)

BTW the second idea "Always save in TT even if search is continued" it is a pattern completely new to me, I never saw such a pattern before in a chess engine.
Hi Marco. I am not sure how exactly you implemented the condition, but I don't always save to the TT. In fact, my implementation does not even use the TBs if a "correct" ttValue is detected, greater than KNOWN_WIN for a win, less that -KNOWN_WIN for a loss.

The idea behind saving though is, that since we are not returning, in the case that we detect an incorret ttValue or no ttValue at all, we (over)write that to the TT. All reduced depth searches (which is prettymuch everything other than the PV), will be able to take advantage of this. The idea being that if we have access to perfect information about a position, we can use it as a soft guide to the search. This can as you noticed lead to some search instability, but I do not recall it being quite that severe in my implementation. It has been quite some time since I last looked at or worked on the code, however.

Code: Select all

`````` if &#40;value <= VALUE_DRAW&#41;
&#123;
tte->save&#40;posKey, value_to_tt&#40;value, ss->ply&#41;, b,
std&#58;&#58;min&#40;DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY&#41;,
MOVE_NONE, VALUE_NONE, TT.generation&#40;));
return value;
&#125; ``````
But shouldn't the condition here be:

Code: Select all

`` if &#40;wdl <= drawScore&#41;``
That way you save and return for cursed wins as well (if using the 50 move rule).

Anyway, hope that helps. I may take a look at the code again when I get some more free time. [/quote]

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

### Re: Natural TB (take 2)

jhellis3 wrote: But shouldn't the condition here be:

Code: Select all

`` if &#40;wdl <= drawScore&#41;``
Thanks Joseph, yes you are right. I have rewritten the logic to accomplish following goals:

Code: Select all

``````   - Full symmety between win and lose positions

- Full symmetry between PV and non-PV nodes &#40;it probes also in PV nodes&#41;

- Full efficency when TB hit is deep in the tree &#40;midgame&#41;

- Full efficency to detect draw positions

- Normal search and scores during endgames
``````
Indeed I realized these are important things to have. In test games I see the last version kept all the nice properties of yesterday version regarding play behaviour and artifacts. Mainly it finds mates and it does not show sacrificies to simplify into a TB position. Also search stability seems good and I didn't experience anomalus score fluctations.

Now I have to pit it against master in a long test to verify we, hopefully, don't have lost ELO.

I have pushed the version on Github, the core of new version logic is the following:

Code: Select all

``````    // Step 4a. Tablebase probe
if (!rootNode && ss->tbCardinality&#41;
&#123;
int piecesCount = pos.count<ALL_PIECES>();

if (    piecesCount <= ss->tbCardinality
&& &#40;piecesCount <  ss->tbCardinality || depth >= TB&#58;&#58;ProbeDepth&#41;
&& !pos.can_castle&#40;ANY_CASTLING&#41;)
&#123;
TB&#58;&#58;ProbeState err;
TB&#58;&#58;WDLScore wdl = Tablebases&#58;&#58;probe_wdl&#40;pos, &err&#41;;

if &#40;err != TB&#58;&#58;ProbeState&#58;&#58;FAIL&#41;
&#123;

int drawScore = TB&#58;&#58;UseRule50 ? 1 &#58; 0;

value =  wdl < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
&#58; wdl >  drawScore ?  VALUE_MATE - MAX_PLY - ss->ply
&#58;  VALUE_DRAW + 2 * wdl * drawScore;

// Use TB scores win/loss as bounds &#40;like TT upperbound and
// lowerbound scores&#41;, a draw score is always considered.
if &#40;value >= beta ? wdl >= TB&#58;&#58;WDLDraw &#58; wdl <= TB&#58;&#58;WDLDraw&#41;
&#123;
Bound b =  wdl > TB&#58;&#58;WDLDraw ? BOUND_LOWER
&#58; wdl < TB&#58;&#58;WDLDraw ? BOUND_UPPER &#58; BOUND_EXACT;

bool farFromRoot = ss->ply - depth / &#40;2 * ONE_PLY&#41; >= 0;

// When draw or in midgame save TB score in TT and return
if &#40;farFromRoot || wdl == TB&#58;&#58;WDLDraw&#41;
&#123;
tte->save&#40;posKey, value_to_tt&#40;value, ss->ply&#41;, b,
std&#58;&#58;min&#40;DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY&#41;,
MOVE_NONE, VALUE_NONE, TT.generation&#40;));
return value;
&#125;

// When in endgame proceed with a reduced search
depth = depth / 2;
ss->tbCardinality = 0;
&#125;
&#125;
&#125;
&#125;
``````

BBauer
Posts: 658
Joined: Wed Mar 08, 2006 7:58 pm

### Re: Natural TB (take 2)

not working.

Code: Select all

``````g++ -Wall -Wcast-qual -std=c++11 -march=native -mtune=native  -Wextra -Wshadow -DNDEBUG -march=native -mtune=native -Ofast -fno-tracer -DIS_64BIT -march=native -march=native -mpopcnt -DUSE_POPCNT   -c -o search.o search.cpp
search.cpp&#58; In function 'Value &#123;anonymous&#125;&#58;&#58;search&#40;Position&, Search&#58;&#58;Stack*, Value, Value, Depth, bool, bool&#41;'&#58;
search.cpp&#58;707&#58;24&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
if (!PvNode && ss->tbCardinality&#41;
^~~~~~~~~~~~~
search.cpp&#58;711&#58;36&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
if (    piecesCount <= ss->tbCardinality
^~~~~~~~~~~~~
search.cpp&#58;712&#58;36&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
&& &#40;piecesCount <  ss->tbCardinality || depth >= TB&#58;&#58;ProbeDepth&#41;
^~~~~~~~~~~~~
search.cpp&#58;747&#58;25&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
ss->tbCardinality = 0;
^~~~~~~~~~~~~
<builtin>&#58; recipe for target 'search.o' failed
mingw32-make&#91;1&#93;&#58; *** &#91;search.o&#93; Error 1
mingw32-make&#91;1&#93;&#58; Leaving directory 'C&#58;/Users/bbauer/linscott/mysrc'
Makefile&#58;438&#58; recipe for target 'build' failed
mingw32-make&#58; *** &#91;build&#93; Error 2``````
kind regards

syzygy
Posts: 4720
Joined: Tue Feb 28, 2012 10:56 pm

### Re: Natural TB (take 2)

BBauer wrote:not working.

Code: Select all

``````g++ -Wall -Wcast-qual -std=c++11 -march=native -mtune=native  -Wextra -Wshadow -DNDEBUG -march=native -mtune=native -Ofast -fno-tracer -DIS_64BIT -march=native -march=native -mpopcnt -DUSE_POPCNT   -c -o search.o search.cpp
search.cpp&#58; In function 'Value &#123;anonymous&#125;&#58;&#58;search&#40;Position&, Search&#58;&#58;Stack*, Value, Value, Depth, bool, bool&#41;'&#58;
search.cpp&#58;707&#58;24&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
if (!PvNode && ss->tbCardinality&#41;
^~~~~~~~~~~~~
search.cpp&#58;711&#58;36&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
if (    piecesCount <= ss->tbCardinality
^~~~~~~~~~~~~
search.cpp&#58;712&#58;36&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
&& &#40;piecesCount <  ss->tbCardinality || depth >= TB&#58;&#58;ProbeDepth&#41;
^~~~~~~~~~~~~
search.cpp&#58;747&#58;25&#58; error&#58; 'struct Search&#58;&#58;Stack' has no member named 'tbCardinality'
ss->tbCardinality = 0;
^~~~~~~~~~~~~
<builtin>&#58; recipe for target 'search.o' failed
mingw32-make&#91;1&#93;&#58; *** &#91;search.o&#93; Error 1
mingw32-make&#91;1&#93;&#58; Leaving directory 'C&#58;/Users/bbauer/linscott/mysrc'
Makefile&#58;438&#58; recipe for target 'build' failed
mingw32-make&#58; *** &#91;build&#93; Error 2``````
kind regards
You need all the changes and not just those posted here. Try this:
https://github.com/mcostalba/Stockfish/ ... tural2.zip

tpoppins
Posts: 919
Joined: Tue Nov 24, 2015 8:11 pm
Location: upstate

### Re: Natural TB (take 2)

MikeB wrote:
Nordlandia wrote: How long will it take to generate 5-men syzygy in DTM format on high-end hardware (in my case i7-5960X 8-core) and estimated volume with good compression technique?
The generation time is ultimately based the size of the TB's. Using a 12 core Mac Pro with slightly older CPUs (x5690) was able to generate syzygy all 6 Man EGTB's in less than 72 hours - let's call it 60 hours . This is about 150 GB.
Simply amazing.