Replaced set_naively with set(normalize=False).
[pseudoku.git] / pseudoku / grid / __init__.py
index 2f77aaf..94d0833 100644 (file)
@@ -63,18 +63,14 @@ class Cell(object):
         self._values = range(self._grid.size)
         self._normalized = False
 
-    def set_naively(self, value):
-        """Sets the value of this cell, WITHOUT eliminating the value from
-        every other cell in its row/column/box.
+    def set(self, value, normalize=True):
+        """Sets the value of this cell.  If `normalize` is True or omitted, the
+        grid will be updated accordingly.
         """
-
         self._values = [value]
-
-    def set(self, value):
-        """Sets the value of this cell and adjusts the grid accordingly."""
-        self.set_naively(value)
-        self._normalized = False
-        self.normalize()
+        if normalize:
+            self._normalized = False
+            self.normalize()
 
 
 
@@ -117,14 +113,6 @@ class Cell(object):
             self.normalize()
 
 
-    def __str__(self):
-        """Stringification for pretty-printing."""
-        if self.value != None:
-            return symbols[self.value]
-
-        return '.'
-
-
 class Grid(object):
     """Represents a Sudoku grid."""
 
@@ -222,7 +210,7 @@ class Grid(object):
                 value = rows[row][col]
                 if not value:
                     continue
-                self.cell(row, col).set_naively(value - 1)
+                self.cell(row, col).set(value - 1, normalize=False)
 
         return self
 
@@ -261,7 +249,7 @@ class Grid(object):
                 ch = grid[ self._cellidx(row, col) ]
                 if ch == '0':
                     continue
-                self.cell(row, col).set_naively(symbols.index(ch))
+                self.cell(row, col).set(symbols.index(ch), normalize=False)
 
         return self
 
@@ -302,31 +290,3 @@ class Grid(object):
         """Normalizes every cell in the grid."""
         for cell in self._cells:
             cell.normalize()
-
-
-    def __str__(self):
-        """Pretty-printing."""
-        divider = '+'
-        for box in xrange(self._box_height):
-            for col in xrange(self._box_width):
-                divider += '-'
-            divider += '+'
-
-        res = ''
-        for row in xrange(self._size):
-            if row % self._box_height == 0:
-                res += divider
-                res += "\n"
-
-            for col in xrange(self._size):
-                if col % self._box_width == 0:
-                    res += '|'
-                res += str(self.cell(row, col))
-
-            res += '|'
-            res += "\n"
-
-        res += divider
-        res += "\n"
-
-        return res