Simple KQK endgame tablebase verification

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Simple KQK endgame tablebase verification

Post by xmas79 »

Hello,
for fun (as everything else here!) I implemented the KQK endgame tablebase. Now I'm looking for a method to test its correctness. I fed some positions to the engine, however search is not stable enough. I see that the first move at iteration 1 is a mate in N, then the search often settles on a longer mate (eg N+1). I think I can disable everything search-related and revert to a plain AB to prove the correctness of the TB, but I'm trying to figure out if there is a better approach. Of course I'm not willing to take an existing TB since it would require to understand other code as well as mine, doubling the effort :))))

Thanks,
Natale.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Simple KQK endgame tablebase verification

Post by Ferdy »

Could you post sample positions where your search appeared to be not stable?

One way to verify is to collect all KQK pos then get all its dm's and bm's then check if your TB can match those dm's and bm's.

Before I attempted to generate all KQK pos, let chest engine analyze it and get the pos with dm's and bm's and other info.
Sample output.

Code: Select all

2QK4/8/8/8/8/8/3k4/8 w - - 0 1; acn 177; acs 0; bm Kc7 Kd7 Ke7 Ke8 Qa6 Qc4 Qc5 Qc6 Qc7 Qd7+ Qe6 Qf5 Qg4 Qh3; ce 32750; dm 9; pv Qd7+ Ke2 Ke7 Kf2 Qd2+ Kf3 Qe1 Kf4 Ke6 Kg4 Qe3 Kh5 Qg3 Kh6 Kf6 Kh7 Qg7#;

Code: Select all

5K2/8/1k6/8/2Q5/8/8/8 w - - 0 1; acn 25; acs 0; bm Ke7 Ke8; ce 32758; dm 5; pv Ke8 Kb7 Kd7 Kb8 Qb4+ Ka8 Kc7 Ka7 Qb7#;
Vinvin
Posts: 5228
Joined: Thu Mar 09, 2006 9:40 am
Full name: Vincent Lejeune

Re: Simple KQK endgame tablebase verification

Post by Vinvin »

You can download this file : https://www.dropbox.com/s/3or245ruu7r2n ... D.ZIP?dl=0
Inside you'll find a file "KQK-9moves.epd", the field DM (distance to mate) is filled, there's a lot of 9 moves and a couple of 10 moves.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple KQK endgame tablebase verification

Post by hgm »

When the tablebase statistics (i.e. number of positions with a particular DTM) is the same as those published for other flavors of end-game tables there is little reason to doubt the correctness of your own.

Code: Select all

$ ./3men KQK
allocate 266304 at 7fe60040
        mated    mate
King captures 105476
mates     364         ( 0.01 sec)
in-1     1352    2448 ( 0.01 sec)
in-2     2956    5012 ( 0.01 sec)
in-3     7480    9064 ( 0.01 sec)
in-4    14144   19964 ( 0.03 sec)
in-5    25484   26164 ( 0.05 sec)
in-6    39908   32064 ( 0.06 sec)
in-7    54052   32104 ( 0.08 sec)
in-8    43800   15000 ( 0.11 sec)
in-9    11300    2680 ( 0.11 sec)
in-10      56       8 ( 0.11 sec)
in-11       0       0 ( 0.11 sec)
won:     249984 (100.0%)
lost:    200896 ( 80.4%)
avg:        6.4 moves
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

KQK summary

Post by sje »

Code: Select all

Summary for TB/KQK.tbw (WTM):

Score        Sp        Sp/unfold Tp        Tp/unfold Ap        Ap/unfold
------------ --------- --------- --------- --------- --------- ---------
Even                 0         0       564      3612       564      3612
MateIn10             1         8         0         0         1         8
MateIn9            428      2680         0         0       428      2680
MateIn8           2514     15000         0         0      2514     15000
MateIn7           5181     32104         0         0      5181     32104
MateIn6           4981     32064         0         0      4981     32064
MateIn5           3850     26164         0         0      3850     26164
MateIn4           3001     19964         0         0      3001     19964
MateIn3           1329      9064         0         0      1329      9064
MateIn2            750      5012         0         0       750      5012
MateIn1            399      2448         0         0       399      2448
Bust             16626    105476      1336      8548     17962    114024

