22
33from chess_utils import fen_to_tensor
44
5+ from .labels import label_to_vector
6+
57
68def load_chessfile_predict (filepath : str ) -> List [str ]:
79 with open (filepath , "r" , encoding = "utf-8" ) as f :
@@ -11,7 +13,6 @@ def load_chessfile_predict(filepath: str) -> List[str]:
1113def load_chessfile_train (
1214 filepath : str , encoding : str = "simple"
1315) -> List [Tuple [List [float ], List [float ]]]:
14- from .labels import label_to_vector
1516
1617 dataset : List [Tuple [List [float ], List [float ]]] = []
1718
@@ -21,18 +22,12 @@ def load_chessfile_train(
2122 if not line :
2223 continue
2324
24- parts = line .rsplit ( maxsplit = 2 )
25- if len (parts ) < 2 :
26- print (f"Warning: line { line_num } has no label , skipping" )
25+ parts = line .split ( )
26+ if len (parts ) < 7 or len ( parts ) > 8 :
27+ print (f"Warning: line { line_num } has invalid format , skipping" )
2728 continue
28-
29- if len (parts ) == 3 and parts [1 ] in ("Check" , "Checkmate" ):
30- fen = parts [0 ]
31- label_str = f"{ parts [1 ]} { parts [2 ]} "
32- else :
33- fen = " " .join (parts [:- 1 ])
34- label_str = parts [- 1 ]
35-
29+ fen = " " .join (parts [:6 ])
30+ label_str = " " .join (parts [6 :])
3631 try :
3732 x = fen_to_tensor (fen , encoding = encoding )
3833 y = label_to_vector (label_str )
0 commit comments