An Object Oriented Sudoku Game Generator
Project description
Beginner Object Oriented Sudoku Board Generator
Matrix Class
This class keeps track of the board with an instance variable called self.board It is responsible for checking the rules of sudoku in order to make a move, it check to see which numbers to exclude from a cell's row, column and 3x3 square
The variable self.cellStack is a list of the last 5 cells that were changed in order to backtrack in case of the algorithm cornering itself
Finally, self.cells is just a flattened version of self.board for easy traversing.
Cell Class
Each Cell gets initialized with 4 instance variables:
- self.row and self.col keep track of cell's position in the board
- self.options contains all the possible numbers that the cell could be
- self.num is the actual number it contains
Main
The main function of the program is an example of how to create a board
- Create a Matrix Object
- Set the center cell (located at 4,4) to a random number utilizing
Matrix.changeBoard(self, cell:Cell)
- Parameter cell is retrieved from using
Matrix.self.board[4][4]
- Parameter cell is retrieved from using
- Start a while loop that runs if
Matrix.cells
contains anything - Get least number of choices of cell closest to being solved
- Important to mention that each time
Matrix.changeBoard()
is called, it sortsself.cells
to have the cells closest to being done in front
- Important to mention that each time
- Create a list of all cells that have least number amount of choices
- Randomly choose one cell from this list
- Call
Matrix.changeBoard()
with the random cell as the argument
End
To use this module all you have to do is set var_name = sudoku-oop.generateBoard()
and it will return a Matrix Object with your board
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Sudoku_DCHEQUER-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e0f41988c5b974e557d14a1462a3f149a175e608b3ba73c5c5329528fdff49f |
|
MD5 | ee57247fa5f25c3ba8a04408a21cd192 |
|
BLAKE2b-256 | 33a276964188c56262ade26f1a2f75a36e28c8ce20e7bc4f01c5ae8dc2eecee8 |