class EndgameAdvisor(Advisor, Thread): def __init__ (self, store, tv, boardview): Thread.__init__(self, name=fident(self.run)) self.daemon = True # FIXME 'Advisor.name = ...' in Advisor.__init__ overwrites Thread.name Advisor.__init__(self, store, _("Endgame Table"), ENDGAME) self.egtb = EndgameTable() self.tv = tv self.boardview = boardview self.tooltip = _("The endgame table will show exact analysis when there are few pieces on the board.") # TODO: Show a message if tablebases for the position exist but are neither installed nor allowed. self.egtb.connect("scored", self.on_scored) self.queue = Queue() self.start() class StopNow (Exception): pass def run (self): while True: v = self.queue.get() if v == self.StopNow: break elif v == self.board.board: self.egtb.scoreAllMoves(v) self.queue.task_done() def shown_changed (self, boardview, shown): m = boardview.model if m.isPlayingICSGame(): return self.parent = self.empty_parent() self.board = m.getBoardAtPly(shown, boardview.shownVariationIdx) self.queue.put(self.board.board) def gamewidget_closed (self, gamewidget): try: self.queue.put_nowait(self.StopNow) except Full: log.warning("EndgameAdvisor.gamewidget_closed: Queue.Full") @idle_add def on_scored(self, w, ret): m = self.boardview.model if m.isPlayingICSGame(): return board, endings = ret if board != self.board.board: return for move, result, depth in endings: if result == DRAW: result = (_("Draw"), 1, 0.5) details = "" elif (result == WHITEWON) ^ (self.board.color == WHITE): result = (_("Loss"), 1, 0.0) details = _("Mate in %d") % depth else: result = (_("Win"), 1, 1.0) details = _("Mate in %d") % depth self.store.append(self.parent, [(self.board, move, None), result, 0, False, details, False, False]) self.tv.expand_row(Gtk.TreePath(self.path), False)
class EndgameAdvisor(Advisor, Thread): def __init__(self, store, tv, boardview): Thread.__init__(self, name=fident(self.run)) self.daemon = True # FIXME 'Advisor.name = ...' in Advisor.__init__ overwrites Thread.name Advisor.__init__(self, store, _("Endgame Table"), ENDGAME) self.egtb = EndgameTable() # If mate in # was activated by double click let egtb do the rest self.auto_activate = False self.tv = tv self.boardview = boardview self.tooltip = _( "The endgame table will show exact analysis when there are few pieces on the board." ) # TODO: Show a message if tablebases for the position exist but are neither installed nor allowed. self.cid = self.egtb.connect("scored", self.on_scored) self.queue = Queue() self.start() class StopNow(Exception): pass def run(self): while True: v = self.queue.get() if v == self.StopNow: break elif v == self.board.board: self.egtb.scoreAllMoves(v) self.queue.task_done() def shownChanged(self, boardview, shown): m = boardview.model if m is None: return if m.isPlayingICSGame(): return self.parent = self.empty_parent() self.board = m.getBoardAtPly(shown, boardview.shown_variation_idx) self.queue.put(self.board.board) def _del(self): self.egtb.disconnect(self.cid) try: self.queue.put_nowait(self.StopNow) except Full: log.warning("EndgameAdvisor.gamewidget_closed: Queue.Full") @idle_add def on_scored(self, w, ret): m = self.boardview.model if m.isPlayingICSGame(): return board, endings = ret if board != self.board.board: return for move, result, depth in endings: if result == DRAW: result = (_("Draw"), 1, 0.5) details = "" elif (result == WHITEWON) ^ (self.board.color == WHITE): result = (_("Loss"), 1, 0.0) details = _("Mate in %d") % depth else: result = (_("Win"), 1, 1.0) details = _("Mate in %d") % depth self.store.append(self.parent, [(self.board, move, None), result, 0, False, details, False, False]) self.tv.expand_row(Gtk.TreePath(self.path), False) if self.auto_activate: path = None for i, row in enumerate(self.store): if row[4] == self.name: path = Gtk.TreePath.new_from_indices((i, 0)) break if path is not None: self.row_activated(self.tv.get_model().get_iter(path), m, from_gui=False) def row_activated(self, iter, model, from_gui=True): if self.store.get_path(iter) != Gtk.TreePath(self.path): board, move, moves = self.store[iter][0] if from_gui: result = self.store[iter][1] if result is not None and result[2] != 0.5: # double click on mate in # self.auto_activate = True if board.board.next is None and not self.boardview.shownIsMainLine( ): model.add_move2variation(board, move, self.boardview.shown_variation_idx) else: model.add_variation(board, (move, ))
class EndgameAdvisor(Advisor, Thread): def __init__(self, store, tv, boardview): Thread.__init__(self, name=fident(self.run)) self.daemon = True # FIXME 'Advisor.name = ...' in Advisor.__init__ overwrites Thread.name Advisor.__init__(self, store, _("Endgame Table"), ENDGAME) self.egtb = EndgameTable() self.tv = tv self.boardview = boardview self.tooltip = _( "The endgame table will show exact analysis when there are few pieces on the board." ) # TODO: Show a message if tablebases for the position exist but are neither installed nor allowed. self.egtb.connect("scored", self.on_scored) self.queue = Queue() self.start() class StopNow(Exception): pass def run(self): while True: v = self.queue.get() if v == self.StopNow: break elif v == self.board.board: self.egtb.scoreAllMoves(v) self.queue.task_done() def shown_changed(self, boardview, shown): m = boardview.model if m.isPlayingICSGame(): return self.parent = self.empty_parent() self.board = m.getBoardAtPly(shown, boardview.shownVariationIdx) self.queue.put(self.board.board) def gamewidget_closed(self, gamewidget): try: self.queue.put_nowait(self.StopNow) except Full: log.warning("EndgameAdvisor.gamewidget_closed: Queue.Full") @idle_add def on_scored(self, w, ret): m = self.boardview.model if m.isPlayingICSGame(): return board, endings = ret if board != self.board.board: return for move, result, depth in endings: if result == DRAW: result = (_("Draw"), 1, 0.5) details = "" elif (result == WHITEWON) ^ (self.board.color == WHITE): result = (_("Loss"), 1, 0.0) details = _("Mate in %d") % depth else: result = (_("Win"), 1, 1.0) details = _("Mate in %d") % depth self.store.append(self.parent, [(self.board, move, None), result, 0, False, details, False, False]) self.tv.expand_row(Gtk.TreePath(self.path), False)