|
@@ -2,7 +2,7 @@ class Board:
|
|
|
symbols = "123456789"
|
|
|
blank = "."
|
|
|
|
|
|
- _board = ['.' * 10 for i in range(9)]
|
|
|
+ _board = ["." * 10 for i in range(9)]
|
|
|
|
|
|
def set_initial(self, board: list):
|
|
|
self._board = board.copy()
|
|
@@ -16,16 +16,16 @@ class Board:
|
|
|
def get_block(self, x, y):
|
|
|
row = x // 3
|
|
|
col = y // 3
|
|
|
- return [r[col * 3:(col + 1) * 3] for r in self._board[row * 3:(row + 1) * 3]]
|
|
|
+ return [r[col * 3 : (col + 1) * 3] for r in self._board[row * 3 : (row + 1) * 3]]
|
|
|
|
|
|
def is_blank(self, x, y):
|
|
|
return self._board[x][y] == self.blank
|
|
|
-
|
|
|
+
|
|
|
def is_solved(self):
|
|
|
return self.blank not in "".join(self._board)
|
|
|
|
|
|
def set_cell(self, x, y, value):
|
|
|
- self._board[x] = self._board[x][:y] + value + self._board[x][y + 1:]
|
|
|
+ self._board[x] = self._board[x][:y] + value + self._board[x][y + 1 :]
|
|
|
|
|
|
def get_possibilities(self, x, y):
|
|
|
all_symbols = list(self.get_row(x) + self.get_col(y) + "".join(self.get_block(x, y)))
|
|
@@ -40,12 +40,12 @@ class Board:
|
|
|
if self.is_blank(i, j) and len(self.get_possibilities(i, j)) == 1:
|
|
|
return (i, j)
|
|
|
return None
|
|
|
-
|
|
|
+
|
|
|
def get_next_blank(self):
|
|
|
for i in range(9):
|
|
|
for j in range(9):
|
|
|
if self.is_blank(i, j):
|
|
|
- return (i, j)
|
|
|
+ return (i, j)
|
|
|
|
|
|
def solve(self):
|
|
|
while cell := self.get_unique_cell():
|