output module
authorTomas Musil <tomik.musil@gmail.com>
Thu, 17 Oct 2013 21:39:09 +0000 (23:39 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Thu, 17 Oct 2013 21:39:09 +0000 (23:39 +0200)
TODO [new file with mode: 0644]
imago_pack/imago.py
imago_pack/intrsc.py
imago_pack/output.py [new file with mode: 0644]
imago_pack/sgf.py [deleted file]

diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..f74b253
--- /dev/null
+++ b/TODO
@@ -0,0 +1,5 @@
+documentation
+faster (and more realiable) grid search
+stone finding
+better user interface
+faster image processing
index c0e6202..c31db64 100755 (executable)
@@ -102,8 +102,7 @@ def main():
     board = intrsc.board(image, lines, show_all, do_something)
 
     #simple ASCII output:
-    for line in board:
-        print ' '.join(line)
+    print board
     
     if len(args.files) > 1:
         for f in args.files[1:]:
index 445c447..d26bea4 100644 (file)
@@ -6,6 +6,7 @@ from operator import itemgetter
 import ImageDraw
 
 import k_means
+import output
 
 def dst(line):
     """Return normalized line."""
@@ -76,15 +77,16 @@ def board(image, lines, show_all, do_something):
     
     board_r = []
 
+    #TODO 19 should be a size parameter
     try:
         for i in xrange(19):
-            board_r.append([])
             for _ in xrange(19):
-                board_r[i].append(board_rg.next())
+                board_r.append(board_rg.next())
     except StopIteration:
         pass
+    
 
-    return board_r
+    return output.Board(19, board_r)
 
 def mean_luma(cluster):
     return sum(c[0][0] for c in cluster) / float(len(cluster))
diff --git a/imago_pack/output.py b/imago_pack/output.py
new file mode 100644 (file)
index 0000000..82d1e4f
--- /dev/null
@@ -0,0 +1,55 @@
+"""Imago output module."""
+
+import sys
+
+COORDS = 'abcdefghijklmnopqrs'
+
+def txt2sgf(board):
+    """Converts textual represantation to SGF (set position)."""
+
+    board = sys.stdin.read().split('\n')
+    board = [line.split() for line in board]
+
+    black = []
+    white = []
+
+    for i in range(19):
+        for j in range(19):
+            if board[i][j] == 'B':
+                black.append((i, j))
+            elif board[i][j] == 'W':
+                white.append((i, j))
+
+    sgf = ""
+    #TODO version numbering
+    sgf += "(;FF[4]GM[1]SZ[19]AP[Imago:0.1.0]"
+    sgf += "AB" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in black) 
+    sgf += "AW" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in white)
+    sgf += ")"
+
+class Board:
+    def __init__(self, size, stones):
+        self.stones = stones        
+        self.size = size
+
+    def __str__(self):
+        lines = []
+        k = 0
+        for i in range(self.size):
+            line = []
+            for j in range(self.size):
+                line.append(self.stones[k])
+                k += 1
+            lines.append(" ".join(line))
+        return ("\n".join(lines))
+
+
+
+class Game:
+    def __init__(self, size):
+        self.board =  (size * size) * "."
+        self.moves = []
+
+    def add(self, board):
+        self
+
diff --git a/imago_pack/sgf.py b/imago_pack/sgf.py
deleted file mode 100644 (file)
index 3999f77..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-import sys
-
-def main():
-    coords = 'abcdefghijklmnopqrs'
-
-    board = sys.stdin.read().split('\n')
-    board = [line.split() for line in board]
-
-    black = []
-    white = []
-
-    for i in range(19):
-        for j in range(19):
-            if board[i][j] == 'B':
-                black.append((i, j))
-            elif board[i][j] == 'W':
-                white.append((i, j))
-
-    #TODO version numbering
-    print "(;FF[4]GM[1]SZ[19]AP[Imago:0.1.0]"
-    print "AB" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in black) 
-    print "AW" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in white)
-    print ")"
-
-if __name__ == '__main__':
-    main()