Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Final Project 組員:楊承叡、謝谷松.

Similar presentations


Presentation on theme: "Python Final Project 組員:楊承叡、謝谷松."— Presentation transcript:

1 Python Final Project 組員:楊承叡、謝谷松

2 數獨

3 遊戲規則 每行、每列、每宮均包含1~9, 不能缺少,也不能重複

4 製作動機 與其花錢買紙本題目,不如自己動手做!

5 目標 暴力破解數獨題目 題目產生 遊戲介面 2 2 4 4 9 8 7

6 1. 演算法 題目產生 & 暴力破解數獨題目

7 題目產生 產生完成的題目 挖空格 檢查是否單一解 2 2 4 4 6 8 9

8 暴力破解 def solve(self, index=None, number=None): i = self.getEmptyGrid()
if i is None: return True for num in range(1, 10): if i == index and str(num) == number: continue if self.checkNum(i, num): self.board[i] = str(num) if self.solve(): self.board[i] = '0' return False 暴力破解

9 暴力破解

10 產生解答 def generateSolvedPuzzle(self): index = self.getIndex()
if index is None: return True possibleNum = [num for num in range(1, 10)] for i in range(1, 10): if not self.checkNum(index, i): possibleNum.remove(i) if len(possibleNum) == 0: return False shuffle(possibleNum) for num in possibleNum: self.board[index] = str(num) copyBoard = list(self.board) if self.indexCount < 17 or solver(copyBoard).solve(): if self.generateSolvedPuzzle(): # can't solved self.board[index] = '0' self.indexCount -= 1 產生解答

11 挖空格 檢查唯一解 def generatePuzzle(self): while True: clue = 81
shuffle(self.index) for i in self.index: # a valid sudoku puzzle must have at least 17 non-empty grids if clue <= 17: break tempNum = self.board[i] self.board[i] = '0' copyBoard = list(self.board) sol = solver(copyBoard) if not sol.solve(i, tempNum): # this is the only one answer puzzle clue -= 1 else: self.board[i] = tempNum if clue <= 51: 挖空格 檢查唯一解

12 題庫

13 2. 遊戲介面 使用 Tkinter 製作

14 遊戲介面 可做記號 難易度 遊戲提示 計時功能 遊戲紀錄 2 2 4 4 6 8 9

15 遊戲介面

16 遊戲介面


Download ppt "Python Final Project 組員:楊承叡、謝谷松."

Similar presentations


Ads by Google