def run(): """Runs the Sudoku-solver Program""" board = sudoku.Board(puzzle) if sudoku.fill(board): print('Board has been solved, Final Board: \n') print(board) else: print('This puzzle cannot be solved') print(board)
def __init__(self, difficulty): self.running = True self.size = self.width, self.height = 660, 800 self.board = sudoku.Board(difficulty) self.initial = [[0 for i in range(self.board.size)] for j in range(self.board.size)] for i in range(self.board.size): for j in range(self.board.size): self.initial[i][j] = self.board.board[i][j] self.solution = self.board.copy() self.solution.solve()
def __init__(self, **kwargs): super().__init__(**kwargs) self.board = sudoku.Board() self.entries = [] self.title('Sudoku') self.geometry('501x425') self.resizable(False, False) self.create_widgets() self.new_game()
def get_board_from_image(im): width, height = im.size cell_width = width / 9 cell_height = height / 9 board = sudoku.Board() for i in range(0,9): for j in range(0,9): # crop the cell with a small margin to remove the borders cell_image = im.crop(( int((j+0.1)*cell_width), int((i+0.1)*cell_height), int((j+0.1)*cell_width+cell_width*0.8), int((i+0.1)*cell_height+cell_height*0.8))) try: board.values[j][i] = cell_to_number(cell_image) except ValueError: raise return board
while True: givensDict = {} # grab the data for row in range(9): for col in range(9): webCell = driver.find_element_by_xpath('//*[@id="f' + str(col) + str(row) + '"]') cellValue = webCell.get_property('value') if cellValue: givensDict[str((row, col))] = int(cellValue) board = sudoku.Board(9, givensDict) print("Solving the following board:") print(str(board)) # solve the puzzle board.solve() # enter the data for row in range(9): for col in range(9): solutionCell = board.getCellAt(row, col) webCell = driver.find_element_by_xpath('//*[@id="f' + str(col) + str(row) +
def solvePuzzle(puzzle): '''Solves the puzzle. Returns true if successful and false otherwise.''' board = sudoku.Board(puzzle) result = board.solve() return board, result
num = random.randint(0, 50) f = open("sudoku_boards.txt", "r") data = f.read().split("\n") f.close() num = 10 * num + 1 return [[int(char) for char in data[num + i]] for i in range(9)] if STATS_MODE == 0: cycles = [] failed = [] bigboi = 0 smolboi = 0 for i in range(51): print(i) board = sudoku.Board(generateBoard(i)) if SOLVER == "backTrackingSolve": cycle = backTrackingSolve(board) else: cycle = simpleSolve(board, Cells(board), False)[2] if cycle > 0: cycles.append(cycle) if cycle == max(cycles): bigboi = i if cycle == min(cycles): smolboi = i else: failed.append((i, cycle)) print(board) print()
cycle += 1 return -cycle def printBoard(self): print(self.board) if STATS_MODE: cycles = [] failed = [] bigboi = 0 smolboi = 0 for i in range(51): print(i) solve = Solver(sudoku.Board(generateBoard(i))) if SOLVER == "backTrackingSolve": cycle = solve.backTrackingSolve() else: cycle = solve.simpleSolve(False) if cycle > 0: cycles.append(cycle) if cycle == max(cycles): bigboi = i if cycle == min(cycles): smolboi = i else: failed.append((i, cycle)) solve.printBoard() print()