Exemplo n.º 1
0
    def test_handicap_load(self):
        input_sgf = (
            "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]RU[Chinese]SZ[19]HA[2]KM[0.50]TM[600]OT[5x30 byo-yomi]PW[kneh]PB[ayabot003]WR[4k]BR[6k]DT[2021-01-04]PC[The KGS Go Server at http://www.gokgs.com/]C[ayabot003 [6k\\"
            "]: GTP Engine for ayabot003 (black): Aya version 7.85x]RE[W+Resign];B[pd]BL[599.647];B[dp]BL[599.477];W[pp]WL[597.432];B[cd]BL[598.896];W[ed]WL[595.78];B[ec]BL[598.558])"
        )
        root = KaTrainSGF.parse_sgf(input_sgf)
        game = Game(MockKaTrain(force_package_config=True), MockEngine(), move_tree=root)
        assert 0 == len(game.root.placements)

        root2 = KaTrainSGF.parse_sgf("(;GM[1]FF[4]SZ[19]HA[2];)")
        game2 = Game(MockKaTrain(force_package_config=True), MockEngine(), move_tree=root2)
        assert 2 == len(game2.root.placements)
Exemplo n.º 2
0
    def load_sgf_from_clipboard(self):
        clipboard = Clipboard.paste()
        if not clipboard:
            self.controls.set_status("Ctrl-V pressed but clipboard is empty.",
                                     STATUS_INFO)
            return

        url_match = re.match(r"(?P<url>https?://[^\s]+)", clipboard)
        if url_match:
            self.log("Recognized url: " + url_match.group(), OUTPUT_INFO)
            http = urllib3.PoolManager()
            response = http.request("GET", url_match.group())
            clipboard = response.data.decode("utf-8")

        try:
            move_tree = KaTrainSGF.parse_sgf(clipboard)
        except Exception as exc:
            self.controls.set_status(
                i18n._("Failed to import from clipboard").format(
                    error=exc, contents=clipboard[:50]), STATUS_INFO)
            return
        move_tree.nodes_in_tree[-1].analyze(
            self.engine,
            analyze_fast=False)  # speed up result for looking at end of game
        self._do_new_game(move_tree=move_tree, analyze_fast=True)
        self("redo", 9999)
        self.log("Imported game from clipboard.", OUTPUT_INFO)
Exemplo n.º 3
0
 def load_sgf_from_clipboard(self):
     clipboard = Clipboard.paste()
     if not clipboard:
         self.controls.set_status(f"Ctrl-V pressed but clipboard is empty.", STATUS_INFO)
         return
     try:
         move_tree = KaTrainSGF.parse_sgf(clipboard)
     except Exception as exc:
         self.controls.set_status(
             i18n._("Failed to import from clipboard").format(error=exc, contents=clipboard[:50]), STATUS_INFO
         )
         return
     move_tree.nodes_in_tree[-1].analyze(
         self.engine, analyze_fast=False
     )  # speed up result for looking at end of game
     self._do_new_game(move_tree=move_tree, analyze_fast=True)
     self("redo", 999)
     self.log("Imported game from clipboard.", OUTPUT_INFO)
Exemplo n.º 4
0
    }
    return results


katrain = KaTrainBase(force_package_config=True, debug_level=0)
combined_settings = {**katrain.config("engine"), **settings}
engine = KataGoEngine(katrain, {**katrain.config("engine"), **settings})
thresholds = katrain.config("trainer/eval_thresholds")

games = []
n = 0
for sgf in os.listdir("sgftest/"):
    if sgf.lower().endswith("sgf"):
        print(sgf)
        with open(os.path.join("sgftest", sgf)) as f:
            move_tree = KaTrainSGF.parse_sgf(f.read())
        games.append(
            Game(katrain, engine, move_tree=move_tree, analyze_fast=False))
    n += 1
    if n >= 30000:  # small test=3
        break

while not engine.is_idle():
    print(
        f"waiting for engine to finish...{engine.queries_remaining()} queries left"
    )
    time.sleep(0.5)
engine.shutdown(finish=None)

reports = []
for game in games: