public void TestPriority()
        {
            var t1    = new Tile(1);
            var t2    = new Tile(2);
            var t3    = new Tile(3);
            var model = new AdjacentModel(DirectionSet.Cartesian2d);

            model.AddAdjacency(t1, t1, Direction.XPlus);
            model.AddAdjacency(t1, t2, Direction.XPlus);
            model.AddAdjacency(t2, t2, Direction.XPlus);
            model.AddAdjacency(t2, t3, Direction.XPlus);
            model.AddAdjacency(t3, t3, Direction.XPlus);

            model.SetUniformFrequency();

            var topology = new GridTopology(6, 1, false).WithMask(new bool[] { true, true, true, true, true, false });

            IDictionary <Tile, PriorityAndWeight> weights = new Dictionary <Tile, PriorityAndWeight>
            {
                { t1, new PriorityAndWeight {
                      Priority = 0, Weight = 1
                  } },
                { t2, new PriorityAndWeight {
                      Priority = 1, Weight = 1
                  } },
                { t3, new PriorityAndWeight {
                      Priority = 2, Weight = 1
                  } },
            };

            var weightsArray = TopoArray.CreateByIndex(_ => weights, topology);

            var propagator = new TilePropagator(model, topology, new TilePropagatorOptions
            {
                IndexPickerType  = IndexPickerType.ArrayPriorityMinEntropy,
                WeightSetByIndex = TopoArray.CreateByIndex(_ => 0, topology),
                WeightSets       = new Dictionary <int, IDictionary <Tile, PriorityAndWeight> > {
                    { 0, weights }
                },
            });

            propagator.Select(0, 0, 0, t1);

            propagator.Run();

            Assert.AreEqual(Resolution.Decided, propagator.Status);

            var r = propagator.ToValueArray <int>();

            Assert.AreEqual(1, r.Get(0, 0));
            Assert.AreEqual(2, r.Get(1, 0));
            Assert.AreEqual(3, r.Get(2, 0));
            Assert.AreEqual(3, r.Get(3, 0));
        }
Beispiel #2
0
        /**
         * Returns an array where each cell is a list of remaining possible patterns.
         */
        public ITopoArray <ISet <int> > ToTopoArraySets()
        {
            return(TopoArray.CreateByIndex(index =>
            {
                var hs = new HashSet <int>();
                for (var pattern = 0; pattern < patternCount; pattern++)
                {
                    if (wave.Get(index, pattern))
                    {
                        hs.Add(pattern);
                    }
                }

                return (ISet <int>)(hs);
            }, topology));
        }
Beispiel #3
0
 /**
  * Returns the array of decided patterns, writing
  * -1 or -2 to indicate cells that are undecided or in contradiction.
  */
 public ITopoArray <int> ToTopoArray()
 {
     return(TopoArray.CreateByIndex(GetDecidedPattern, topology));
 }
Beispiel #4
0
 /// <summary>
 /// Convert the generated result to an array of sets, where each set
 /// indicates the values of tiles that are still valid at the location.
 /// The size of the set indicates the resolution of that location:
 /// * Greater than 1: <see cref="Resolution.Undecided"/>
 /// * Exactly 1: <see cref="Resolution.Decided"/>
 /// * Exactly 0: <see cref="Resolution.Contradiction"/>
 /// </summary>
 public ITopoArray <ISet <T> > ToValueSets <T>()
 {
     return(TopoArray.CreateByIndex(GetPossibleValues <T>, topology));
 }
Beispiel #5
0
 /// <summary>
 /// Convert the generated result to an array of sets, where each set
 /// indicates the tiles that are still valid at the location.
 /// The size of the set indicates the resolution of that location:
 /// * Greater than 1: <see cref="Resolution.Undecided"/>
 /// * Exactly 1: <see cref="Resolution.Decided"/>
 /// * Exactly 0: <see cref="Resolution.Contradiction"/>
 /// </summary>
 public ITopoArray <ISet <Tile> > ToArraySets()
 {
     return(TopoArray.CreateByIndex(GetPossibleTiles, topology));
 }
Beispiel #6
0
 /// <summary>
 /// Converts the generated results to an <see cref="ITopoArray{T}"/>,
 /// by extracting the value of each decided tile and
 /// using specific values for locations that have not been decided or are in contradiction.
 /// This is simply a convenience over
 /// The arguments are not relevant if the <see cref="Status"/> is <see cref="Resolution.Decided"/>.
 /// </summary>
 public ITopoArray <T> ToValueArray <T>(T undecided = default(T), T contradiction = default(T))
 {
     return(TopoArray.CreateByIndex(index => GetValue(index, undecided, contradiction), topology));
 }
Beispiel #7
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 contradiction = default)
 {
     return(TopoArray.CreateByIndex(index => GetTile(index, undecided, contradiction), topology));
 }
 public ITopoArray <IDictionary <Tile, double> > ToWeightedArraySets()
 {
     return(TopoArray.CreateByIndex(GetWeightedTiles, topology));
 }