help="save images instead of displaying them")
parser.add_argument('-c', '--cache', dest='l_cache', action='store_true',
help="use cached lines")
+ parser.add_argument('-S', '--sgf', dest='sgf_output', action='store_true',
+ help="output in SGF")
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help="report progress")
return parser
board = intrsc.board(image, lines, show_all, do_something)
- #simple ASCII output:
- print board
+ if len(args.files) == 1:
+
+ if args.sgf_output:
+ print board.asSGFsetPos()
+ else:
+ print board
- if len(args.files) > 1:
+ else:
for f in args.files[1:]:
try:
image = Image.open(f)
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
lines.append(" ".join(line))
return ("\n".join(lines))
+ def asSGFsetPos(self):
+ """Returns SGF (set position) representation of the position."""
+
+ black = []
+ white = []
+ for i in range(self.size):
+ for j in range(self.size):
+ stone = self.stones[i * self.size + j]
+ if stone == 'B':
+ black.append((i, j))
+ elif stone == 'W':
+ white.append((i, j))
+
+ sgf = ""
+ #TODO version numbering
+ sgf += "(;FF[4]GM[1]SZ[" + str(self.size) + "]AP[Imago:0.1.0]\n"
+ sgf += "AB" + ''.join('[' + COORDS[j] + COORDS[i] + ']'
+ for (i, j) in black) + "\n"
+ sgf += "AW" + ''.join('[' + COORDS[j] + COORDS[i] + ']'
+ for (i, j) in white) + "\n"
+ sgf += ")"
+ return sgf
class Game:
def __init__(self, size):