Sudoku Showcase
Public Member Functions | Public Attributes | List of all members
sudoku.app.App Class Reference

The App is the central Controller and API of the application following Model-View-Controller architecture. More...

Public Member Functions

def __init__ (self, bool useUi=True, bool verbose=True)
 
int|None selectedDigit (self)
 Properties - State Management. More...
 
None selectedDigit (self, int|None digit)
 Sets the property selectedDigit to a valid value or no value. More...
 
tuple[int, int]|None selectedCell (self)
 (property) The selected cell defines the field/cell in the puzzle. More...
 
None selectedCell (self, tuple[int, int]|None pos)
 Sets the property selectedCell to a tuple of coordinates or None. More...
 
bool inEraseMode (self)
 (property) Defines if app is in eraseMode or not. More...
 
bool inNoteMode (self)
 (property) Defines if app is in noteMode or not. More...
 
bool highlightRules (self)
 (property) Defines if the ui visualizes the sudoku rules depending on the selected cell. More...
 
bool highlightDigits (self)
 (property) Defines if the ui is visualizing the digits in the puzzle depending on the selected Digit. More...
 
None toggleEraseMode (self)
 toggle property functions More...
 
None toggleNoteMode (self)
 Toggle property noteMode. More...
 
None toggleHighlightRules (self)
 Toggle property highlightRules. More...
 
None toggleHighlightDigits (self)
 Toggle property highlighDigits. More...
 
set[tuple[int, int]] getErrorCells (self)
 public property functions More...
 
None addErrorCell (self, int row, int col)
 Adds a cell to errorCells. More...
 
None removeErrorCell (self, int row, int col)
 Removes a Cell from errorCells. More...
 
None clearErrorCells (self)
 Removes all cells from errorCells. More...
 
None selectDigit (self, int value)
 Sets the selectedDigit to the value. More...
 
None selectCell (self, int row, int col)
 Sets a cell as selected. More...
 
None deselectCell (self)
 Deselects the cell. More...
 
None run (self)
 Game Core Functions. More...
 
None startNewGame (self, str difficulty)
 Starts a new Game and creates the ui, if needed. More...
 
None restartGame (self)
 Restarts the current game. More...
 
bool hasGameEnded (self)
 If the current game has ended. More...
 
str getPuzzle (self)
 Game Core getter Functions. More...
 
int getGridSize (cls)
 (classmethod) Returns the size of the grid (Puzzle) More...
 
int getBlockSize (cls)
 (classmethod) Returns the size of a Block. More...
 
str getCurrentDifficulty (self)
 Returns the difficulty of the current game. More...
 
str getDefaultDifficulty (self)
 Returns the default difficulty of game. More...
 
list[str] getAllDifficultyNames (cls)
 (classmethod) Returns the names of difficulty levels. More...
 
int getMistakesMade (self)
 Returns the amount of mistakes made in the current game. More...
 
int getMaxMistakes (cls)
 (classmethod) Returns the maximum amount of mistakes per game. More...
 
int getElapsedTime (self)
 Returns the elapsed time in seconds of the current game. More...
 
None handleMove (self, int row, int col)
 Game Move Functions. More...
 
int|None getFieldValue (self, int row, int col)
 Setter / Getter Functions (Field, Digits) More...
 
str getFieldLabel (self, int row, int col)
 Returns the Label for a Field at (row, col) More...
 
list[int] getFieldNotes (self, int row, int col)
 Returns a list with all Notes from a Field. More...
 
None printField (self, int row, int col)
 Prints the Field attributes. More...
 
bool isFieldFixed (self, int row, int col)
 Returns if a field is fixed. More...
 
list[int]|list getSetDigits (self)
 Returns all the Digits, which occur 9 times in the current game. More...
 
None setAutoNotes (self)
 Set Notes for all Fields automatically. More...
 
None clearAllNotes (self)
 Clear all notes in the puzzle. More...
 

Public Attributes

 selectedDigit
 
 selectedCell
 

Detailed Description

The App is the central Controller and API of the application following Model-View-Controller architecture.

It coordinates all major components:

The App also controls overall game flow logic, such as erase modes and other UI-related behaviors, which are intentionally separated from the core game logic.

This design intentionally results in a larger class with many forwarding functions, in order to keep submodules and domain classes cleaner and better separated.

