Rebel wrote: ↑Thu Feb 28, 2019 8:10 am
Code: Select all
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - id sf10; bm e2e4; ce 55; acd 18;
To make that a compliant epd it should be
Code: Select all
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - id "sf10"; bm e4; ce 55; acd 18;
Added double quotes to id name and convert bm LAN to bm SAN.
If you want to add hmvc and fmvn
Code: Select all
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - id "sf10"; bm e4; ce 55; acd 18; hmvc 0; fmvn 1;
If you want to make all your epd's compliant here is the script to change its format.
Code: Select all
# -*- coding: utf-8 -*-
"""
modify_epd_1.py
Read epd file and fix epd lines to make it epd compliant.
* Add double quotes to id name
* Convert bm LAN to bm SAN
* Add hmvc and fmvn
* Write to a new epd file
Requirements:
python 3
python-chess v0.26.0
"""
import chess
def main():
inepdfn = 'big.epd'
outepdfn = 'out_' + inepdfn
with open(outepdfn, 'w') as w:
with open(inepdfn, 'r') as f:
for line in f:
epd = line.rstrip()
# Modify bm LAN to bm SAN in orig epd
epd1 = ' '.join(epd.split()[0:4])
bm_lan = epd.split('bm')[1].strip().split(';')[0]
pos = chess.Board()
pos.set_epd(epd1)
bm_san = pos.san(chess.Move.from_uci(bm_lan))
a = 'bm ' + bm_lan
b = 'bm ' + bm_san
updated_epd = epd.replace(a, b)
# Add double quotes to id name
id_name = updated_epd.split('id')[1].strip().split(';')[0]
updated_id_name = '\"' + id_name + '\"'
a = 'id ' + id_name
b = 'id ' + updated_id_name
updated_epd = updated_epd.replace(a, b)
# Convert bm LAN to bm SAN and add hmvc and fmvn
pos, epd_info = chess.Board().from_epd(updated_epd)
new_epd = pos.epd(id=epd_info['id'],
bm=epd_info['bm'],
ce=epd_info['ce'],
acd=epd_info['acd'],
hmvc=pos.halfmove_clock,
fmvn=pos.fullmove_number)
# print(new_epd)
w.write('%s\n' % (new_epd))
if __name__ == "__main__":
main()
If you really just want to insert the hmvc and fmvn
Code: Select all
# -*- coding: utf-8 -*-
"""
modify_epd_0.py
Insert 0 1 after epd's e.p field
Requirements:
python 3
"""
def main():
inepdfn = 'big.epd' # Your input epd file
outepdfn = 'out_' + inepdfn
with open(outepdfn, 'w') as w:
with open(inepdfn, 'r') as f:
for epd in f:
# Get the first 4 fields and add '0 1'
first4field = ' '.join(epd.split()[0:4])
others = ' '.join(epd.split()[4:])
new_epd = first4field + ' 0 1 ' + others
# print(new_epd)
w.write('%s\n' % (new_epd))
if __name__ == "__main__":
main()