Entry count: 40960
Entry count (unfolded): 262144

Longest mate score (WTM): MateIn10
Sample WTM longest mating position: 7K/6Q1/8/8/8/3k4/8/8 w - - 0 1

Optimal move sequence from the above WTM longest mating position:

1. Kg8 {Kh7 Qa1 Qa7 Qb2 Qb7 Qc7 Qd7+ Qe5 Qe7 Qf6 Qf7 Qf8 Qg1 Qg2 Qg3+ Qg4 Qg5
Qg6+ Qg8 Qh6 Qh7+} Kc4 2. Kf7 {Qa1 Qb2 Qd7 Qe5 Qg1 Qg3 Qg4+ Qg5 Qh6} Kd3 3. Ke6
{Kf6 Qa1 Qb2 Qe5 Qg1 Qg3+ Qg4 Qg5 Qh6} Kc4 4. Ke5 {Qa1 Qa7 Qd7 Qe5 Qg1 Qg4+ Qg5
Qh6} Kc3 {Kc5 Kd3} 5. Kd5+ {Ke4+} Kb3 {Kc2 Kd2 Kd3} 6. Kd4 {Qa1 Qc7 Qd4 Qf6
Qg3+} Kb2 {Kc2} 7. Kc4+ {Kd3+ Qf7 Qg6 Qg8 Qh7} Ka2 {Kb1 Kc1 Kc2} 8. Kc3 {Qb7
Qe5 Qg2+} Ka1 {Kb1} 9. Kb3+ {Kc2+ Qb7 Qg2} Kb1 10. Qb2# {Qg1#}

No WTM non-transition lose positions exist.

Summary for TB/KQK.tbb (BTM):

Score        Sp        Sp/unfold Tp        Tp/unfold Ap        Ap/unfold
------------ --------- --------- --------- --------- --------- ---------
Even              3661     23048         0         0      3661     23048
Bust              4092     26040      1900     12160      5992     38200
Checkmated          62       364         0         0        62       364
LoseIn1            237      1352         0         0       237      1352
LoseIn2            458      2956         0         0       458      2956
LoseIn3           1201      7480         0         0      1201      7480
LoseIn4           2193     14144         0         0      2193     14144
LoseIn5           3779     25484         0         0      3779     25484
LoseIn6           6130     39908         0         0      6130     39908
LoseIn7           8452     54052         0         0      8452     54052
LoseIn8           6974     43800         0         0      6974     43800
LoseIn9           1812     11300         0         0      1812     11300
LoseIn10             9        56         0         0         9        56

Entry count: 40960
Entry count (unfolded): 262144

No BTM non-transition mate positions exist.

Longest lose score (BTM): LoseIn10
Sample BTM longest losing position: 7K/6Q1/8/8/8/8/2k5/8 b - - 0 1

Optimal move sequence from the above BTM longest losing position:

1... Kd3 2. Kg8 {Kh7 Qa1 Qa7 Qb2 Qb7 Qc7 Qd7+ Qe5 Qe7 Qf6 Qf7 Qf8 Qg1 Qg2 Qg3+
Qg4 Qg5 Qg6+ Qg8 Qh6 Qh7+} Kc4 3. Kf7 {Qa1 Qb2 Qd7 Qe5 Qg1 Qg3 Qg4+ Qg5 Qh6}
Kd3 4. Ke6 {Kf6 Qa1 Qb2 Qe5 Qg1 Qg3+ Qg4 Qg5 Qh6} Kc4 5. Ke5 {Qa1 Qa7 Qd7 Qe5
Qg1 Qg4+ Qg5 Qh6} Kc3 {Kc5 Kd3} 6. Kd5+ {Ke4+} Kb3 {Kc2 Kd2 Kd3} 7. Kd4 {Qa1
Qc7 Qd4 Qf6 Qg3+} Kb2 {Kc2} 8. Kc4+ {Kd3+ Qf7 Qg6 Qg8 Qh7} Ka2 {Kb1 Kc1 Kc2} 9.
Kc3 {Qb7 Qe5 Qg2+} Ka1 {Kb1} 10. Kb3+ {Kc2+ Qb7 Qg2} Kb1 11. Qb2# {Qg1#}
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Simple KQK endgame tablebase verification

