def advance(C, color, mv): foundChildIdx = None clr = 'W' if color =='white' else 'B' for j in range(len(C.children)): if clr in C.children[j].keys() and C.children[j][clr].data[0] == mv: foundChildIdx = j if foundChildIdx is not None: C.next(foundChildIdx) else: nnode = sgflib.Node() nnode.addProperty(nnode.makeProperty(clr,[mv])) C.appendNode(nnode) C.next(len(C.children)-1)
def advance(cursor, color, mv): found_child_idx = None clr = 'W' if color == 'white' else 'B' for j in range(len(cursor.children)): if clr in cursor.children[j].keys( ) and cursor.children[j][clr].data[0] == mv: found_child_idx = j if found_child_idx is not None: cursor.next(found_child_idx) else: nnode = sgflib.Node() nnode.add_property(sgflib.Property(clr, [mv])) cursor.append_node(nnode) cursor.next(len(cursor.children) - 1)
def insert_sequence(cursor, seq, data=None, callback=None): if data is None: data = [0] * len(seq) for (color, mv), elem in zip(seq, data): nnode = sgflib.Node() assert color in ['white', 'black'] color = 'W' if color == 'white' else 'B' nnode.addProperty(nnode.makeProperty(color, [mv])) cursor.appendNode(nnode) cursor.next(len(cursor.children) - 1) if callback is not None: if type(elem) in [list, tuple]: elem = list(elem) else: elem = [elem] callback(*tuple([cursor] + elem)) for i in xrange(len(seq)): cursor.previous()