예제 #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);
        }
예제 #2
0
        static public PuzzleArea Subset(PuzzleArea areaA, PuzzleArea areaB)
        {
            PuzzleArea result = Differenz(areaA, areaB);

            if (result != null)
            {
                result.MaxFilled = Math.Min(areaA.MinFilled - areaB.MinFilled, result.Positions.Count);
                result.MinFilled = Math.Min(areaA.MaxFilled - areaB.MaxFilled, result.Positions.Count);

                result.MaxEmpty = Math.Min(areaA.MinEmpty - areaB.MinEmpty, result.Positions.Count);
                result.MinEmpty = Math.Min(areaA.MaxEmpty - areaB.MaxEmpty, result.Positions.Count);

                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);
        }
예제 #3
0
        static public PuzzleArea Differenz(PuzzleArea areaA, PuzzleArea areaB)
        {
            PuzzleArea result  = new PuzzleArea(areaA.Board);
            PuzzleArea overlap = Overlap(areaA, areaB);

            foreach (Point pos in areaA.Positions)
            {
                if (!areaB.Positions.Contains(pos))
                {
                    result.AddPosition(pos);
                }
            }

            PuzzleArea areaRightB = new PuzzleArea(areaB.Board);

            foreach (Point pos in areaB.Positions)
            {
                if (!areaA.Positions.Contains(pos))
                {
                    areaRightB.AddPosition(pos);
                }
            }

            if (result.Positions.Count == 0)
            {
                return(null);
            }

            result.MinFilled = Math.Max(result.Positions.Count, areaA.MinFilled - overlap.MaxFilled - areaRightB.MinFilled);
            result.MaxFilled = Math.Min(result.Positions.Count, areaA.MaxFilled - overlap.MinFilled - areaRightB.MaxFilled);

            result.MinEmpty = Math.Max(result.Positions.Count, areaA.MinEmpty - overlap.MaxEmpty - areaRightB.MinEmpty);
            result.MaxEmpty = Math.Min(result.Positions.Count, areaA.MaxEmpty - overlap.MinEmpty - areaRightB.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);
        }
예제 #4
0
        static public PuzzleArea Overlap(PuzzleArea areaA, PuzzleArea areaB)
        {
            PuzzleArea result    = new PuzzleArea(areaA.Board);
            PuzzleArea leftAreaA = new PuzzleArea(areaA.Board);

            foreach (Point pos in areaA.Positions)
            {
                if (areaB.Positions.Contains(pos))
                {
                    result.AddPosition(pos);
                }
                else
                {
                    leftAreaA.AddPosition(pos);
                }
            }
            if (result.Positions.Count == 0)
            {
                return(null);
            }
            result.MinFilled = Math.Max(0, areaA.MinFilled - leftAreaA.UndefinedCount - leftAreaA.FilledCount);
            result.MaxFilled = Math.Min(areaA.MaxFilled, result.UndefinedCount + result.FilledCount);

            result.MinEmpty = Math.Max(0, areaA.MinEmpty - leftAreaA.UndefinedCount - leftAreaA.EmptyCount);
            result.MaxEmpty = Math.Min(areaA.MaxEmpty, result.UndefinedCount + result.EmptyCount);

            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);
        }