def new_board( self, size ): # assumes there already is a board; will crash if this is not so unlink_target = self.node.get_root_node() self.node = gofish.new_tree(size) unlink_target.unlink_recursive( ) # recursively destroy the old tree's circular references so the GC can work self.node_changed()
def __init__(self, owner, filename, *args, **kwargs): tkinter.Canvas.__init__(self, owner, *args, **kwargs) self.owner = owner self.node = gofish.new_tree(19) # Do this now in case the load fails self.directory = os.path.dirname(os.path.realpath(sys.argv[0])) self.show_siblings = tkinter.IntVar(value=0) self.show_children = tkinter.IntVar(value=0) self.click_mode = tkinter.IntVar(value=NORMAL) if filename is not None: self.open_file( filename ) # Can fail, leaving us with the tree we created above self.node_changed()
def handle_key_DELETE(self): if len(self.node.children) > 0: ok = tkinter.messagebox.askokcancel( "Delete?", "Delete this node and all of its children?") else: ok = True if ok: unlink_target = self.node if self.node.parent: parent = self.node.parent parent.children.remove(self.node) self.node = parent self.node.fix_main_line_status_recursive() else: self.node = gofish.new_tree(self.node.board.boardsize) self.node_changed() unlink_target.unlink_recursive( ) # the old node gets its circular references recursively removed to allow GC to work
def reset(self, size): if self.awaiting_move: return self.node = gofish.new_tree(size) for cmd in [ "boardsize {}".format(self.node.board.boardsize), "clear_board", "komi 0" ]: send_command(cmd) get_reply() if self.human_colour == BLACK: statusbar.config( text="Your move ({})".format(colour_lookup[self.human_colour])) else: command = "genmove {}".format(colour_lookup[self.engine_colour]) engine_in_queue.put(command) self.need_to_wait() self.draw_node()
def handicap(self, h): if self.awaiting_move: return self.node = gofish.new_tree(self.node.board.boardsize) for cmd in [ "boardsize {}".format(self.node.board.boardsize), "clear_board", "komi 0" ]: send_command(cmd) get_reply() send_command("fixed_handicap {}".format(h)) response = get_reply() if response[0] == "?": self.reset(self.node.board.boardsize) return self.node.set_value("HA", h) english_points_list = response[1:].strip().split() for p in english_points_list: x, y = gofish.point_from_english_string(p, self.node.board.boardsize) self.node.add_stone(BLACK, x, y) if self.human_colour == WHITE: # The reverse of normal; white goes first statusbar.config( text="Your move ({})".format(colour_lookup[self.human_colour])) else: command = "genmove {}".format(colour_lookup[self.engine_colour]) engine_in_queue.put(command) self.need_to_wait() self.draw_node()