Example #1
0
        /// <remark>Returns if the cell is contradicted</remark>
        public bool removePatternUpdatingEntropy(int x, int y, PatternId id, PatternStorage patterns)
        {
            this.possibilities[x, y, id.asIndex] = false;

            var cache = this.entropies[x, y];

            cache.reduceWeight(patterns[id.asIndex].weight);
            this.entropies[x, y] = cache;

            return(cache.totalWeight == 0);
        }
Example #2
0
        bool removePatternUpdatingHeap(int x, int y, PatternId id, WfcContext cx, Solver solver)
        {
            if (cx.state.removePatternUpdatingEntropy(x, y, id, cx.model.patterns))
            {
                return(true);
            }

            solver.updateHeap(x, y, cx.state.entropies[x, y].entropyWithNoise());
            this.removals.Push(new TileRemoval(x, y, id));
            return(false);
        }
Example #3
0
        static void solveCellWithPattern(int x, int y, PatternId idToLockin, State state, PatternStorage patterns, Propagator propagator)
        {
            state.solveCellWithPattern(x, y, patterns[idToLockin.asIndex].weight);

            // setup next propagation
            for (int i = 0; i < patterns.len; i++)
            {
                var idToRemove = new PatternId(i);
                if (!state.isPossible(x, y, idToRemove) || i == idToLockin.asIndex)
                {
                    continue;
                }

                state.removePattern(x, y, idToRemove);
                propagator.onSolve(x, y, idToRemove);
            }
        }
Example #4
0
        /// <summary>Choose a possible pattern for an unlocked cell randomly in respect of weights of patterns</summary>
        static PatternId selectPatternForCell(int x, int y, State state, PatternStorage patterns, System.Random rnd)
        {
            int random = rnd.Next(0, state.entropies[x, y].totalWeight);

            int sumWeight = 0;

            for (int id_ = 0; id_ < patterns.len; id_++)
            {
                var id = new PatternId(id_);
                if (!state.isPossible(x, y, id))
                {
                    continue;
                }

                sumWeight += patterns[id_].weight;
                if (sumWeight > random)
                {
                    return(id);
                }
            }

            System.Console.WriteLine("ERROR: tried to select a pattern for a contradicted cell");
            return(new PatternId(-1));
        }
Example #5
0
 public int this[int x, int y, PatternId id, Dir4 dir] {
     get => this.counts[x, y, (int)dir + 4 * id.asIndex];
Example #6
0
 public void removePattern(int x, int y, PatternId id)
 {
     this.possibilities[x, y, id.asIndex] = false;
 }
Example #7
0
 /// <summary>Is the pattern still compaible</summary>
 public bool isPossible(int x, int y, PatternId id) => this.possibilities[x, y, id.asIndex];
Example #8
0
 /// <summary>Add a removal, which will be propagated later</summary>
 public void onSolve(int x, int y, PatternId id)
 {
     this.removals.Push(new TileRemoval(x, y, id));
 }
Example #9
0
 public TileRemoval(int x, int y, PatternId id)
 {
     this.pos = new Vec2i(x, y);
     this.id  = id;
 }