-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle_creator.py
51 lines (45 loc) · 1.38 KB
/
puzzle_creator.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
from random import shuffle
from board import Board
from board_filler import BoardFiller
class PuzzleCreator(object):
def __init__(
self,
board=None
):
self.board = board
@staticmethod
def random_board():
board = Board(3, 9)
board_filler = BoardFiller(
board,
shuffle_choices=True,
shuffle_squares=True
)
assert board_filler.fill()
assert board.is_valid()
return board
def create_puzzle(self, num_decisions, square_difficulty):
if not self.board:
board = PuzzleCreator.random_board()
else:
board = self.board
"""
@param num_decisions: how many squares a player will need to fill
before the board is "complete"
@param square_difficulty: the maximum number of values the easiest square could
possibly be
"""
squares = list(board.all_squares())
shuffle(squares)
while True:
if num_decisions == 0:
break
for square in squares:
square.choice = None
num_decisions -= 1
if num_decisions == 0:
break
return board
if __name__ == "__main__":
for i in xrange(5, 60, 7):
print PuzzleCreator().create_puzzle(i, 2).ascii()