示例#1
0
文件: GUI.py 项目: taichatha/mysudoku
    def solvePuzzle(self):
        if self.n == 0:
            print "No grid. Generate a grid, or import one."

        elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.evenRecSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo( "Solved!", ("It took this long to solve the puzzle: ",(datetime.now()-startTime)))

        elif self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.recSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo( "Solved!", ("It took this long to solve the puzzle: ",(datetime.now()-startTime)))
            else:
                print "Already solved!"
示例#2
0
    def solvePuzzle(self):
        if self.n == 0:
            print "No grid. Generate a grid, or import one."

        elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.evenRecSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo(
                    "Solved!", ("It took this long to solve the puzzle: ",
                                (datetime.now() - startTime)))

        elif self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.recSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo(
                    "Solved!", ("It took this long to solve the puzzle: ",
                                (datetime.now() - startTime)))
            else:
                print "Already solved!"
示例#3
0
        def setN():

            self.cells = []
            self.n = int(E1.get())

            # A list of variables tied to entries
            if self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
                self.n == int(math.sqrt(self.n))

                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                grid = []
                startTime = datetime.now()
                stats = True
                while stats == True:
                    grid = sudokuGen.generator(int(math.sqrt(self.n)))
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.recSolve(answer)
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid,
                              width=3,
                              justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(row=i + 1,
                                                                  column=j + 1)
                tkMessageBox.showinfo(
                    "Generated!", ("It took this long to make the puzzle: ",
                                   (datetime.now() - startTime)))
                print sudokuGen.toString(self.puzzle)
            elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
                print "yes"
                print int(math.sqrt(self.n))
                self.n == int(self.n)
                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                stats = True
                grid = []
                startTime = datetime.now()
                while stats == True:
                    grid = sudokuGen.altGenrator(self.n)
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.evenRecSolve(answer)
                    print answer
                    print self.puzzle
                    print answer == self.puzzle
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid,
                              width=3,
                              justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(row=i + 1,
                                                                  column=j + 1)
                tkMessageBox.showinfo(
                    "Generated!", ("It took this long to make the puzzle: ",
                                   (datetime.now() - startTime)))
                print sudokuGen.toString(self.puzzle)
示例#4
0
文件: GUI.py 项目: taichatha/mysudoku
        def setN():

            self.cells = []
            self.n = int(E1.get())

             # A list of variables tied to entries
            if self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
                self.n == int(math.sqrt(self.n))

                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                grid = []
                startTime = datetime.now()
                stats = True
                while stats == True:
                    grid = sudokuGen.generator(int(math.sqrt(self.n)))
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.recSolve(answer)
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid, width=3, justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(
                            row=i+1, column=j+1)
                tkMessageBox.showinfo( "Generated!", ("It took this long to make the puzzle: ",(datetime.now()-startTime)))
                print sudokuGen.toString(self.puzzle)
            elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
                print "yes"
                print int(math.sqrt(self.n))
                self.n == int(self.n)
                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                stats = True
                grid = []
                startTime = datetime.now()
                while stats == True:
                    grid = sudokuGen.altGenrator(self.n)
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.evenRecSolve(answer)
                    print answer
                    print self.puzzle
                    print answer == self.puzzle
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid, width=3, justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(
                            row=i+1, column=j+1)
                tkMessageBox.showinfo( "Generated!", ("It took this long to make the puzzle: ",(datetime.now()-startTime)))
                print sudokuGen.toString(self.puzzle)