Exemple #1
0
        protected FoundFields GetRow_Mirror(Puzzle puzzle, Field?searchField, Field oppositeField, int y, List <int> row, bool mirror)
        {
            var result = new FoundFields(puzzle.GetWidth(mirror));

            // If the whole row is invalid already before we start, we don't show anything.
            this.Puzzle = puzzle.Clone();
            if (!this.canFindValidRowConfiguration_Mirror(0, y, row, mirror))
            {
                return(result);
            }

            // This has some performance problems, you are (have the risk of) bruteforcing all solutions #width times, rather than once.
            // (Every time it tries to find a configuration for the same row remember).
            for (int x = 0; x < puzzle.GetWidth(mirror); x++)
            {
                if (puzzle[x, y, mirror] == Field.Unknown)
                {
                    this.Puzzle = puzzle.Clone();

                    this.Puzzle[x, y, mirror] = oppositeField;
                    if (!this.canFindValidRowConfiguration_Mirror(0, y, row, mirror))
                    {
                        result[x] = true;

                        if (searchField.HasValue)
                        {
                            puzzle[x, y, mirror] = searchField.Value;
                        }
                    }
                }
            }

            return(result);
        }
Exemple #2
0
 private void loopChanges_Mirror(Puzzle puzzle, FoundFields changes, Field search, Field opposite, List <int>[] rows, List <int>[] cols, bool mirror)
 {
     for (int x = 0; x < this.Puzzle.GetWidth(mirror); x++)
     {
         if (changes[x])
         {
             loopCols_Mirror(puzzle, search, opposite, rows, cols, mirror);
         }
     }
 }
Exemple #3
0
            public static FoundFields Merge(FoundFields one, FoundFields other)
            {
                if (one.Length != other.Length)
                {
                    throw new ArgumentException("Lengths must be equal to merge found fields.");
                }

                var result = new FoundFields(one.Length);

                if (one.FoundChange || other.FoundChange)
                {
                    for (int i = 0; i < other.Length; i++)
                    {
                        result[i] = one[i] || other[i];
                    }
                }

                return(result);
            }
Exemple #4
0
        private bool loopRows_Mirror(Puzzle puzzle, Field search, Field opposite, List <int>[] rows, List <int>[] cols, bool mirror)
        {
            if (this.ThreadHelper.Cancelling)
            {
                return(false);
            }

            for (int y = 0; y < this.Puzzle.GetHeight(mirror); y++)
            {
                FoundFields resultBlack = GetRow_Mirror(puzzle, search, opposite, y, rows[y], mirror);
                if (resultBlack.FoundChange)
                {
                    FoundFields resultWhite = GetRow_Mirror(puzzle, opposite, search, y, rows[y], mirror);
                    FoundFields changes     = FoundFields.Merge(resultBlack, resultWhite);

                    loopChanges_Mirror(puzzle, changes, search, opposite, rows, cols, mirror);
                    return(true);
                }
            }
            return(false);
        }