BenjaminChambers / SudokuSharp

A C# library for working with Sudoku puzzles
MIT License
3 stars 3 forks source link

Add PuzzleGeneration with a Solution Mask #10

Open BenjaminChambers opened 7 years ago

BenjaminChambers commented 7 years ago

I need to add a new factory method which accepts a bool[] solution mask, where you can provide what you want the final puzzle to look like.

BenjaminChambers commented 7 years ago

The problem I'm running into is that for a given mask, you have a large number of possible solutions, but only a small number of them have unique solutions.

I've written methods that generate single solutions, or batches of them. But both of those are unsatisfying because you don't know if a puzzle that suits your needs will be found as either the single or a member of the batch. You also don't know how large of a batch you need before it contains one that meets your criteria.

BenjaminChambers commented 7 years ago

What I need is something like an iterator, where you initialize it, and then ask it for the next puzzle (or next N puzzles). It needs to track its own internal state related to the search/puzzle generation.

Because the search itself has a separate state, I'm leaning toward using a separate class that's created with the search parameters. You will then call First to reset it and Next to grab the next puzzle. You may continue calling Next until you find a puzzle you like or the last puzzle is found (unlikely - some quick back-of-the-envelope calculations yield that a puzzle with only 17 clues {the minimum number for a valid Sudoku puzzle, proven elsewhere} will have something along the lines of 10^15 possible solutions).