stepping
This module provides the base for any 'stepper' class plus a few example steppers used in the default solver. The steppers are devices used as backend for the formatted output of the solving process. Stepper objects provide an interface for the solving method classes to pass information about any successfully eliminated candidate. Moreover, they are able to pause the solving process after any successful elimination to pass the latter information to any frontend, thus enabling the user to step through the solving process, possibly by means of a graphical output.
AnyStep
#
Bases: StepperBase
Stepper class to transfer information about every elimination step to the frontend.
show_step(sudoku, affected_tiles, affected_options)
#
Invoke the render to print the solving step based on the previously specified consideration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sudoku |
Sudoku
|
The concerned puzzle |
required |
affected_tiles |
set
|
The tiles affected by the present configuration of the neighboring tiles |
required |
affected_options |
set
|
The candidate to be removed from the latter tiles |
required |
DeadStepper
#
Bases: StepperBase
Trivial 'stepper' class serving as default value for any variable whose
value must be of type StepperBase. That is, if no proper 'stepper' is
assigned, this placeholder will raise an error whenever the user tries to
make use of the abstract methods that any stepper needs to implement.
DeadTrigger
#
Bases: NoTrigger
Trivial trigger to raise an error when called. Such objects serve as
default argument for variables that take an object of type NoTrigger as
value.
InterestingStep
#
Bases: AnyStep
Stepper with functionality analogous to AnyStep but only solving steps
whose importance was set to 'interesting' by means of the respective
argument of the set_consideration method are rendered.
NoTrigger
#
Classes that implement the functionality to await any sort uf user input after the puzzle has been rendered.
trigger_next_step()
#
Trigger the next solving step.
Skipper
#
Bases: StepperBase
Trivial stepper class that only counts the solving steps without invoking any rendering or interrupting the solving process.
StepperBase
#
Base class providing the template for any stepper by implementing a solution-step counting mechanism and the interface to pass information about the current state of the puzzle through the stepper to the frontend.
__init__(formatter=None, trigger=None)
#
Create a stepper instance by passing a formatting function, i.e. a function to render the puzzle with additional information about the solving process
set_consideration(tiles, options, message, interesting=False)
abstractmethod
#
Tell the stepper what options of what tiles we're currently
considering to draw conclusions about what candidates we can eliminate.
The message will be printed at a successful elimination. The
interesting parameter specifies the complexity of the consideration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiles |
set
|
The tiles we consider to draw conclusion about possible future removals of candidates of neighboring tiles |
required |
options |
set
|
The candidates that allow for the latter conclusions |
required |
message |
str
|
The message to pass to the render when successfully removing candidates based on the latter conclusion. interesting: whether the removal step should be printed by a stepper that only cares about elaborate algorithms |
required |
show(sudoku)
#
Use the selected formatter to render the Sudoku without any information about the solving process.
show_step(*args)
abstractmethod
#
Invoke the frontend to print the current state of the Sudoku and
increase the solving step counter by one as this method is only called
after a successful elimination of a candidate.
StepperMissingError
#
Bases: NotImplementedError
No stepper has been assigned to the solving method.
TriggerMissingError
#
Bases: NotImplementedError
No trigger has been assigned to the stepper.