Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sudoku/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Sudoku:
_empty_cell_value = None # type: None
__difficulty = None # type: float

def __init__(self, width = 3, height = None, board = None, difficulty = None, seed = randrange(sys.maxsize)):
def __init__(self, width = 3, height = None, board = None, difficulty = None, seed = None):
# type: (int, Optional[int], Optional[Iterable[Iterable[Optional[int]]]], Optional[float], int) -> None
"""
Initializes a Sudoku board
Expand All @@ -192,7 +192,7 @@ def __init__(self, width = 3, height = None, board = None, difficulty = None, se
:param height: Optional integer representing the height of the Sudoku grid. If not provided, defaults to the value of `width`.
:param board: Optional iterable for a the initial state of the Sudoku board.
:param difficulty: Optional float representing the difficulty level of the Sudoku puzzle. If provided, sets the difficulty level based on the number of empty cells. Defaults to None.
:param seed: Integer representing the seed for the random number generator used to generate the board. Defaults to a random seed within the system's maximum size.
:param seed: Integer representing the seed for the random number generator used to generate the board. Defaults to a runtime-generated random seed within the system's maximum size.

:raises AssertionError: If the width, height, or size of the board is invalid.
"""
Expand All @@ -204,6 +204,10 @@ def __init__(self, width = 3, height = None, board = None, difficulty = None, se
assert self.height > 0, 'Height cannot be less than 1'
assert self.size > 1, 'Board size cannot be 1 x 1'

if seed is None:
# Generate a fresh random seed every time this is called unless the user explicitly provides it
seed = randrange(sys.maxsize)

if difficulty is not None:
self.__difficulty = difficulty

Expand Down Expand Up @@ -390,7 +394,7 @@ def __str__(self):
class DiagonalSudoku(Sudoku):
__difficulty = None # type: float

def __init__(self, size = 3, board = None, difficulty = None, seed = randrange(sys.maxsize)):
def __init__(self, size = 3, board = None, difficulty = None, seed = None):
# type: (int, Optional[Iterable[Iterable[Optional[int]]]], Optional[float], int) -> None
self.width = size
self.height = size
Expand All @@ -403,6 +407,10 @@ def __init__(self, size = 3, board = None, difficulty = None, seed = randrange(s
assert self.height > 0, 'Height cannot be less than 1'
assert self.size > 1, 'Board size cannot be 1 x 1'

if seed is None:
# Generate a fresh random seed every time this is called unless the user explicitly provides it
seed = randrange(sys.maxsize)

if difficulty is not None:
self.__difficulty = difficulty

Expand Down