tsumego solver 5000 is go
This commit is contained in:
1 parent
da42fc4e0f
commit
0ade2524ce
27 files changed
+252
-83
No files matched your search
+9
-10
@@ -6,7 +6,7 @@ import subprocess
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
from typing import Callable, Dict, Optional
|
||||
from typing import Callable, Dict, Optional, List
|
||||
|
||||
from kivy.utils import platform
|
||||
|
||||
@@ -112,6 +112,7 @@ class KataGoEngine:
|
||||
self.terminate_query(query_id)
|
||||
self.queries = {}
|
||||
|
||||
|
||||
def restart(self):
|
||||
self.queries = {}
|
||||
self.shutdown(finish=False)
|
||||
@@ -249,7 +250,7 @@ class KataGoEngine:
|
||||
analyze_fast: bool = False,
|
||||
time_limit=True,
|
||||
find_alternatives: bool = False,
|
||||
find_local: bool = False,
|
||||
region_of_interest: Optional[List] = None,
|
||||
priority: int = 0,
|
||||
ownership: Optional[bool] = None,
|
||||
next_move: Optional[GameNode] = None,
|
||||
@@ -278,22 +279,20 @@ class KataGoEngine:
|
||||
"untilDepth": 1,
|
||||
}
|
||||
]
|
||||
elif find_local:
|
||||
distance = 5
|
||||
last_move = analysis_node.move
|
||||
if last_move is None or last_move.is_pass:
|
||||
return
|
||||
elif region_of_interest:
|
||||
xmin, xmax, ymin, ymax = region_of_interest
|
||||
avoid = [
|
||||
{
|
||||
"moves": [
|
||||
Move((x, y)).gtp()
|
||||
for x in range(0, size_x)
|
||||
for y in range(0, size_y)
|
||||
if max(abs(x - last_move.coords[0]), abs(y - last_move.coords[1])) > distance
|
||||
if x < xmin or x > xmax or y < ymin or y > ymax
|
||||
],
|
||||
"player": analysis_node.next_player,
|
||||
"untilDepth": 1,
|
||||
"player": player,
|
||||
"untilDepth": 10000,
|
||||
}
|
||||
for player in "BW"
|
||||
]
|
||||
else:
|
||||
avoid = []
|
||||
|
||||
+19
-6
@@ -62,6 +62,8 @@ class Game:
|
||||
self.insert_mode = False
|
||||
self.insert_after = None
|
||||
|
||||
self.region_of_interest = None
|
||||
|
||||
if move_tree:
|
||||
self.root = move_tree
|
||||
self.komi = self.root.komi
|
||||
@@ -233,7 +235,11 @@ class Game:
|
||||
played_node = self.current_node.play(move)
|
||||
self.current_node = played_node
|
||||
if analyze:
|
||||
played_node.analyze(self.engines[played_node.next_player])
|
||||
if self.region_of_interest:
|
||||
played_node.analyze(self.engines[played_node.next_player],analyze_fast=True)
|
||||
played_node.analyze(self.engines[played_node.next_player],region_of_interest=self.region_of_interest)
|
||||
else:
|
||||
played_node.analyze(self.engines[played_node.next_player])
|
||||
return played_node
|
||||
|
||||
def set_current_node(self, node):
|
||||
@@ -410,6 +416,17 @@ class Game:
|
||||
f.write(sgf)
|
||||
return i18n._("sgf written").format(file_name=filename)
|
||||
|
||||
def set_region_of_interest(self,region_of_interest):
|
||||
x1, x2, y1, y2 =region_of_interest
|
||||
xmin, xmax = min(x1, x2), max(x1, x2)
|
||||
ymin, ymax = min(y1, y2), max(y1, y2)
|
||||
if not (xmin==xmax and ymin==ymax):
|
||||
self.region_of_interest = [xmin,xmax,ymin,ymax]
|
||||
else:
|
||||
self.region_of_interest = None
|
||||
self.katrain.controls.set_status("",OUTPUT_INFO)
|
||||
|
||||
|
||||
def analyze_extra(self, mode, **kwargs):
|
||||
stones = {s.coords for s in self.stones}
|
||||
cn = self.current_node
|
||||
@@ -426,7 +443,7 @@ class Game:
|
||||
visits = cn.analysis_visits_requested + engine.config["max_visits"]
|
||||
self.katrain.controls.set_status(i18n._("extra analysis").format(visits=visits), STATUS_ANALYSIS)
|
||||
self.katrain.controls.set_status(i18n._("extra analysis").format(visits=visits), STATUS_ANALYSIS)
|
||||
cn.analyze(engine, visits=visits, priority=-1_000, time_limit=False)
|
||||
cn.analyze(engine, visits=visits, priority=-1_000, region_of_interest=self.region_of_interest, time_limit=False)
|
||||
return
|
||||
if mode == "game":
|
||||
nodes = self.root.nodes_in_tree
|
||||
@@ -467,10 +484,6 @@ class Game:
|
||||
visits = engine.config["fast_visits"]
|
||||
self.katrain.controls.set_status(i18n._("sweep analysis").format(visits=visits), STATUS_ANALYSIS)
|
||||
priority = -1_000_000_000
|
||||
elif mode == "local": # also do a quick update on current candidates so it doesn't look too weird
|
||||
self.katrain.controls.set_status(i18n._("local analysis"), STATUS_ANALYSIS)
|
||||
cn.analyze(engine, priority=-500, time_limit=False, find_local="local")
|
||||
return
|
||||
elif mode in ["equalize", "alternative", "local"]:
|
||||
if not cn.analysis_complete and mode != "local":
|
||||
self.katrain.controls.set_status(i18n._("wait-before-equalize"), STATUS_INFO, self.current_node)
|
||||
|
||||
@@ -145,13 +145,14 @@ class GameNode(SGFNode):
|
||||
refine_move=None,
|
||||
analyze_fast=False,
|
||||
find_alternatives=False,
|
||||
find_local=False,
|
||||
region_of_interest = None,
|
||||
report_every=0.25,
|
||||
):
|
||||
additional_moves = bool(find_alternatives or region_of_interest)
|
||||
engine.request_analysis(
|
||||
self,
|
||||
callback=lambda result, partial_result: self.set_analysis(
|
||||
result, refine_move, find_alternatives or find_local, partial_result
|
||||
result, refine_move, additional_moves, partial_result
|
||||
),
|
||||
priority=priority,
|
||||
visits=visits,
|
||||
@@ -159,7 +160,7 @@ class GameNode(SGFNode):
|
||||
time_limit=time_limit,
|
||||
next_move=refine_move,
|
||||
find_alternatives=find_alternatives,
|
||||
find_local=find_local,
|
||||
region_of_interest=region_of_interest,
|
||||
report_every=report_every,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user