Sudoku Showcase
Public Member Functions | Static Public Attributes | List of all members
field.Field Class Reference

Represents the atomic unit of a Sudoku puzzle: a single Field. More...

Public Member Functions

def __init__ (self, int x, int y, int value=0, bool fixed=False, set|None notes=None)
 
str __str__ (self)
 The represent when using str(Fieldobj) Recommended usage on console. More...
 
int|list|None __repr__ (self)
 The represent when not using str(Fieldobj) More...
 
None printDict (self)
 Prints all attributs of Field on cli. More...
 
None inspect (self)
 Prints the public attributes of Field on cli. More...
 
"Field" clone (cls, "Field" other)
 (classmethod) Returns a flat copy of a Field (call-by-value) Usage: newField = Field.clone(oldField) More...
 
int x (self)
 Properties. More...
 
int row (self)
 (readonly property) The row where the Field is located in the puzzle. More...
 
int y (self)
 (readonly property) The y-coordinate of a Field. More...
 
int col (self)
 (readonly property) The column where the Field is located in the puzzle. More...
 
tuple[int, int] position (self)
 (readonly property) Position as a tuple of ints. More...
 
tuple[int, int] pos (self)
 (readonly property) abbreviation for property position NOTE: The values are set on initialization. More...
 
int|None value (self)
 (property) The value the Field contains NOTE: Default is None More...
 
None value (self, int x)
 Set a valid value to value-property of a non-fixed Field NOTE: to clear a value,. More...
 
bool fixed (self)
 (property) Wether a Field is editable or not. More...
 
None fixed (self, bool value)
 Sets the property fixed to True, in other words: Locks the Field NOTE: There is no way to unlock a Field NOTE: Has to be Not-Empty to do so. More...
 
bool isEmpty (self)
 (readonly property) Wether a Field has a value or not (value is None) More...
 
set[int] notes (self)
 (readonly property) Returns a set of notes for the Field. More...
 
bool addNote (self, int x)
 Functions. More...
 
bool removeNote (self, int x)
 Removes a note from the set, if in the list. More...
 
None clearNotes (self)
 Deletes the current set of notes. More...
 
bool clear (self)
 The only way to set a non-fixed Field to empty (value is None). More...
 
int getRandomValue (cls)
 (classmethod) Returns random valid value More...
 

Static Public Attributes

 NULL = None
 
string DEFAULT_AS_STRING = " "
 

Detailed Description

Represents the atomic unit of a Sudoku puzzle: a single Field.

A Field stores its position, value, fixed state, and possible candidate notes. It is designed with defensive programming principles and behaves as a near-immutable data object when used correctly through its public API.

The class enforces strict validation for all modifications and ensures that Sudoku constraints are respected at the field level. Direct manipulation of internal state is intentionally restricted.

A Field can:

Field provides utility functions for cloning, inspection, and random value generation (used primarily during puzzle creation).

The value setter automatically clears notes when a value is assigned, ensuring consistency between solved state and candidate state.

Constructor & Destructor Documentation

◆ __init__()

def field.Field.__init__ (   self,
int  x,
int  y,
int   value = 0,
bool   fixed = False,
set | None   notes = None 
)

Member Function Documentation

◆ __repr__()

int | list | None field.Field.__repr__ (   self)

The represent when not using str(Fieldobj)

Returns
int | list | None

◆ __str__()

str field.Field.__str__ (   self)

The represent when using str(Fieldobj) Recommended usage on console.

Returns
str

◆ addNote()

bool field.Field.addNote (   self,
int  x 
)

Functions.

Adds a note, if field is empty and value is allowed

Parameters
xint - the value of the note
Returns
bool - if successfull

◆ clear()

bool field.Field.clear (   self)

The only way to set a non-fixed Field to empty (value is None).

Returns
bool - if successfull

◆ clearNotes()

None field.Field.clearNotes (   self)

Deletes the current set of notes.

Returns
None

◆ clone()

"Field" field.Field.clone (   cls,
"Field"  other 
)

(classmethod) Returns a flat copy of a Field (call-by-value) Usage: newField = Field.clone(oldField)

Returns
Field

◆ col()

int field.Field.col (   self)

(readonly property) The column where the Field is located in the puzzle.

Also known as y. NOTE: The value is set on initialization.

Returns
int

◆ fixed() [1/2]

bool field.Field.fixed (   self)

(property) Wether a Field is editable or not.

Returns
bool

◆ fixed() [2/2]

None field.Field.fixed (   self,
bool  value 
)

Sets the property fixed to True, in other words: Locks the Field NOTE: There is no way to unlock a Field NOTE: Has to be Not-Empty to do so.

Parameters
valuebool - has to be True. False will be ignored
Returns
None

◆ getRandomValue()

int field.Field.getRandomValue (   cls)

(classmethod) Returns random valid value

Returns
int

◆ inspect()

None field.Field.inspect (   self)

Prints the public attributes of Field on cli.

Returns
None

◆ isEmpty()

bool field.Field.isEmpty (   self)

(readonly property) Wether a Field has a value or not (value is None)

Returns
bool

◆ notes()

set[int] field.Field.notes (   self)

(readonly property) Returns a set of notes for the Field.

To change the current set of notes:

◆ pos()

tuple[int, int] field.Field.pos (   self)

(readonly property) abbreviation for property position NOTE: The values are set on initialization.

Returns
tuple[int,int]

◆ position()

tuple[int,int] field.Field.position (   self)

(readonly property) Position as a tuple of ints.

NOTE: The values are set on initialization.

Returns
tuple[int, int]

◆ printDict()

None field.Field.printDict (   self)

Prints all attributs of Field on cli.

Returns
None

◆ removeNote()

bool field.Field.removeNote (   self,
int  x 
)

Removes a note from the set, if in the list.

Parameters
xint - - the value of the note to be removed from set
Returns
bool - if successfull

◆ row()

int field.Field.row (   self)

(readonly property) The row where the Field is located in the puzzle.

Also known as x. NOTE: The value is set on initialization.

Returns
int

◆ value() [1/2]

int | None field.Field.value (   self)

(property) The value the Field contains NOTE: Default is None

Returns
int | None

◆ value() [2/2]

None field.Field.value (   self,
int  x 
)

Set a valid value to value-property of a non-fixed Field NOTE: to clear a value,.

See also
clear()
Parameters
xint - the value to set
Exceptions
ValueError- if value is not in [1 ... 9]
Exception- on editing a fixed Field
Returns
None

◆ x()

int field.Field.x (   self)

Properties.

(readonly property) The x-coordinate of a Field. Also known as row. NOTE: The value is set on initialization.

Returns
int

◆ y()

int field.Field.y (   self)

(readonly property) The y-coordinate of a Field.

Also known as column

Returns
int

Member Data Documentation

◆ DEFAULT_AS_STRING

string field.Field.DEFAULT_AS_STRING = " "
static

◆ NULL

field.Field.NULL = None
static

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