Constructor & Destructor Documentation

◆ __init__()

def sudoku.app.App.__init__ (   self,
bool   useUi = True,
bool   verbose = True 
)

Member Function Documentation

◆ addErrorCell()

None sudoku.app.App.addErrorCell (   self,
int  row,
int  col 
)

Adds a cell to errorCells.

Parameters
rowint
colint
Returns
None

◆ clearAllNotes()

None sudoku.app.App.clearAllNotes (   self)

Clear all notes in the puzzle.

Returns
None

◆ clearErrorCells()

None sudoku.app.App.clearErrorCells (   self)

Removes all cells from errorCells.

Returns
None

◆ deselectCell()

None sudoku.app.App.deselectCell (   self)

Deselects the cell.

Returns
None

◆ getAllDifficultyNames()

list[str] sudoku.app.App.getAllDifficultyNames (   cls)

(classmethod) Returns the names of difficulty levels.

Returns
list[str]

◆ getBlockSize()

int sudoku.app.App.getBlockSize (   cls)

(classmethod) Returns the size of a Block.

Returns
int

◆ getCurrentDifficulty()

str sudoku.app.App.getCurrentDifficulty (   self)

Returns the difficulty of the current game.

Returns
str

◆ getDefaultDifficulty()

str sudoku.app.App.getDefaultDifficulty (   self)

Returns the default difficulty of game.

Returns
str

◆ getElapsedTime()

int sudoku.app.App.getElapsedTime (   self)

Returns the elapsed time in seconds of the current game.

Returns
int

◆ getErrorCells()

set[tuple[int, int]] sudoku.app.App.getErrorCells (   self)

public property functions

Returns the current errorcells.

Returns
set[tuple[int, int]]

◆ getFieldLabel()

str sudoku.app.App.getFieldLabel (   self,
int  row,
int  col 
)

Returns the Label for a Field at (row, col)

Parameters
rowint - the row of the field in question
colint - the column of the field in question
Returns
str

◆ getFieldNotes()

list[int] sudoku.app.App.getFieldNotes (   self,
int  row,
int  col 
)

Returns a list with all Notes from a Field.

NOTE: The list can be empty.

Parameters
rowint - the row of the field in question
colint - the column of the field in question
Returns
list[int]

◆ getFieldValue()

int | None sudoku.app.App.getFieldValue (   self,
int  row,
int  col 
)

Setter / Getter Functions (Field, Digits)

Returns the value for a Field at (row, col)

Parameters
rowint - the row of the field in question
colint - the column of the field in question
Returns
int | None

◆ getGridSize()

int sudoku.app.App.getGridSize (   cls)

(classmethod) Returns the size of the grid (Puzzle)

Returns
int

◆ getMaxMistakes()

int sudoku.app.App.getMaxMistakes (   cls)

(classmethod) Returns the maximum amount of mistakes per game.

Returns
int

◆ getMistakesMade()

int sudoku.app.App.getMistakesMade (   self)

Returns the amount of mistakes made in the current game.

Returns
int

◆ getPuzzle()

str sudoku.app.App.getPuzzle (   self)

Game Core getter Functions.

Returns the str-repr of the current puzzle.

Returns
str

◆ getSetDigits()

list[int] | list sudoku.app.App.getSetDigits (   self)

Returns all the Digits, which occur 9 times in the current game.

NOTE: list can be empty!

Returns
list[int] | list

◆ handleMove()

None sudoku.app.App.handleMove (   self,
int  row,
int  col 
)

Game Move Functions.

Lets the game handle a move depending on modes and the selectedDigit. Additionally checks if game over or won.

Parameters
rowint
colint
Returns
None

◆ hasGameEnded()

bool sudoku.app.App.hasGameEnded (   self)

If the current game has ended.

Returns
bool

◆ highlightDigits()

bool sudoku.app.App.highlightDigits (   self)

(property) Defines if the ui is visualizing the digits in the puzzle depending on the selected Digit.

NOTE: This setting does not affect the gameplay itself.

See also
self.toggleHighlightDigits(), to set the highlightDigits
Returns
bool

◆ highlightRules()

bool sudoku.app.App.highlightRules (   self)

