-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenGame.py
51 lines (41 loc) · 1.05 KB
/
genGame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__='Tim W'
import typlerGen, random # use the Tyler's generator
#sudoku game class
class sudokuGame(object):
#init
def __init__(self,difficulty,table):
self.num=difficulty
self.game=table
#return a list as sudoku game
def getSudokuGame(self):
for i in range(0,self.num):
tmp=random.randint(0,80)## ? can not keep the space is num so improve it
self.game[tmp]=0
return self.game
#out put the sudoku game list for human reading
def printSudoku(self):
tmpGame=self.getSudokuGame()
temp = []
for i in range(9):
temp.append([])
boxCtr = 0
rowCtr = 0
while boxCtr < 81:
for i in range(9):
temp[rowCtr].append(tmpGame[boxCtr])
boxCtr += 1
rowCtr += 1
for row in temp:
print row
def main():
#randomly choose the game difficulty
difficulty=random.randint(65,75)
#crete an instance of the sudoku game class
gameA=sudokuGame(difficulty,tylerGen.getTable())
#print(gameA.getSudokuGame())
gameA.printSudoku()
return 0
if __name__ == '__main__':
main()