/// <summary> /// Creates a puzzle editor. This object offers /// all functionality related to the creation and modification /// of puzzles. /// </summary> /// <param name="puzzle">Puzzle to be edited. Note that this object cannot be changed; the editor /// uses this puzzle solely as an initial state.</param> /// <returns>An IPuzzleEditor object.</returns> public IPuzzleEditor CreatePuzzleEditor(Puzzle puzzle) { var editorGrid = EditorGrid.FromPuzzle(puzzle); var puzzleEditor = new PuzzleEditor(editorGrid); return(puzzleEditor); }
/// <summary> /// Creates a Puzzle from a solution. The constraints /// will be inferred. /// </summary> /// <param name="grid">Solution represented by a grid of Squares.</param> /// <returns>A Puzzle with the given solution.</returns> public static Puzzle FromGrid(IGrid <Square> grid) { var editorGrid = new EditorGrid(grid); var columnConstraints = editorGrid.DeriveColumnConstraints(); var rowConstraints = editorGrid.DeriveRowConstraints(); var boolGrid = ConvertSquareGridToBoolGrid(grid); return(new Puzzle(columnConstraints: columnConstraints, rowConstraints: rowConstraints, grid: boolGrid)); }
public PuzzleEditor(EditorGrid editorGrid) { if (editorGrid == null) { throw new ArgumentNullException(nameof(editorGrid)); } else { this.editorGrid = editorGrid; ambiguityChecker = new AmbiguityChecker(columnConstraints: editorGrid.DeriveColumnConstraints(), rowConstraints: editorGrid.DeriveRowConstraints()); ambiguityGrid = ambiguityChecker.Ambiguities.Map(( Ambiguity x ) => Cell.Create(x)).Copy(); facadeGrid = editorGrid.Contents.Map(position => new PuzzleEditorSquare(this, position, ambiguityGrid[position])).Copy(); columnConstraints = editorGrid.Contents.ColumnIndices.Select(x => new PuzzleEditorColumnConstraints(editorGrid, x)).ToSequence(); rowConstraints = editorGrid.Contents.RowIndices.Select(y => new PuzzleEditorRowConstraints(editorGrid, y)).ToSequence(); } }
public PuzzleEditorColumnConstraints(EditorGrid parent, int column) : base(() => parent.DeriveColumnConstraints(column)) { // NOP }
public PuzzleEditorRowConstraints(EditorGrid parent, int row) : base(() => parent.DeriveRowConstraints(row)) { // NOP }