-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfendistribute.py
More file actions
41 lines (34 loc) · 1.1 KB
/
fendistribute.py
File metadata and controls
41 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
import sys
import chess
import logging, sys
#logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
#logging.debug('A debug message!')
#logging.info('We processed %d records', len(processed_records))
# MAIN
if len(sys.argv) < 2:
print("Usage:",
sys.argv[0],
"<filename_with_games_fen_positions_each_game_starting_with_underscore>")
exit(1)
filename = sys.argv[1]
fileopenings = open(filename+".openings.epd","w")
filemiddlegames = open(filename+".middlegames.epd","w")
fileendgames = open(filename+".endgames.epd","w")
board = chess.Board()
lines = [line.rstrip('\n') for line in open(sys.argv[1])]
for line in lines:
if line=="_":
currentmove = 0
else:
currentmove = currentmove+1
epdposition = " ".join(line.split()[0:4])
if currentmove<10:
fileopenings.write(epdposition+"\n")
else:
board.set_epd(epdposition)
if chess.popcount(board.occupied)<10:
fileendgames.write(epdposition+"\n")
else:
filemiddlegames.write(epdposition+"\n")
exit(0)