コード例 #1
0
        /// <summary>
        /// Converts the generated results to an <see cref="ITopoArray{Tile}"/>,
        /// using specific tiles for locations that have not been decided or are in contradiction.
        /// The arguments are not relevant if the <see cref="Status"/> is <see cref="Resolution.Decided"/>.
        /// </summary>
        public ITopoArray <Tile> ToArray(Tile undecided = default(Tile), Tile contradiction = default(Tile))
        {
            var width  = topology.Width;
            var height = topology.Height;
            var depth  = topology.Depth;

            var patternArray = wavePropagator.ToTopoArray();

            return(TopoArray.CreateByIndex(index =>
            {
                topology.GetCoord(index, out var x, out var y, out var z);
                TileCoordToPatternCoord(x, y, z, out var px, out var py, out var pz, out var o);
                var pattern = patternArray.Get(index);
                Tile tile;
                if (pattern == (int)Resolution.Undecided)
                {
                    tile = undecided;
                }
                else if (pattern == (int)Resolution.Contradiction)
                {
                    tile = contradiction;
                }
                else
                {
                    tile = tileModelMapping.PatternsToTilesByOffset[o][pattern];
                }
                return tile;
            }, topology));
        }
コード例 #2
0
        public void TestChessboard()
        {
            var model = new PatternModel
            {
                Frequencies = new double[] { 1, 1 },
                Propagator  = new int[][][]
                {
                    new int[][] { new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, },
                    new int[][] { new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, },
                }
            };
            var width      = 10;
            var height     = 10;
            var topology   = new Topology(width, height, true);
            var propagator = new WavePropagator(model, topology);
            var status     = propagator.Run();

            Assert.AreEqual(Resolution.Decided, status);
            var a       = propagator.ToTopoArray().ToArray2d();
            var topLeft = a[0, 0];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    Assert.IsTrue((a[x, y] == topLeft) ^ (x % 2 == 0) ^ (y % 2 == 0));
                }
            }

            // Should be impossible with an odd sized region
            topology   = new Topology(width + 1, height + 1, true);
            propagator = new WavePropagator(model, topology);
            status     = propagator.Run();
            Assert.AreEqual(Resolution.Contradiction, status);
        }
コード例 #3
0
        public void TestChessboard(ModelConstraintAlgorithm algorithm)
        {
            var model = new PatternModel
            {
                Frequencies = new double[] { 1, 1 },
                Propagator  = new int[][][]
                {
                    new int[][] { new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, },
                    new int[][] { new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, },
                }
            };
            var width    = 10;
            var height   = 10;
            var topology = new GridTopology(width, height, true);
            var options  = new WavePropagatorOptions {
                ModelConstraintAlgorithm = algorithm
            };
            var propagator = new WavePropagator(model, topology, options);
            var status     = propagator.Run();

            Assert.AreEqual(Resolution.Decided, status);
            var a       = propagator.ToTopoArray().ToArray2d();
            var topLeft = a[0, 0];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    Assert.IsTrue((a[x, y] == topLeft) ^ (x % 2 == 0) ^ (y % 2 == 0));
                }
            }

            // Should be impossible with an odd sized region
            topology   = new GridTopology(width + 1, height + 1, true);
            propagator = new WavePropagator(model, topology, options);
            status     = propagator.Run();
            Assert.AreEqual(Resolution.Contradiction, status);

            // Should be possible with an odd sized region, if we have the right mask
            var mask = new bool[(width + 1) * (height + 1)];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    mask[x + y * (width + 1)] = true;
                }
            }
            topology   = new GridTopology(width + 1, height + 1, true).WithMask(mask);
            propagator = new WavePropagator(model, topology, options);
            status     = propagator.Run();
            Assert.AreEqual(Resolution.Decided, status);
        }
コード例 #4
0
        /// <summary>
        /// Converts the generated results to an <see cref="ITopoArray{Tile}"/>,
        /// using specific tiles for locations that have not been decided or are in contradiction.
        /// The arguments are not relevant if the <see cref="Status"/> is <see cref="Resolution.Decided"/>.
        /// </summary>
        public ITopoArray <Tile> ToArray(Tile undecided = default(Tile), Tile contradiction = default(Tile))
        {
            var width  = topology.Width;
            var height = topology.Height;
            var depth  = topology.Depth;

            var patternArray = wavePropagator.ToTopoArray();

            var result = new Tile[width, height, depth];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        TileCoordToPatternCoord(x, y, z, out var px, out var py, out var pz, out var ox, out var oy, out var oz);
                        var  pattern = patternArray.Get(px, py, pz);
                        Tile tile;
                        if (pattern == (int)Resolution.Undecided)
                        {
                            tile = undecided;
                        }
                        else if (pattern == (int)Resolution.Contradiction)
                        {
                            tile = contradiction;
                        }
                        else
                        {
                            tile = patternsToTilesByOffset[CombineOffsets(ox, oy, oz)][pattern];
                        }
                        result[x, y, z] = tile;
                    }
                }
            }
            return(new TopoArray3D <Tile>(result, topology));
        }
コード例 #5
0
        public void TestChessboard3d(ModelConstraintAlgorithm algorithm)
        {
            var model = new PatternModel
            {
                Frequencies = new double[] { 1, 1 },
                Propagator  = new int[][][]
                {
                    new int[][] { new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, new int[] { 1 }, },
                    new int[][] { new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, },
                }
            };
            var width    = 4;
            var height   = 4;
            var depth    = 4;
            var topology = new GridTopology(width, height, depth, true);
            var options  = new WavePropagatorOptions {
                ModelConstraintAlgorithm = algorithm
            };
            var propagator = new WavePropagator(model, topology, options);
            var status     = propagator.Run();

            Assert.AreEqual(Resolution.Decided, status);
            var a       = propagator.ToTopoArray();
            var topLeft = a.Get(0, 0, 0);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        Assert.IsFalse((a.Get(x, y, z) == topLeft) ^ (x % 2 == 0) ^ (y % 2 == 0) ^ (z % 2 == 0));
                    }
                }
            }

            // Should be impossible with an odd sized region
            topology   = new GridTopology(width + 1, height + 1, depth + 1, true);
            propagator = new WavePropagator(model, topology, options);
            status     = propagator.Run();
            Assert.AreEqual(Resolution.Contradiction, status);
        }