Added a Diagonal constraint.
authorEevee <eevee@nyarumaa.(none)>
Wed, 7 Jan 2009 13:40:03 +0000 (08:40 -0500)
committerEevee <eevee@nyarumaa.(none)>
Wed, 7 Jan 2009 13:40:03 +0000 (08:40 -0500)
Also fixed a bug when rendering: value 1 would be shown as a space.

pseudoku/__init__.py
pseudoku/grid/cellgroup.py
pseudoku/render/__init__.py
pseudoku/render/text.py

index 853904b..2fe15f3 100644 (file)
@@ -1,4 +1,5 @@
 from grid import Grid
 from grid import Grid
+from grid.cellgroup import Diagonal
 import render.text
 
 def main():
 import render.text
 
 def main():
@@ -14,6 +15,9 @@ def main():
         1...6...9
     """)
 
         1...6...9
     """)
 
+    grid.add_constraint(Diagonal(grid, direction='down', offset=0))
+    grid.add_constraint(Diagonal(grid, direction='up', offset=0))
+
     r = render.text.AsciiArtGridRenderer()
     print r.render_grid(grid)
 
     r = render.text.AsciiArtGridRenderer()
     print r.render_grid(grid)
 
index 374bd20..841a490 100644 (file)
@@ -84,3 +84,28 @@ class Column(CellConstraint):
         self._cells = []
         for row in xrange(self.grid._size):
             self._cells.append(ref(self.grid.cell(row, self._pos)))
         self._cells = []
         for row in xrange(self.grid._size):
             self._cells.append(ref(self.grid.cell(row, self._pos)))
+
+class Diagonal(CellConstraint):
+    def __init__(self, grid, direction='down', offset=0):
+        self._grid = ref(grid)
+        self._direction = direction
+        self._offset = offset
+
+        if direction == 'down':
+            coords = {'row': 0, 'column': 0}
+            increment = 1
+        elif direction == 'up':
+            coords = {'row': 0, 'column': grid.size - 1}
+            increment = -1
+        else:
+            raise Exception # XXX
+
+        # XXX
+        if offset != 0:
+            raise NotImplementedError
+
+        self._cells = []
+        for i in xrange(self.grid.size):
+            self._cells.append(ref(self.grid.cell(coords['row'], coords['column'])))
+            coords['row'] += 1
+            coords['column'] += increment
index a3593df..4b6bd65 100644 (file)
@@ -83,7 +83,7 @@ class GridRenderer(object):
 
     def inside_cell(self, cell):
         """Content used to represent the actual cell value."""
 
     def inside_cell(self, cell):
         """Content used to represent the actual cell value."""
-        if cell.value:
+        if cell.solved:
             return symbols[cell.value]
         else:
             return '.'
             return symbols[cell.value]
         else:
             return '.'
index 3a49134..2c8a6fd 100644 (file)
@@ -31,7 +31,7 @@ class AsciiArtGridRenderer(SquareGridRenderer):
         return '|\n'
 
     def inside_cell(self, cell):
         return '|\n'
 
     def inside_cell(self, cell):
-        if cell.value:
+        if cell.solved:
             return symbols[cell.value]
         else:
             return ' '
             return symbols[cell.value]
         else:
             return ' '