Ejemplo n.º 1
0
        public override void Run(string[] args)
        {
            var filename = string.Empty;
            var options = new OptionSet()
            {
                { "f=|file=", "Extracts parent/child relationship from book.", f => filename = f }
            };

            options.Parse(args);

            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new OptionSetException(options);
            }

            int written = 0;
            var importer = new NtestImporter(filename);
            foreach (var pos in from kvp in importer.Import()
                                select kvp.Board.MinimalReflection())
            {
                foreach (var successor in pos.CalculateMinimalSuccessors())
                {
                    Console.WriteLine("{0},{1}", successor.ToGuid(), pos.ToGuid());

                    if (++written % 1000000 == 0)
                    {
                        Console.Error.WriteLine("Written {0} lines", written);
                    }
                }
            }

            Console.Error.WriteLine("Wrote {0} lines", written);
        }
Ejemplo n.º 2
0
        public override void Run(string[] args)
        {
            var filename = string.Empty;
            var options = new OptionSet() { { "f=|file=", "Creates Json dump from specified book.", f => filename = f } };
            options.Parse(args);
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new OptionSetException(options);
            }

            var importer = new NtestImporter(filename);
            var written = 0;
            foreach (var pos in from kvp in importer.Import()
                                select kvp.Board.MinimalReflection())
            {
                Console.Write("{{ _id : \"{0}\", \"successors\" : [ ", pos.ToGuid());
                var successors = pos.CalculateMinimalSuccessors();
                Console.Write("\"{0}\"", successors.First().ToGuid());

                // add rest of successors
                for (int i = 1; i < successors.Count; i++)
                {
                    Console.Write(", \"{0}\"", successors[i].ToGuid());
                    if (++written % 100000 == 0)
                    {
                        Console.Error.WriteLine("Written {0} lines", written);
                    }
                }

                Console.WriteLine(" ] }");
            }

            Console.Error.WriteLine("Wrote {0} lines", written);
        }
Ejemplo n.º 3
0
        public override void Run(string[] args)
        {
            var filename = string.Empty;
            var options = new OptionSet() { { "f=|file=", "Creates split files from specified book.", f => filename = f } };
            options.Parse(args);
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new OptionSetException(options);
            }

            var importer = new NtestImporter(filename);
            // find first available split file
            int splitId = 0;
            FileStream stream = Utils.FindFirstSplitFile("split", ref splitId);
            Console.WriteLine("Creating {0}", stream.Name);

            var list = new List<Guid>();
            foreach (var pos in from kvp in importer.Import()
                                select kvp.Board.MinimalReflection())
            {
                // add position
                var bytes = new List<Byte>(BitConverter.GetBytes(pos.Empty));
                bytes.AddRange(BitConverter.GetBytes(pos.Mover));
                list.Add(new Guid(bytes.ToArray()));

                // add successors
                foreach (var successor in pos.CalculateMinimalSuccessors())
                {
                    var b = new List<Byte>(BitConverter.GetBytes(successor.Empty));
                    b.AddRange(BitConverter.GetBytes(successor.Mover));
                    list.Add(new Guid(b.ToArray()));
                }

                if (list.Count > 1000000)
                {
                    list.Sort();
                    list.ForEach(g => stream.Write(g.ToByteArray(), 0, 16));
                    stream.Close();
                    stream = Utils.FindFirstSplitFile("split", ref splitId);
                    Console.WriteLine("Creating {0}", stream.Name);
                    list = new List<Guid>();
                }
            }

            list.Sort();
            list.ForEach(g => stream.Write(g.ToByteArray(), 0, 16));
            stream.Close();
        }