def backtrack(strippedList): Sudoku_validCheck.validCheck(Sudoku_board.board.tileList()) for tile in sortedList: for validValue in tile.validValues(): tile.setValue(validValue) Sudoku_validCheck.validCheck((Sudoku_board.board.tileList())) #Keep things up to date here... Sudoku_main.main() if Sudoku_main.isComplete()==True: return else: Sudoku_main.reset() Sudoku_main.createScenario3() #Ah, this solves the mystery Sudoku_view.view()
def solveSudoku(tileList): """ Takes a partially filled-in grid and attempts to assign values to all unassigned locations in such a way to meet the requirements for Sudoku solution (non-duplication across rows, columns, and boxes) """ # index; #Index unused, inaccurate? index=findUnassignedLocation(tileList) # print index.name() # If there is no unassigned location, we are done if (findUnassignedLocation(tileList)==False): Sudoku_view.view() return True # success! # consider digits 1 to 9 for num in index.validValues(): if (isValid(index,num)): index.setValue(num) Sudoku_validCheck.validCheck(Sudoku_board.board.tileList()) if Sudoku_main.main()==True: #TEST# Sudoku_view.view() return True else: Sudoku_main.reset() Sudoku_main.createScenario3() index.setValue(num) if solveSudoku(tileList): return True index.setValue(-1) return False # this triggers backtracking #solveSudoku(Sudoku_board.board.tileList()) #elapsed = timeit.default_timer() - start_time #print elapsed