(property) Defines if the ui visualizes the sudoku rules depending on the selected cell.

NOTE: This setting does not affect the gameplay itself.

See also
self.toggleHighlightRules(), to set the highlightDigits
Returns
bool

◆ inEraseMode()

bool sudoku.app.App.inEraseMode (   self)

(property) Defines if app is in eraseMode or not.

In eraseMode, the selectedCell will be set to no value. To set the eraseMode, use self.toggleEraseMode()

Returns
bool

◆ inNoteMode()

bool sudoku.app.App.inNoteMode (   self)

(property) Defines if app is in noteMode or not.

In noteMode, the selectedDigit can be assigned as a note to the selectedCell To set the NoteMode, use self.toggleNoteMode()

Returns
bool

◆ isFieldFixed()

bool sudoku.app.App.isFieldFixed (   self,
int  row,
int  col 
)

Returns if a field is fixed.

Returns
bool

◆ printField()

None sudoku.app.App.printField (   self,
int  row,
int  col 
)

Prints the Field attributes.

Parameters
rowint - the row of the field in question
colint - the column of the field in question
Returns
str

◆ removeErrorCell()

None sudoku.app.App.removeErrorCell (   self,
int  row,
int  col 
)

Removes a Cell from errorCells.

Parameters
rowint
colint
Returns
None

◆ restartGame()

None sudoku.app.App.restartGame (   self)

Restarts the current game.

Usually called from Client.

Returns
None

◆ run()

None sudoku.app.App.run (   self)

Game Core Functions.

Starts to run the application. and creates a new game with default difficulty

Returns
None

◆ selectCell()

None sudoku.app.App.selectCell (   self,
int  row,
int  col 
)

Sets a cell as selected.

Requirement to show rules.

Parameters
rowint - the row of selected cell
colint - the column of selected cell
Returns
None

◆ selectDigit()

None sudoku.app.App.selectDigit (   self,
int  value 
)

Sets the selectedDigit to the value.

NOTE: if digit is already selected, it will be deselected. (like toggling)

Parameters
valueint - the newly selected digit
Returns
None

◆ selectedCell() [1/2]

tuple[int, int] | None sudoku.app.App.selectedCell (   self)

(property) The selected cell defines the field/cell in the puzzle.

Required to visualize the sudoku rules in the ui. To set a value, use self.selectedCell = tuple(int(x), int(y))

Returns
tuple[int,int] | None

◆ selectedCell() [2/2]

None sudoku.app.App.selectedCell (   self,
tuple[int, int] | None  pos 
)

Sets the property selectedCell to a tuple of coordinates or None.

Parameters
postuple | None
Returns
None

◆ selectedDigit() [1/2]

int | None sudoku.app.App.selectedDigit (   self)

Properties - State Management.

(property) The selected digit defines the value assigned to field/cell in the puzzle. Returns a digit [1 .. 9] if selected. To set the selectedDigit, use self.selectedDigit = value

Returns
int | None

◆ selectedDigit() [2/2]

None sudoku.app.App.selectedDigit (   self,
int | None  digit 
)

Sets the property selectedDigit to a valid value or no value.

Parameters
digitint | None
Returns
None

◆ setAutoNotes()

None sudoku.app.App.setAutoNotes (   self)

Set Notes for all Fields automatically.

Returns
None

◆ startNewGame()

None sudoku.app.App.startNewGame (   self,
str  difficulty 
)

Starts a new Game and creates the ui, if needed.

All game-related settings will be reset.

Parameters
difficultystr
Returns
None

◆ toggleEraseMode()

None sudoku.app.App.toggleEraseMode (   self)

toggle property functions

Toggle property eraseMode.

Returns
None

◆ toggleHighlightDigits()

None sudoku.app.App.toggleHighlightDigits (   self)

Toggle property highlighDigits.

Returns
None

◆ toggleHighlightRules()

None sudoku.app.App.toggleHighlightRules (   self)

Toggle property highlightRules.

Returns
None

◆ toggleNoteMode()

None sudoku.app.App.toggleNoteMode (   self)

Toggle property noteMode.

Returns
None

Member Data Documentation

◆ selectedCell

sudoku.app.App.selectedCell

◆ selectedDigit

sudoku.app.App.selectedDigit

The documentation for this class was generated from the following file: