prioritized analysis
This commit is contained in:
1 parent
0a331cf294
commit
8bcd80e569
1 file changed
+12
-6
+12
-6
@@ -48,6 +48,7 @@ class EngineControls(GridLayout):
|
||||
self.outstanding_analysis_queries = [] # allows faster interaction while kata is starting
|
||||
self.kata = None
|
||||
self.query_time = {}
|
||||
self.game_counter = 0
|
||||
|
||||
def show_error(self, msg):
|
||||
print(f"ERROR: {msg}")
|
||||
@@ -92,7 +93,7 @@ class EngineControls(GridLayout):
|
||||
raise
|
||||
msg, *args = self.message_queue.get()
|
||||
|
||||
def play(self, move, faster=False):
|
||||
def play(self, move, faster=False, analysis_priority=None):
|
||||
try:
|
||||
mr = self.board.play(move)
|
||||
except IllegalMoveException as e:
|
||||
@@ -100,7 +101,7 @@ class EngineControls(GridLayout):
|
||||
return
|
||||
self.update_evaluation()
|
||||
if not mr.analysis_ready: # replayed old move
|
||||
self._request_analysis(mr, faster=faster)
|
||||
self._request_analysis(mr, faster=faster, priority=self.game_counter if analysis_priority is None else analysis_priority)
|
||||
return mr
|
||||
|
||||
def show_evaluation_stats(self, move):
|
||||
@@ -211,10 +212,11 @@ class EngineControls(GridLayout):
|
||||
self.update_evaluation()
|
||||
|
||||
def _do_init(self, board_size, komi=None):
|
||||
self.game_counter += 1 # prioritize newer games
|
||||
self.board_size = board_size
|
||||
self.komi = float(komi or Config.get("board").get(f"komi_{board_size}", 6.5))
|
||||
self.board = Board(board_size)
|
||||
self._request_analysis(self.board.root)
|
||||
self._request_analysis(self.board.root, priority=self.game_counter)
|
||||
self.redraw(include_board=True)
|
||||
self.ready = True
|
||||
if self.ai_lock.active:
|
||||
@@ -263,16 +265,18 @@ class EngineControls(GridLayout):
|
||||
if handicap and not "AB" in sgfprops:
|
||||
self.board.place_handicap_stones(handicap)
|
||||
|
||||
analysis_priority = self.game_counter - 1_000_000_000
|
||||
|
||||
placements = [Move(player=pl, sgfcoords=(mv, self.board_size)) for pl, player in enumerate(Move.PLAYERS) for mv in sgfprops.get("A" + player, [])]
|
||||
for placement in placements: # free handicaps
|
||||
self.board.play(placement) # bypass analysis
|
||||
|
||||
if handicap or placements:
|
||||
self._request_analysis(self.board.current_move) # ensure next move analysis works
|
||||
self._request_analysis(self.board.current_move, priority=analysis_priority) # ensure next move analysis works
|
||||
|
||||
moves = [Move(player=Move.PLAYERS.index(p.upper()), sgfcoords=(mv, self.board_size)) for p, mv in sgfmoves]
|
||||
for move in moves:
|
||||
self.play(move, faster=faster and move != moves[-1])
|
||||
self.play(move, faster=faster and move != moves[-1], analysis_priority=analysis_priority)
|
||||
if rewind:
|
||||
self.board.rewind()
|
||||
|
||||
@@ -300,13 +304,14 @@ class EngineControls(GridLayout):
|
||||
|
||||
def _send_analysis_query(self, query):
|
||||
self.query_time[query["id"]] = time.time()
|
||||
print(query)
|
||||
if self.kata:
|
||||
self.kata.stdin.write((json.dumps(query) + "\n").encode())
|
||||
self.kata.stdin.flush()
|
||||
else: # early on / root / etc
|
||||
self.outstanding_analysis_queries.append(copy.copy(query))
|
||||
|
||||
def _request_analysis(self, move, faster=False):
|
||||
def _request_analysis(self, move, faster=False, priority=0):
|
||||
faster_fac = 5 if faster else 1
|
||||
move_id = move.id
|
||||
moves = self.board.moves
|
||||
@@ -321,6 +326,7 @@ class EngineControls(GridLayout):
|
||||
"analyzeTurns": [len(moves)],
|
||||
"includeOwnership": True,
|
||||
"maxVisits": self.visits[fast][1] // faster_fac,
|
||||
"priority": priority,
|
||||
}
|
||||
if self.debug:
|
||||
print(f"sending query for move {move_id}: {str(query)[:80]}")
|
||||
|
||||
Reference in new issue
Block a user