It’s this structure that is then used for pattern matching. This gives a structure of three columns, one for each cube containing three sets of possible values.
SUDOKU STRATEGY CODE
To accommodate this, the code aggregates the possible values of all rows of three cells within the three cubes. The four green cells don’t need to be in the same columns, they could be in any combination. The pattern of the green cells shown is Pattern.Lower2, other possible patterns of two cells within cube columns is Pattern.Upper2 and Pattern.TopAndBottom. That means we can infer that the red cells in the remaining cube must have six in their possible values and thus six can then be removed from the cell possibles in the blue area. The six can occur in either the top and bottom or bottom and top cells in different columns, both arrangements could be valid. The four green cells in two cubes will have six in their list of possible values. None of the coloured cells shown below have a value, only possibles. While cells in a row or column may have multiple possible values, if only one cell has a particular value, then that must be the value of the cell. In addition, if a cell has a possible value that has both vertical and horizontal directions, then that must be the cell’s value. Possible values will be shown as red if their direction is horizontal and green if vertical. An identical process is used for columns in cubes (vertical direction). This is a row, so the direction of influence of the exclusive values is horizontal.
![sudoku strategy sudoku strategy](https://sudoku.com/img/post-images/Intermediate-sudoku-techniques-3-1.jpg)
If the possible values of cells are exclusive to a single row of 3 cells in a cube, then no cells in remaining six cells of the puzzle row can contain those exclusive possibles. If that results in a cell having only one possible left, then that is added to a stack and the code loops processing cells until there are no more cells on the stack. If the user types a number into the red cell, then that number is removed from the possibles of all cells in the blue area. 1. Simple Cube, Row and Column Elimination
![sudoku strategy sudoku strategy](https://sudoku.com/img/post-images/Sudoku-Strategy-for-Beginners-3.jpg)
The 81 cells are also arranged in to nine cubes each containing nine cells. These will probably be very familiar to fellow Sudoku solvers but being self taught, they will have different names and terminology.
![sudoku strategy sudoku strategy](https://assets.funnygames.org/0/93810/82199/300x300/classic-solitaire.jpg)
The grid is contained within a Viewbox which provides automatic rescaling. Turns out they are quite easy, if you’ve written a custom control before, a lot of it will be familiar. I couldn’t find much information online about writing layout panels so I reverse engineered the UniformGrid using ILSpy. The View contains a custom layout panel SudokuGrid that is used to arrange the cells and the grid lines. When the model function returns, the two cell lists are compared and the view model list updated if required which redraws the cell. It determines which action is required and calls the appropriate model function, be it Add, Edit, Delete etc. When a user changes the puzzle, a callback in the ViewModel is executed. The ViewModel also contains a list of 81 cells this time stored in an ObservableCollection. The puzzle isn't actually rotated, the code simply changes the way each cell's coordinates are converted into an array index. The other notable point is that instead of writing two functions to implement a strategy, one for rows and another very similar version for columns I simply write the rows version, rotate the puzzle then call the rows function again. The list is actually a bit field which allows the use of boolean algebra to aid the required pattern matching. To that end, each cell contains a list of possible cell values which is then updated by the strategies. The trick to solving Sudoku puzzles is not to find out where numbers go directly, but is to find out where they cannot and when there is only one possibility left that must be it. The Model contains all the solving strategies and a single dimension array of 81 cells. The program structure follows a minimal MVVM design pattern. The code will attempt to solve the puzzle on the fly each time the user changes it. It uses the MahApps library to provide a icon less window and also an easy implementation of a dark mode. I was pretty sure there was a strategy that I was missing, and this program would confirm it. I’ve converted all the strategies that I know into code which will never get bored and make mistakes. It may be obvious and I just cannot see it. Sometimes, I can get stuck on a puzzle and it can get a bit boring just going through all the strategies to try and find the next number. Being a self taught Sudoku puzzle solver, I do enjoy solving the puzzles themselves but the real challenge is working out the strategies you need to solve them.