Zurichess pgn tuning data validation

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Zurichess pgn tuning data validation

Post by xr_a_y »

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.
chrisw
Posts: 4317
Joined: Tue Apr 03, 2012 4:28 pm

Re: Zurichess pgn tuning data validation

Post by chrisw »

xr_a_y wrote: Sat Mar 07, 2020 10:34 am 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.
Very easy if you can program Python and download Python-Chess.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Zurichess pgn tuning data validation

Post by xr_a_y »

chrisw wrote: Sat Mar 07, 2020 11:49 am
xr_a_y wrote: Sat Mar 07, 2020 10:34 am 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.
Very easy if you can program Python and download Python-Chess.
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))
And all position in Zurichess tuning data are fine.

My bad (as often), I had an issue with my threaded version of Minic tuning process.
chrisw
Posts: 4317
Joined: Tue Apr 03, 2012 4:28 pm

Re: Zurichess pgn tuning data validation

Post by chrisw »

xr_a_y wrote: Sat Mar 07, 2020 12:38 pm
chrisw wrote: Sat Mar 07, 2020 11:49 am
xr_a_y wrote: Sat Mar 07, 2020 10:34 am 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.
Very easy if you can program Python and download Python-Chess.
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))
And all position in Zurichess tuning data are fine.

My bad (as often), I had an issue with my threaded version of Minic tuning process.
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 checking
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.