Exemplo n.º 1
0
def CreateSudoImg(
    A, sourceimg, destination
):  #Adds new Sudoku problem as png image to the desirable folder
    # font = ImageFont.truetype("/usr/share/fonts/dejavu/DejaVuSans.ttf", 18)
    img = Image.open(sourceimg + "/image.png")
    draw = ImageDraw.Draw(img)
    for i in range(9):
        for j in range(9):
            if (A[i, j] != 0):
                draw.text((j * 25 + 8, i * 25 + 3), str(A[i, j]), fill=2)
                draw = ImageDraw.Draw(img)

    if not os.path.exists(destination):
        os.mkdir(destination)
        os.mkdir(destination + "/Arr")
        os.mkdir(destination + "/Img")
        os.mkdir(destination + "/Sol")

    file_list = os.listdir(destination + "/Arr")
    file_count = len(file_list) + 1

    # imgname="/Img/Prob"+str(file_count)+".png"
    arrayname = "/Arr/Array" + str(file_count) + ".npy"
    solutionname = "/Sol/Solution" + str(file_count) + ".npy"

    # img.save(destination+imgname)
    np.save(destination + arrayname, A)
    sol_A = SL.SudoSolveIt2(A, [], 1)
    np.save(destination + solutionname, sol_A)
Exemplo n.º 2
0
def onPressSolve(A):
    if (np.min(A) >= 0 and np.max(A) <= 9):
        if (SC.IsSudoRight(A)):
            print("Solver", "Already Solved!")
        else:
            Adef = A.copy()
            if (GU.CountSolutions(Adef, [], 0, 1) == 1):
                sol_A = SL.SudoSolveIt2(A, [], 1)
                print(A)
            else:
                print("Solver", "There isn't unique solution!")
    else:
        print("Solver", "Wrong inputs!")
Exemplo n.º 3
0
 def onPressSolve():
     A=np.zeros((9,9), dtype=int)
     i=0
     for row in rows:
         j=0
         for col in row:
             A[i,j]=int(col.get())
             j=j+1
         i=i+1
     if (np.min(A)>=0 and np.max(A)<=9):
         if (SC.IsSudoRight(A)):
             printMes("Solver","Already Solved!")
         else:
             Adef=deepcopy(A)
             if (GU.CountSolutions(Adef,[],0,1)==1):
                 A=SL.SudoSolveIt2(A,[],1)
                 print(A)
             else:
                 printMes("Solver","There isn't unique solution!")
     else:
         printMes("Solver","Wrong inputs!")
 
     mw.destroy()
Exemplo n.º 4
0
def solvabel(m):
    A = deepcopy(m)
    return np.min(SL.SudoSolveIt2(A, [], 1)) > 0
Exemplo n.º 5
0
    difficulty = ""
    back_dir = "sudoku" + difficulty
    # back_dir = "sudoku"

    with open(os.path.join(back_dir, 'features.pt'), 'rb') as f:
        X_in = torch.load(f)
    with open(os.path.join(back_dir, 'labels.pt'), 'rb') as f:
        Y_in = torch.load(f)
    # # #
    X_numpy, Y_numpy = process_inputs(X_in, Y_in)
    print(X_numpy[0])
    print(Y_numpy[0])

    np.save(os.path.join(back_dir, difficulty + '.npy'), X_numpy)
    np.save(os.path.join(back_dir, difficulty + 'label.npy'), Y_numpy)
    exit(0)

    file_X = difficulty + ".npy"
    file_Y = difficulty + "_label.npy"
    X = np.load(os.path.join(back_dir, file_X))
    features = np_back_torch(X)
    torch.save(features, os.path.join(back_dir, "features.pt"))

    Y = np.zeros(shape=X.shape)
    for i, _ in enumerate(Y):
        print(i)
        Y[i] = SL.SudoSolveIt2(X[i], [], 1)

    labels = np_back_torch(Y)
    torch.save(labels, os.path.join(back_dir, "labels.pt"))