How can I check there is no illegal position in a given pgn ? and specifically here on the Zurichess tuning data.
I suspect, but I may be wrong, that there are kings on adjacent square at some point.
Zurichess pgn tuning data validation
Moderators: hgm, Rebel, chrisw
-
- Posts: 1871
- Joined: Sat Nov 25, 2017 2:28 pm
- Location: France
-
- Posts: 4317
- Joined: Tue Apr 03, 2012 4:28 pm
Re: Zurichess pgn tuning data validation
Very easy if you can program Python and download Python-Chess.
-
- Posts: 1871
- Joined: Sat Nov 25, 2017 2:28 pm
- Location: France
Re: Zurichess pgn tuning data validation
Yes of course ... Sorry to even ask ...
I was refereing to EDP, not PGN, so even my title is bad ...
So here's how
Code: Select all
import chess
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
filepath = "tuning/quiet-labeled.epd"
with open(filepath) as fp:
line = fp.readline()
c = file_len(filepath)
i = 0
while line:
edp = chess.Board(' '.join(line.split(' ')[:4]))
if not edp.is_valid():
print( "invalid position" + line)
line = fp.readline()
i = i + 1
if not i % 10000:
print( " {} / {} ".format(i,c))
My bad (as often), I had an issue with my threaded version of Minic tuning process.
-
- Posts: 4317
- Joined: Tue Apr 03, 2012 4:28 pm
Re: Zurichess pgn tuning data validation
Python-Chess tests a lot of EPD bad situations, but I think not all that you may need. For use as test positions in development work, it is probably worth checkingxr_a_y wrote: ↑Sat Mar 07, 2020 12:38 pmYes of course ... Sorry to even ask ...
I was refereing to EDP, not PGN, so even my title is bad ...
So here's howAnd all position in Zurichess tuning data are fine.Code: Select all
import chess def file_len(fname): with open(fname) as f: for i, l in enumerate(f): pass return i + 1 filepath = "tuning/quiet-labeled.epd" with open(filepath) as fp: line = fp.readline() c = file_len(filepath) i = 0 while line: edp = chess.Board(' '.join(line.split(' ')[:4])) if not edp.is_valid(): print( "invalid position" + line) line = fp.readline() i = i + 1 if not i % 10000: print( " {} / {} ".format(i,c))
My bad (as often), I had an issue with my threaded version of Minic tuning process.
1. If there actually is a legal move available from the position.
2. Depending what you are doing, that legal move count >=2, because not much point asking engine for BM if there’s only one move.
Not sure if the latest Python-Chess tests for idiotic EPD’s, so it may be worth running them through a bla-bla-bla detector before trying to load board.