-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSudokuChooser.py
36 lines (27 loc) · 1.01 KB
/
SudokuChooser.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
from sudoku import Sudoku
import random
class SudokuChooser:
def __init__(self,difficulty='easiest'):
self.difficulty={
'easiest':'puzzles1.txt',
'easy':'puzzles2.txt',
'normal':'puzzles3.txt',
'hard':'puzzles4.txt',
'hardest':'puzzles5.txt'}
if difficulty not in self.difficulty:
print(f'Difficulty string must be one of:easiest,easy,normal,hard,hardest ({difficulty} given)')
print(f'Selecting easiest difficulty')
difficulty='easiest'
random.seed(3)
self.puzzleFile=self.difficulty[difficulty]
self.newPuzzle()
def getPuzzle(self):
return self.currentPz
def newPuzzle(self):
idx=random.randint(0,10000)
#print(f'new index chosen {idx}')
with open(self.puzzleFile,'r') as pzfile:
strpz=pzfile.readlines()[idx]
#print(f'Read puzzle:{strpz}')
self.currentPz=Sudoku(strpz[:-1])
return self.currentPz