Object Oriented Design for Sudoku Puzzle

I am trying to develop a Sudoku puzzle in OOD.

On the one hand, it seems cheap to present to the board in a matrix with a check function that will be activated after each insert

On the other hand, it may be more convenient to represent the board with "blocks": each cell will be assigned with three blocks containing it - a column, a row, a square. The validation function here will be implemented differently according to the block class (col / row / square) using polymorphism, and when you insert a number, it is activated 3 times for every block belonging to the cell. This seems like more "OOD", but it is very expensive from the memory aspect.

Which way do you think is better? Is there a better way that is OOD but still cheap?

+3


source to share


1 answer


If you want to create a more general sudoku solver (there are other forms) you can use:

Cell

  • Position on screen
  • May contain a restricted alphabet character or be empty.
  • Belongs to one or more groups.
  • Some cells have a fixed value (they cannot be changed).
  • Each time a cell is to be changed, the new value must be valid across all groups.

General group

  • Contains multiple cells up to the number of characters in the alphabet.
  • The general group has an IsValid method.


Regular group sudoku

  • The IsValid method returns true if all nonblank cells contain different values.

Another Sodoku group

  • (You can define your own IsValid function).

Note You can even mix different types of groups.

+3


source







All Articles