Exemple #1
0
        static public PuzzleArea Join(PuzzleArea areaA, PuzzleArea areaB)
        {
            // Sicherstellen, dass beide Mengen gleich groß sind!!!
            if (!areaA.PositionsEquals(areaB))
            {
                return(null);
            }
            PuzzleArea result = Clone(areaA);

            result.MinFilled = Math.Max(areaA.MinFilled, areaB.MinFilled);
            result.MaxFilled = Math.Min(areaA.MaxFilled, areaB.MaxFilled);
            result.MinEmpty  = Math.Max(areaA.MinEmpty, areaB.MinEmpty);
            result.MaxEmpty  = Math.Min(areaA.MaxEmpty, areaB.MaxEmpty);

            result.RefreshDistincts();
            foreach (Point pos in areaA.InvolvedNumberPositions)
            {
                if (!result.InvolvedNumberPositions.Contains(pos))
                {
                    result.InvolvedNumberPositions.Add(pos);
                }
            }
            foreach (Point pos in areaB.InvolvedNumberPositions)
            {
                if (!result.InvolvedNumberPositions.Contains(pos))
                {
                    result.InvolvedNumberPositions.Add(pos);
                }
            }
            return(result);
        }
Exemple #2
0
        static public List <PuzzleArea> Join(List <PuzzleArea> areas)
        {
            List <PuzzleArea> result = new List <PuzzleArea>();

            result.AddRange(areas);
            for (int i = 0; i < result.Count; i++)
            {
                PuzzleArea areaA = result[i];
                int        j     = i + 1;
                while (j < result.Count)
                {
                    PuzzleArea areaB = result[j];
                    if (areaA.PositionsEquals(areaB))
                    {
                        result[i] = Join(areaA, areaB);
                        result.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }
            return(result);
        }
Exemple #3
0
        static public List <PuzzleArea> Split(List <PuzzleArea> areas)
        {
            List <int>        indexes       = new List <int>();
            List <PuzzleArea> splittedAreas = new List <PuzzleArea>();

            for (int i = 0; i < areas.Count; i++)
            {
                PuzzleArea areaA      = areas[i];
                bool       foundSplit = false;
                for (int j = i + 1; j < areas.Count; j++)
                {
                    PuzzleArea areaB = areas[j];
                    if (HasOverlap(areaA, areaB) && !areaA.PositionsEquals(areaB))
                    {
                        PuzzleArea overlapA  = Overlap(areaA, areaB);
                        PuzzleArea overlapB  = Overlap(areaB, areaA);
                        PuzzleArea overlapAB = Join(overlapA, overlapB);
                        PuzzleArea leftA     = Subset(areaA, overlapAB);
                        PuzzleArea rightB    = Subset(areaB, overlapAB);
                        if (!indexes.Contains(i))
                        {
                            indexes.Add(i);
                        }
                        if (!indexes.Contains(j))
                        {
                            indexes.Add(j);
                        }

                        if (leftA != null && leftA.Positions.Count > 1)
                        {
                            splittedAreas.Add(leftA);
                            foundSplit = true;
                        }
                        if (overlapAB != null && overlapAB.Positions.Count > 1)
                        {
                            splittedAreas.Add(overlapAB);
                            foundSplit = true;
                        }
                        if (rightB != null && rightB.Positions.Count > 1)
                        {
                            splittedAreas.Add(rightB);
                            foundSplit = true;
                        }
                    }
                }
                if (!foundSplit)
                {
                    splittedAreas.Add(areaA);
                }
            }
            List <PuzzleArea> joindAreas = CleanUp(Join(splittedAreas));

            return(CleanUp(joindAreas));
        }