Post by xmas79 »

Code: Select all

mate in  0:    364   mated in  0:    364
mate in  1:   2448   mated in  1:   1352
mate in  2:   5012   mated in  2:   2956
mate in  3:   9064   mated in  3:   7480
mate in  4:  19964   mated in  4:  14144
mate in  5:  26164   mated in  5:  25484
mate in  6:  32064   mated in  6:  39908
mate in  7:  32104   mated in  7:  54052
mate in  8:  15000   mated in  8:  43800
mate in  9:   2680   mated in  9:  11300
mate in 10:      8   mated in 10:     56
Elapsed time: 0.172000
Success! Now going to see what the search has....

Thanks...
syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: Simple KQK endgame tablebase verification

Post by syzygy »

xmas79 wrote:I think I can disable everything search-related and revert to a plain AB to prove the correctness of the TB, but I'm trying to figure out if there is a better approach.
A straightforward way to verify the correctness of a TB is by looping through all positions of the TB and recomputing the value of the position using a 1-ply search (probing the TB or a sub-TB at each leaf position). If for all positions the result returned corresponds to the value stored, the TB should be correct.

Comparing statistics as suggested by HGM is easier, but may be tricky if you eliminate symmetrical positions from the TB by mirroring and the TB you want to compare statistics with does this differently.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Simple KQK endgame tablebase verification

Post by hgm »

Indeed, I should have mentioned that the counts I showed are the true counts, and not in anyway symmetry-reduced.

But even if you would compare symmetry-reduced results, and they are the same, it would be pretty amazing if the one you compared to would use a different symmetry reduction or if either of you were in error. It would just not be conclusive if you noticed a difference.
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Simple KQK endgame tablebase verification

Post by xmas79 »

Ferdy wrote:Could you post sample positions where your search appeared to be not stable?
Positions like [d]8/8/8/8/3K4/Q7/3k4/8 w - - 0 1
It said mate in 3, then suddenly mate in 5 and sticked to it. I suspect it was the probing code, it was messing up the search by not adjusting correctly the mate distance by ply. Now everything seems fine.

Thanks.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Simple KQK endgame tablebase verification

Post by sje »

xmas79 wrote: Positions like [d]8/8/8/8/3K4/Q7/3k4/8 w - - 0 1
It said mate in 3, then suddenly mate in 5 and sticked to it. I suspect it was the probing code, it was messing up the search by not adjusting correctly the mate distance by ply. Now everything seems fine.
Symbolic says:

Code: Select all

[] df
8/8/8/8/3K4/Q7/3k4/8 w - - 0 1
[] dmtb
Qa2+ MateIn3
Qb2+ MateIn3
Qa6 MateIn4
Qa8 MateIn4
Ke4 MateIn5
Qa5+ MateIn5
Qa7 MateIn5
Qb3 MateIn5
Qb4+ MateIn5
Qc3+ MateIn5
Qc5 MateIn5
Qd3+ MateIn5
Qd6 MateIn5
Qe3+ MateIn5
Qe7 MateIn5
Qf3 MateIn5
Qf8 MateIn5
Qg3 MateIn5
Qh3 MateIn5
Kc4 MateIn6
Kd5 MateIn6
Ke5 MateIn6
Qa1 MateIn6
Qa4 MateIn6
Kc5 MateIn7
[] dapv
1. Qa2+ Kc1 2. Kc3 Kd1 3. Qd2#