Syzygy Tablebase Names: A very stupid exercise.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

AndrewGrant
Posts: 1753
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Syzygy Tablebase Names: A very stupid exercise.

Post by AndrewGrant »

So, I needed some code in python to generate a list of all the Syzygy file names. KBvK, KQQQvKQ, and so forth. Syzygy has a particular naming scheme. Q > R > B > N > P. The side with more pieces is on the left of the v. The weaker side, if equal pieces, is on the right side.

Here is my solution...

Code: Select all

from itertools import combinations_with_replacements

def build_tablebase_names():

    letters = ['', 'Q', 'R', 'B', 'N', 'P']; candidates = []
    for LHS in combinations_with_replacement(letters, 4):
        for RHS in combinations_with_replacement(letters, 4):
            candidates.append('K{}vK{}'.format(''.join(LHS), ''.join(RHS)))

    def valid_filename(name):
        for i, letter in enumerate(letters[1:]):
            name = name.replace(letter, str(9 - i))
        lhs, rhs = name.replace('K', '9').split('v')
        return 2 < len(lhs + rhs) <= 6 and int(lhs) >= int(rhs)

    return list(filter(valid_filename, candidates))
Extremely unnecessary, but hey it does exactly as desired, without any sort of deeply nested loops. Heres the answer that rests inside the Syzygy code base: https://github.com/AndyGrant/Ethereal/b ... #L676-L733
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
AndrewGrant
Posts: 1753
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Re: Syzygy Tablebase Names: A very stupid exercise.

Post by AndrewGrant »

A (mostly uninteresting?) observation as well. Determining the number of files that would be used for the table bases up to N pieces is as follows below. Although note that for N=20, KQQQQQQQQQQQQQQQQQQvK would exist, although is illegal.

Code: Select all

2 0
3 5
4 35
5 145
6 510
7 1511
8 4031
9 9751
10 21941
11 46251
12 92503
13 176483
14 323553
15 572263
16 981023
17 1634775
18 2656510
19 4218785
20 6562555
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
User avatar
Ajedrecista
Posts: 1968
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Syzygy tablebase names: a very stupid exercise.

Post by Ajedrecista »

Hello Andrew:
AndrewGrant wrote: Sat May 08, 2021 3:31 pm A (mostly uninteresting?) observation as well. Determining the number of files that would be used for the table bases up to N pieces is as follows below. Although note that for N=20, KQQQQQQQQQQQQQQQQQQvK would exist, although is illegal.

Code: Select all

2 0
3 5
4 35
5 145
6 510
7 1511
8 4031
9 9751
10 21941
11 46251
12 92503
13 176483
14 323553
15 572263
16 981023
17 1634775
18 2656510
19 4218785
20 6562555
I think that what you are looking for is in the following site:

Number of endgames in Chess with any starting position.

Column 'Endgames Cumulative', then substracting 1 if you are not interested in K vs k (2 pieces). Only legal subsets are counted in that page, so KQQQQQQQQQQQQQQQQQQvK does not suit there. If you are not looking for legal subsets only, you still can check the number of legal and illegal subsets with your figures and those of that web.

Regards from Spain.

Ajedrecista.
AndrewGrant
Posts: 1753
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Re: Syzygy tablebase names: a very stupid exercise.

Post by AndrewGrant »

Ajedrecista wrote: Sat May 08, 2021 6:52 pm
I think that what you are looking for is in the following site:

Number of endgames in Chess with any starting position.
No, I'm not looking for anything in particular. Just a better solution than copy pasting ~510 file names for later use.
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Syzygy Tablebase Names: A very stupid exercise.

Post by Dann Corbit »

Here are the legal names for two through ten men (I guess kk is not very interesting since every element is 1/2):

Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Syzygy Tablebase Names: A very stupid exercise.

Post by dangi12012 »

AndrewGrant wrote: Sat May 08, 2021 2:39 pm So, I needed some code in python to generate a list of all the Syzygy file names. KBvK, KQQQvKQ, and so forth. Syzygy has a particular naming scheme. Q > R > B > N > P. The side with more pieces is on the left of the v. The weaker side, if equal pieces, is on the right side.
dont now if you are interested after all this time but:

what you need here is the python equivalent of

Code: Select all

std::next_permutation
and skip every item that is *Not in order* (Q > R > B > N > P)
Last edited by dangi12012 on Tue May 24, 2022 10:58 pm, edited 1 time in total.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
AndrewGrant
Posts: 1753
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Re: Syzygy Tablebase Names: A very stupid exercise.

Post by AndrewGrant »

As the title suggests, no. "A very stupid exercise", but a cute compact solution.
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )