示例#1
0
        /// <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();
            }
        }
 private void ResetAmbiguities()
 {
     this.ambiguityChecker = new AmbiguityChecker(columnConstraints: editorGrid.DeriveColumnConstraints(), rowConstraints: editorGrid.DeriveRowConstraints());
     RefreshAmbiguities();
 }
 public PuzzleEditorColumnConstraints(EditorGrid parent, int column)
     : base(() => parent.DeriveColumnConstraints(column))
 {
     // NOP
 }