Beispiel #1
0
        private Resolution RunAnimate(TileModel model, TilePropagator propagator, string dest, ExportOptions exportOptions)
        {
            if (!config.Animate)
            {
                return(Run(propagator));
            }
            // Animate is true - we run the propagator, and export after every step
            Resolution status   = Resolution.Undecided;
            var        allFiles = new List <string>();
            int        i        = 0;

            while (true)
            {
                status = propagator.Step();
                Directory.CreateDirectory(Path.GetDirectoryName(dest));
                var currentDest = Path.ChangeExtension(dest, i + Path.GetExtension(dest));
                allFiles.Add(currentDest);
                Exporter.Export(model, propagator, currentDest, config, exportOptions);
                i++;
                if (status != Resolution.Undecided)
                {
                    return(status);
                }
            }
        }
Beispiel #2
0
        public void TestParityConstraint()
        {
            var w        = 10;
            var h        = 10;
            var topology = new GridTopology(10, 10, false);

            var pathModel = new PathModel(forks: false);

            var constraint = new ParityConstraint
            {
                PathSpec = new EdgedPathSpec {
                    Exits = pathModel.Exits
                },
            };

            var options = new TilePropagatorOptions
            {
                BackTrackDepth = -1,
                Constraints    = new[] { constraint },
            };

            var propagator = new TilePropagator(pathModel.Model, topology, options);

            for (var x = 0; x < w; x++)
            {
                for (var y = 0; y < h; y++)
                {
                    void Select(Tile t) => propagator.Select(x, y, 0, t);

                    if (x == 0 && y == 1)
                    {
                        Select(pathModel.Straight2);
                        continue;
                    }
                    if (x == 0 || y == 0 || x == w - 1 || y == h - 1)
                    {
                        Select(pathModel.Empty);
                    }
                }
            }

            propagator.Step();

            Assert.AreEqual(Resolution.Contradiction, propagator.Status);
        }
Beispiel #3
0
        private Resolution Run(TilePropagator propagator)
        {
            var next = DateTime.Now + TimeSpan.FromMinutes(1);

            while (true)
            {
                for (var i = 0; i < 100; i++)
                {
                    var status = propagator.Step();
                    if (status != Resolution.Undecided)
                    {
                        return(status);
                    }
                }
                if (DateTime.Now > next)
                {
                    System.Console.WriteLine($"Progress {propagator.GetProgress():p2}");
                    next = DateTime.Now + TimeSpan.FromMinutes(1);
                }
            }
        }
Beispiel #4
0
        public static void WriteSteps(TilePropagator propagator)
        {
            Write(propagator);
            System.Console.WriteLine();

            while (true)
            {
                var prevBacktrackCount = propagator.BacktrackCount;
                var status             = propagator.Step();
                Write(propagator);
                if (propagator.BacktrackCount != prevBacktrackCount)
                {
                    System.Console.WriteLine("Backtracked!");
                }
                System.Console.WriteLine();

                if (status != Resolution.Undecided)
                {
                    System.Console.WriteLine(status);
                    break;
                }
            }
        }