public void TestMemoizeIndices() { var model = new PatternModel { Frequencies = new double[] { 1, 1 }, // Free model Propagator = new int[][][] { new int[][] { new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 }, }, new int[][] { new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 }, new int[] { 0, 1 }, }, } }; var width = 10; var height = 10; var topology = new GridTopology(width, height, true); var indexPicker = new CustomIndexPicker(); var memoIndexPicker = new MemoizeIndexPicker(indexPicker); var options = new WavePropagatorOptions { BacktrackPolicy = new ConstantBacktrackPolicy(1), IndexPicker = memoIndexPicker, PatternPicker = new SimpleOrderedPatternPicker(), Constraints = new[] { new DontBanOneConstraint() }, }; var propagator = new WavePropagator(model, topology, options); // Attempts to pick pattern 0 at index 0, should contradict and backtrack var status = propagator.Step(); Assert.AreEqual(Resolution.Undecided, status); Assert.AreEqual(1, propagator.BacktrackCount); CollectionAssert.AreEqual(propagator.GetPossiblePatterns(0), new[] { 1 }); Assert.AreEqual(1, indexPicker.Count); // Should re-attempt index zero, with no effect. propagator.Step(); Assert.AreEqual(Resolution.Undecided, status); Assert.AreEqual(1, propagator.BacktrackCount); CollectionAssert.AreEqual(propagator.GetPossiblePatterns(0), new[] { 1 }); Assert.AreEqual(1, indexPicker.Count); // Attempts to pick pattern 0 at index 1, should contradict and backtrack propagator.Step(); Assert.AreEqual(Resolution.Undecided, status); Assert.AreEqual(2, propagator.BacktrackCount); CollectionAssert.AreEqual(propagator.GetPossiblePatterns(1), new[] { 1 }); Assert.AreEqual(2, indexPicker.Count); // etc }
/// <summary> /// Makes a single tile selection. /// Then it propagates that information to other nearby tiles. /// If backtracking is enabled a single step can include several backtracks,. /// </summary> /// <returns>The current <see cref="Status"/></returns> public Resolution Step() { return(wavePropagator.Step()); }