generators for squares on same line or column
This commit is contained in:
parent
41b14087e2
commit
77353b77b3
1 changed files with 45 additions and 0 deletions
|
@ -192,3 +192,48 @@ class Square:
|
|||
def is_empty(self):
|
||||
return self.state == ' '
|
||||
|
||||
def all_prev_horiz(self):
|
||||
h_prev = self.prev_horiz()
|
||||
all_prev_horiz_list = []
|
||||
while h_prev:
|
||||
all_prev_horiz_list.append(h_prev)
|
||||
h_prev = h_prev.prev_horiz()
|
||||
return all_prev_horiz_list
|
||||
|
||||
def all_next_horiz(self):
|
||||
h_next = self.prev_horiz()
|
||||
all_next_horiz_list = []
|
||||
while h_next:
|
||||
all_next_horiz_list.append(h_next)
|
||||
h_next = h_next.prev_horiz()
|
||||
return all_next_horiz_list
|
||||
|
||||
def all_prev_vert(self):
|
||||
v_prev = self.prev_horiz()
|
||||
all_prev_vert_list = []
|
||||
while v_prev:
|
||||
all_prev_vert_list.append(v_prev)
|
||||
v_prev = v_prev.prev_horiz()
|
||||
return all_prev_vert_list
|
||||
|
||||
def all_next_vert(self):
|
||||
v_next = self.prev_horiz()
|
||||
all_next_vert_list = []
|
||||
while v_next:
|
||||
all_next_vert_list.append(v_next)
|
||||
v_next = v_next.prev_horiz()
|
||||
return all_next_vert_list
|
||||
|
||||
def same_line(self):
|
||||
line_list = []
|
||||
line_list.extend(self.all_prev_horiz())
|
||||
line_list.append(self)
|
||||
line_list.extend(self.all_next_horiz())
|
||||
return line_list
|
||||
|
||||
def same_column(self):
|
||||
line_list = []
|
||||
line_list.extend(self.all_prev_vert())
|
||||
line_list.append(self)
|
||||
line_list.extend(self.all_next_vert())
|
||||
return line_list
|
||||
|
|
Loading…
Reference in a new issue