I managed to write some code to read an epd file and record the results of a probe of the Gaviota tablebases. It works, but it takes a significant fraction of a second to look up each result (processing maybe 15 positions/second on a non-SSD drive).
Is there anyone more familiar with python who can comment on my code below? I think I may be re-initializing the tablebase code for each new line?
import sys
sys.path.append('C:\games\chess\python-chess\dist\python-chess-0.17.0')
import chess
import chess.gaviota
f2 = open(r"c:\games\chess\gaviotaTB\kqkfen.epd", 'w')
num=0
with open(r"c:\games\chess\gaviotaTB\kqkfen.txt", 'r') as f:
for line_terminated in f:
line = line_terminated.rstrip('\n')
with chess.gaviota.open_tablebases(r"c:\games\chess\gaviotaTB\Gaviota") as tablebases:
wdl_score=tablebases.probe_wdl(chess.Board(line))
with chess.gaviota.open_tablebases(r"c:\games\chess\gaviotaTB\Gaviota") as tablebases:
dtm_score=tablebases.probe_dtm(chess.Board(line))
num=num+1
line=line+"; wdl "+str(wdl_score)+"; dtm "+str(dtm_score)+"\n"
print(line)
f2.write(line)
f2.close()
Robert Pope wrote:I managed to write some code to read an epd file and record the results of a probe of the Gaviota tablebases. It works, but it takes a significant fraction of a second to look up each result (processing maybe 15 positions/second on a non-SSD drive).
Is there anyone more familiar with python who can comment on my code below? I think I may be re-initializing the tablebase code for each new line?
import sys
sys.path.append('C:\games\chess\python-chess\dist\python-chess-0.17.0')
import chess
import chess.gaviota
f2 = open(r"c:\games\chess\gaviotaTB\kqkfen.epd", 'w')
num=0
with open(r"c:\games\chess\gaviotaTB\kqkfen.txt", 'r') as f:
for line_terminated in f:
line = line_terminated.rstrip('\n')
with chess.gaviota.open_tablebases(r"c:\games\chess\gaviotaTB\Gaviota") as tablebases:
wdl_score=tablebases.probe_wdl(chess.Board(line))
with chess.gaviota.open_tablebases(r"c:\games\chess\gaviotaTB\Gaviota") as tablebases:
dtm_score=tablebases.probe_dtm(chess.Board(line))
num=num+1
line=line+"; wdl "+str(wdl_score)+"; dtm "+str(dtm_score)+"\n"
print(line)
f2.write(line)
f2.close()
with open (TB):
with open(input fen file):
wdl_score = ...
dtm_score = ...
with open (save line, append mode):
That should be self closing and TB is still open as long as there are fen input and TB open attempt is done only once.
Otherwise just try profiling it.
# import chess modules
import sys
sys.path.append('C:\games\chess\python-chess\dist\python-chess-0.17.0')
import chess
import chess.gaviota
# This is the output filename
f2 = open(r"c:\games\chess\gaviotaTB\kpkfenout.epd", 'w')
num=0
# Update the input filename here
with chess.gaviota.open_tablebases(r"c:\games\chess\gaviotaTB\Gaviota") as tablebases:
with open(r"c:\games\chess\gaviotaTB\kpkfen.epd", 'r') as f:
for line_terminated in f:
line = line_terminated.rstrip('\n')
wdl_score=tablebases.probe_wdl(chess.Board(line))
dtm_score=tablebases.probe_dtm(chess.Board(line))
num=num+1
line=line+"; c0 wdl "+str(wdl_score)+"; c1 dtm "+str(dtm_score)+"\n"
print(num, line)
f2.write(line)
f2.close()