def minConflict(filename): board=() checks=0 board,board_size,small_row,small_col=func.convertBoard(filename) board_copy=board #func.printBoard(board_copy,board_size) board_closed=[] board_dict={} board_dict=func.updateDict(board,board_size,small_row,small_col,{}) #find the board_closed cells for i in range(0,board_size): for j in range(0,board_size): if board[i][j]!=0: board_closed.append(board_size*i+j) #initialize board open cells with random values for i in range (0,board_size): for j in range (0,board_size): if board[i][j]==0: board[i][j]=random.randrange(1,board_size+1) bool_val,checks=minConflictRec(board,board_size,small_row,small_col,board_copy,board_dict,board_closed)# call the recursive function, get the final solution and #checks if (bool_val): print("\n successfully completed sudoku. ") # success else: print("\n not completed board. ",bool_val) # failure return(board,checks) return (board,checks)
def backtracking(filename): board,board_size,small_row,small_col=func.convertBoard(filename) # convert the board bool_val,checks=backtrackingRecursive(board,board_size,small_row,small_col) # call the recursive function, get the final solution and #checks if (bool_val): # if successfully completed execution then return board and checks with success mesage print("\n successfully completed sudoku. ") else: print("\n not completed board. ",bool_val)# if unsuccessful then return board and checks with failure mesage return(board,checks) return (board,checks)
def backtrackingMRVcp(filename): board=() global checks checks=0 board,board_size,small_row,small_col=func.convertBoard(filename) bool_val,checks=backtrackingRecursiveMRVcp(board,board_size,small_row,small_col)# call the recursive function, get the final solution and #checks if (bool_val): print("\n successfully completed sudoku. ") # success else: print("\n not completed board. ",bool_val) # failure return(board,checks) return (board,checks)