Beispiel #1
0
        public static void Main(string[] args)
        {
            string       input  = @"C:\Users\Valdemar\Desktop\Chess\PGN\_CCRL-4040.[439277].pgn";
            string       output = @"c:\book.txt";
            FileStream   file;
            StreamWriter writer;

            try
            {
                file             = File.Open(output, FileMode.CreateNew);
                writer           = new StreamWriter(file);
                writer.AutoFlush = false;
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to open output file: " + e.Message);
                return;
            }

            int total = 0;

            Action <string, string> handler = (f, enc) =>
            {
                total++;

                if (total % 100 == 0)
                {
                    Console.WriteLine("Processed {0} Games", total);
                }
            };

            Action <string, PGNParserError> error = (f, x) =>
            {
                Console.WriteLine("Error parsing game {0} in file {1}", x.GameNumber, f);
                Console.WriteLine(x.ToString());
                Console.WriteLine("");
            };

            var lines = OpeningBook.CompileBook(new List <string>()
            {
                input
            }, 20, 5, handler, error);

            lines.ForEach(x => writer.WriteLine(x));
            writer.Flush();
            writer.Close();
            Console.WriteLine("Process Complete");
            Console.ReadLine();
        }
Beispiel #2
0
        public void TestGenerate()
        {
            var files = new List <string>()
            {
                "..\\..\\..\\TestData\\annotatedsetone.pgn",
                "..\\..\\..\\TestData\\BobbyFischer.pgn",
                "..\\..\\..\\TestData\\HumansVsComputers.pgn",
                "..\\..\\..\\TestData\\perle.pgn"
            };

            // just a smoke test
            var lines = OpeningBook.CompileBook(files, 30);

            Book = lines;
            Assert.IsTrue(lines.Count > 10);
            Assert.IsTrue(lines.All(x => x.Length >= 50 && x.Length <= 70));
        }