1 """Imago output module."""
6 COORDS = 'abcdefghijklmnopqrs'
9 def __init__(self, size, stones):
16 for i in range(self.size):
18 for j in range(self.size):
19 line.append(self.stones[k])
21 lines.append(" ".join(line))
23 return ("\n".join(lines))
25 def asSGFsetPos(self):
26 """Returns SGF (set position) representation of the position."""
28 #TODO version numbering
29 sgf = "(;FF[4]GM[1]SZ[" + str(self.size) + "]AP[Imago:0.1.0]\n"
38 for i in range(self.size):
39 for j in range(self.size):
40 stone = self.stones[i * self.size + j]
42 black.append(Move('B', i, j))
44 white.append(Move('W', i, j))
47 sgf += "AB" + ''.join('[' + m.sgf_coords() + ']'
48 for m in black) + "\n"
50 sgf += "AW" + ''.join('[' + m.sgf_coords() + ']'
51 for m in white) + "\n"
55 self.stones[(m.y * self.size) + m.x] = m.color
57 def getMoveCandidates(self, board):
59 for i in range(self.size):
60 for j in range(self.size):
61 if (self.stones[self.size * i + j] == "."):
62 if (board.stones[self.size * i + j] == "W"):
63 candidates.append(Move("W", i, j))
64 elif (board.stones[self.size * i + j] == "B"):
65 candidates.append(Move("B", i, j))
69 def __init__(self, color, y, x, comment=None):
73 self.comment = comment
76 return COORDS[self.x] + COORDS[self.y]
79 def __init__(self, size, board=None, debug=True):
80 self.init_board = board or Board(size, (size * size) * ".")
81 self.board = copy.deepcopy(self.init_board)
85 self.debug_comment = ""
87 def addMove(self, board):
88 candidates = self.board.getMoveCandidates(board)
91 comment += "Candidates: " + str(len(candidates))
94 self.debug_comment += "No candidates."
98 move.comment = comment
99 self.moves.append(move)
100 self.board.addMove(move)
103 sgf = "(;FF[4]GM[1]SZ[" + str(self.size) + "]AP[Imago:0.1.0]\n"
104 sgf += self.init_board.SGFpos()
107 sgf += ";" + m.color + "[" + m.sgf_coords() + "]"
109 sgf += "C[" + m.comment + "]"