@@ -296,4 +296,94 @@ void tnn_generate_menu()
296296 }
297297}
298298
299+ void tnn_consolidate_files ()
300+ {
301+ /*
302+ fen rnb1k2r/p4ppp/1qp1pn2/1p1pN3/1b1P1B1P/P3P3/1PPN1PP1/R2QKB1R w KQkq - 1 9
303+ move a3b4
304+ score 1340
305+ ply 16
306+ result 1
307+ e
308+ */
309+ #ifdef _MSC_VER
310+ char * from_file_mask_plain = "d:/temp/temp/data_d%d_n%d_%04d.plain" ;
311+ char * to_file_mask_plain = "d:/temp/data/data_d%d_n%d_%04d.plain" ;
312+ #else
313+ char * from_file_mask_plain = "./temp/data_d%d_n%d_%04d.plain" ;
314+ char * to_file_mask_plain = "./data/data_d%d_n%d_%04d.plain" ;
315+ #endif
316+ int total_positions = 100000000 ;
317+ char from_file_name [1000 ];
318+ char to_file_name [1000 ];
319+ FILE * to_file = NULL ;
320+
321+ char fen [500 ];
322+ char move [100 ];
323+ char score [100 ];
324+ char ply [100 ];
325+ char result [100 ];
326+ char e [100 ];
327+
328+ int write_count = 0 ;
329+ int write_file = 0 ;
330+
331+ for (int i = 0 ; i < 100 ; i ++ ) {
332+ sprintf (from_file_name , from_file_mask_plain , 10 , 0 , i );
333+ FILE * from_file = fopen (from_file_name , "r" );
334+ if (from_file == NULL ) continue ;
335+ printf ("reading %s...\n" , from_file_name );
336+ while (TRUE) {
337+ if (!fgets (fen , 500 , from_file )) {
338+ break ;
339+ }
340+ if (strncmp (fen , "fen " , 4 )) {
341+ printf ("error reading 'fen ': %s\n" , fen );
342+ break ;
343+ }
344+ if (!fgets (move , 100 , from_file ) || strncmp (move , "move " , 5 )) {
345+ printf ("error reading 'move ': %s\n" , move );
346+ break ;
347+ }
348+ if (!fgets (score , 100 , from_file ) || strncmp (score , "score " , 6 )) {
349+ printf ("error reading 'score ': %s\n" , score );
350+ break ;
351+ }
352+ if (!fgets (ply , 100 , from_file ) || strncmp (ply , "ply " , 4 )) {
353+ printf ("error reading 'ply ': %s\n" , ply );
354+ break ;
355+ }
356+ if (!fgets (result , 100 , from_file ) || strncmp (result , "result " , 7 )) {
357+ printf ("error reading 'result ': %s\n" , result );
358+ break ;
359+ }
360+ if (!fgets (e , 100 , from_file ) || strncmp (e , "e" , 1 )) {
361+ printf ("error reading 'e': %s\n" , e );
362+ break ;
363+ }
364+ if (write_count == 0 || write_count == total_positions ) {
365+ if (to_file != NULL ) fclose (to_file );
366+ sprintf (to_file_name , to_file_mask_plain , 10 , 0 , ++ write_file );
367+ to_file = fopen (to_file_name , "w" );
368+ if (to_file == NULL ) {
369+ printf ("error opening file: %s\n" , to_file_name );
370+ exit (0 );
371+ }
372+ printf ("\twriting %s\n" , to_file_name );
373+ write_count = 0 ;
374+ }
375+ fputs (fen , to_file );
376+ fputs (move , to_file );
377+ fputs (score , to_file );
378+ fputs (ply , to_file );
379+ fputs (result , to_file );
380+ fputs (e , to_file );
381+ write_count ++ ;
382+ }
383+ fclose (from_file );
384+ }
385+ if (to_file != NULL ) fclose (to_file );
386+ }
387+
299388//END
389+
0 commit comments