-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathline.py
69 lines (52 loc) · 1.74 KB
/
line.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from cell import Cell
import util
class Line:
def __init__(self, cell_list: list):
util.check_value_count('Line', cell_list)
self.possible_value = [x for x in range(1, 10)]
for cell in cell_list:
if cell.value not in self.possible_value:
continue
self.possible_value.remove(cell.value)
self.cell_list = cell_list
def remove_possible_value(self, value):
result = Cell.OK
for cell in self.cell_list:
remove_result = cell.remove_possible_value(value)
if remove_result == Cell.CONTRADICT:
return Cell.CONTRADICT
if remove_result == Cell.FIND:
result = Cell.FIND
return result
def find_only_value(self):
value_list = [0] * 10
result_cell_list = [None] * 10
for cell in self.cell_list:
if cell.value != 0:
continue
for possible_value in cell.possible_value:
value_list[possible_value] += 1
result_cell_list[possible_value] = cell
if 1 not in value_list:
return None, None
i = value_list.index(1)
return result_cell_list[i], i
def __str__(self):
buffer = '|'
for cell in self.cell_list:
buffer += f' {cell} |'
return buffer
if __name__ == '__main__':
cell_list = list()
for v in range(1, 10):
cell_list.append(Cell(v))
line = Line(cell_list)
print(line)
cell_list = list()
for v in range(2, 10):
cell_list.append(Cell(0))
cell_list.append(Cell(1))
line = Line(cell_list)
print(cell_list[0].possible_value)
line.find_only_value()
print(cell_list[0].possible_value)