From 6fee91e0c4dd0676f38a95f3897cb71138c58cb3 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 2 Jan 2015 20:45:51 +0100 Subject: [PATCH] starting work to implement that all lines (and columns) must be different --- sources/grid.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/sources/grid.py b/sources/grid.py index 729dd8d..e2447d9 100644 --- a/sources/grid.py +++ b/sources/grid.py @@ -18,6 +18,13 @@ __author__ = 'gaugendre' import sys +def string_from_list(line): + string = "" + for square in line: + string += square.state + return string + + class Grid: def __init__(self, size, array=None): _squares = [] @@ -58,7 +65,16 @@ class Grid: representation += "\n" return representation - def solve_three(self): + def squares_on_line(self, line_number): + return self.squares[line_number] + + def squares_on_column(self, col_number): + col = [] + for line in self.squares: + col.append(line[col_number]) + return col + + def solve_three_in_a_row(self): for square in self.square_list: if square.is_empty(): v_prev = square.prev_vert() @@ -92,8 +108,9 @@ class Grid: def solve(self): for i in range(0, 2, 1): - self.solve_three() + self.solve_three_in_a_row() self.solve_same_number() + self.solve_different_lines_or_columns() def solve_same_number(self): for square in self.square_list: @@ -127,6 +144,11 @@ class Grid: elif count_blue == self.size / 2: square.state = 'R' + def solve_different_lines_or_columns(self): + pass + # for square in self.square_list: + # line = string_from_list(square.same_line()) + class Square: """ @@ -255,6 +277,7 @@ class Square: """ line_list = [] line_list.extend(self.all_prev_horiz()) + line_list.append(self) line_list.extend(self.all_next_horiz()) return line_list @@ -266,5 +289,6 @@ class Square: """ line_list = [] line_list.extend(self.all_prev_vert()) + line_list.append(self) line_list.extend(self.all_next_vert()) return line_list