-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrinter.py
More file actions
50 lines (40 loc) · 1.47 KB
/
Printer.py
File metadata and controls
50 lines (40 loc) · 1.47 KB
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
"""
Printer class
performs arranging data and tries to visualise the board
you can add your custom output method by defining your method and adding its name to $draw_levels
your new method would be accessible by adding -d {index of your method in $draw_levels)
ex : py main.py 13 -ddd
"""
class Printer:
def __init__(self, size):
# stores possible methods for modular calls
self.draw_levels = ["show_blank_board", "show_short_board", "show_full_board"]
# store size for iterating
self.size = size
# shows nothing
def show_blank_board(self, position):
pass
# Show the full NxN board
def show_full_board(self, positions):
for row in range(self.size):
line = ""
for column in range(self.size):
if positions[row] == column:
line += "Q "
else:
line += ". "
print(line)
print("\n")
"""
Show the queens positions on the board in compressed form,
each number represent the occupied column position in the corresponding row.
"""
def show_short_board(self, positions):
line = ""
for i in range(self.size):
line += str(positions[i]) + " "
print(line)
# only callable function from outside, used to execute printing sequence
def print(self, level, positions):
printer = getattr(self, self.draw_levels[level])
printer(positions)