Created
July 6, 2023 22:36
-
-
Save AndyGrant/f2d9d0b15ed909fe81996ce5e4ed7a48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import os | |
from itertools import combinations_with_replacement | |
def tablebase_names(K=6): | |
letters = ['', 'Q', 'R', 'B', 'N', 'P'] | |
# Generate many potential K[] v K[], including all valid ones | |
candidates = ['K%svK%s' % (''.join(lhs), ''.join(rhs)) | |
for N in range(1, K - 1) | |
for lhs in combinations_with_replacement(letters, N) | |
for rhs in combinations_with_replacement(letters, K - N - 2)] | |
# Syzygy does LHS having more pieces first, stronger pieces second | |
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 int(lhs) >= int(rhs) and name != 'KvK' | |
all_sizes = list(filter(valid_filename, set(candidates))) | |
return [f for f in all_sizes if len(f) == K + 1] | |
for tablebase in tablebase_names(K=6): | |
target = 'http://tablebase.lichess.ovh/tables/standard/6-wdl/%s.rtbw' % (tablebase) | |
print ('Getting SRC=%s' % (target)) | |
os.system('curl %s --output %s.rtbw' % (target, tablebase)) | |
target = 'http://tablebase.lichess.ovh/tables/standard/6-dtz/%s.rtbz' % (tablebase) | |
print ('Getting SRC=%s' % (target)) | |
os.system('curl %s --output %s.rtbz' % (target, tablebase)) | |
for K in [3, 4, 5]: | |
for tablebase in tablebase_names(K=K): | |
target = 'http://tablebase.lichess.ovh/tables/standard/3-4-5/%s.rtbw' % (tablebase) | |
print ('Getting SRC=%s' % (target)) | |
os.system('curl %s --output %s.rtbw' % (target, tablebase)) | |
target = 'http://tablebase.lichess.ovh/tables/standard/3-4-5/%s.rtbz' % (tablebase) | |
print ('Getting SRC=%s' % (target)) | |
os.system('curl %s --output %s.rtbz' % (target, tablebase)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment