This project is a WPF version of my earlier FlowFreeDlx project.
get basic layout with window, grid, controls areadraw fixed size gridadd grid size dropdown and draw dynamically sized gridadd ability to add dots to the gridadd ability to un-add a dot to the gridpre-populate a 7x7 grid with a puzzleadd ability to draw a path (but without the highlighting of cells)add a solve buttonsolve (on UI thread!) + draw solution pathsadd highlight to pathsdo solve on background threaddisplay modal dialog box with indeterminate progress bar during solvingadd a cancel button to the modal dialog boxadd ability to cancel the solve processadd status bar to display statsadd stats re number of rows/cols in the matrixadd stats re time taken to build the matrixadd stats re time taken for Dlx to solve the matrixadd indication of user cancellation (when it applies)display stats so far even after cancellation ?add ability to click on the BoardCanvasraise an event that identifies the cell that was clicked (hit test ?)add a dropdown with a list of colours, add dot of selected colour when clicking on the boardun-add a dot when clicking on an existing dotdisplay the colour in the dropdown items (use an item template ?)add validation of colour pairs on the gridmust be exact pairsminimum number of pairs for the selected grid sizemaximum number of pairs for the selected grid size
add a clear/reset buttonpass maxDirectionChanges into BuildMatrixFor()increase maxDirectionChanges (extending the matrix) until a solution is found- add an app icon
enhance the validation messages (identify the exact problem)indicate minimum number of pairs if too fewindicate maximum number of pairs if too manyindicate which colours are not exact pairs- Now that I am using MVVM, the Solve button is not enabled unless the dots are valid
use TPL to try to speed up the creation of the matrix ?Fix the bug introduced by using Parallel.ForEach()Add an InternalDataRow inner class to simplify the MatrixBuilder codeapply the MVVM design pattern (MVVM Light Toolkit ?)
The solver works quickly for small grid sizes but starts to take a long time for larger grids. It would be nice to improve the solve time for larger grids. Here are some ideas about how to achieve this:
-
Micro optimisations here and there (e.g. inside loops that occur thousands of times)
-
When finding paths, favour ones that maintain direction e.g. if heading left, we currently explore left, up and down. We should probably only explore left initially. We can explore up and down later if necessary.
-
The majority of the time is spent finding paths i.e. building the Dlx matrix. The Dlx solve time is very quick. At the moment, we only attempt a Dlx solve after building the martrix for a given max number of direction changes. Perhaps we could attempt Dlx solves as the matrix is being built. We could potentially use TPL Dataflow to organise this e.g. using a BatchBlock.