def load_sgf_file(self, file, fast=False, rewind=False): try: move_tree = KaTrainSGF.parse_file(file) except ParseError as e: self.log(i18n._("Failed to load SGF").format(error=e), OUTPUT_ERROR) return self._do_new_game(move_tree=move_tree, analyze_fast=fast) if not rewind: self.game.redo(999)
def test_foxwq(): for sgf in ["data/fox sgf error.sgf", "data/fox sgf works.sgf"]: file = os.path.join(os.path.dirname(__file__), sgf) move_tree = KaTrainSGF.parse_file(file) katrain = KaTrainBase(force_package_config=True, debug_level=0) game = Game(katrain, MagicMock(), move_tree) assert [] == move_tree.placements assert [] == game.root.placements while game.current_node.children: assert 1 == len(game.current_node.children) game.redo(1)
def load_sgf_file(self, file, fast=False, rewind=True): if self.contributing: return try: file = os.path.abspath(file) move_tree = KaTrainSGF.parse_file(file) except (ParseError, FileNotFoundError) as e: self.log(i18n._("Failed to load SGF").format(error=e), OUTPUT_ERROR) return self._do_new_game(move_tree=move_tree, analyze_fast=fast, sgf_filename=file) if not rewind: self.game.redo(999)
def readfile(*args): files = popup_contents.filesel.selection self.fileselect_popup.dismiss() try: move_tree = KaTrainSGF.parse_file(files[0]) except ParseError as e: self.log( i18n._("Failed to load SGF").format(error=e), OUTPUT_ERROR) return self._do_new_game(move_tree=move_tree, analyze_fast=popup_contents.fast.active) if not popup_contents.rewind.active: self.game.redo(999)
def readfile(*_args): files = popup_contents.filesel.selection self.fileselect_popup.dismiss() path, file = os.path.split(files[0]) settings_path = self.config("general/sgf_load") if path != settings_path: self.log(f"Updating sgf load path default to {path}", OUTPUT_INFO) self._config["general"]["sgf_load"] = path self.save_config("general") try: move_tree = KaTrainSGF.parse_file(files[0]) except ParseError as e: self.log( i18n._("Failed to load SGF").format(error=e), OUTPUT_ERROR) return self._do_new_game(move_tree=move_tree, analyze_fast=popup_contents.fast.active) if not popup_contents.rewind.active: self.game.redo(999)
from rank_utils import rank_game def format_rank(rank): if rank <= 0: return f"{1-rank:5.1f}d" else: return f"{rank:5.1f}k" if __name__ == "__main__": kt = KaTrainBase(force_package_config=True) e_config = kt.config("engine") e_config["max_visits"] = e_config[ "fast_visits"] = 1 # since it's just policy anyway engine = KataGoEngine(kt, e_config) for filename in glob.glob("sgf_ogs/*.sgf"): game = Game(kt, engine, move_tree=KaTrainSGF.parse_file(filename)) size = game.board_size len_segment = 80 ranks = rank_game(game, len_segment) if not ranks: continue print("* File name: {0:s}".format(filename)) for start, end, rank in ranks: print( f"\tMove quality for moves {start:3d} to {end:3d}\tB: {format_rank(rank['B'])}\tW: {format_rank(rank['W'])}" )