static public PuzzleArea Clone(PuzzleArea original) { PuzzleArea result = new PuzzleArea(original.Board); foreach (Point pos in original.Positions) { result.AddPosition(pos); } return(result); }
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); }
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); }