예제 #1
0
    def __init__(self, store, tv, boardview):
        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.queue = asyncio.Queue()
        self.egtb_task = asyncio.async(self.start())
예제 #2
0
    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()
예제 #3
0
파일: bookPanel.py 프로젝트: well69/pychess
    def __init__(self, store, tv, boardcontrol):
        Advisor.__init__(self, store, _("Endgame Table"), ENDGAME)
        # deferred import to not slow down PyChess starting up
        from pychess.Utils.EndgameTable import EndgameTable
        self.egtb = EndgameTable()
        # If mate in # was activated by double click let egtb do the rest
        self.auto_activate = False
        self.tv = tv
        self.boardcontrol = boardcontrol
        self.boardview = boardcontrol.view
        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.queue = asyncio.Queue()
        self.egtb_task = create_task(self.start())
예제 #4
0
    def __init__(self, store, tv, boardview):
        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.queue = asyncio.Queue()
        self.egtb_task = asyncio.async(self.start())
예제 #5
0
    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()
예제 #6
0
파일: bookPanel.py 프로젝트: JKrame/pychess
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, ))
예제 #7
0
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)
예제 #8
0
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):
    def __init__(self, store, tv, boardcontrol):
        Advisor.__init__(self, store, _("Endgame Table"), ENDGAME)
        # deferred import to not slow down PyChess starting up
        from pychess.Utils.EndgameTable import EndgameTable

        self.egtb = EndgameTable()
        # If mate in # was activated by double click let egtb do the rest
        self.auto_activate = False
        self.tv = tv
        self.boardcontrol = boardcontrol
        self.boardview = boardcontrol.view
        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.queue = asyncio.Queue()
        self.egtb_task = create_task(self.start())

    class StopNow(Exception):
        pass

    @asyncio.coroutine
    def start(self):
        while True:
            v = yield from self.queue.get()
            if isinstance(v, Exception) and v == self.StopNow:
                break
            elif v == self.board.board:
                ret = yield from self.egtb.scoreAllMoves(v)
                self.on_scored(v, ret)
            self.queue.task_done()

    def shownChanged(self, boardview, shown):
        m = boardview.model
        if m is None or m.variant.variant != NORMALCHESS or m.isPlayingICSGame():
            if not (m.practice_game or m.lesson_game):
                return

        self.parent = self.empty_parent()
        self.board = m.getBoardAtPly(shown, boardview.shown_variation_idx)
        self.queue.put_nowait(self.board.board)

    def _del(self):
        try:
            self.queue.put_nowait(self.StopNow)
        except asyncio.QueueFull:
            log.warning("EndgameAdvisor.gamewidget_closed: Queue.Full")
        self.egtb_task.cancel()

    def on_scored(self, board, endings):
        m = self.boardview.model

        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

            if m.practice_game or m.lesson_game:
                m.hint = "%s %s %s" % (
                    toSAN(self.board, move, True),
                    result[0],
                    details,
                )
                return

            if m.isPlayingICSGame():
                return

            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

            self.boardcontrol.play_or_add_move(board, move)
예제 #10
0
class EndgameAdvisor(Advisor):
    def __init__(self, store, tv, boardview):
        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.queue = asyncio.Queue()
        self.egtb_task = asyncio.async(self.start())

    class StopNow(Exception):
        pass

    @asyncio.coroutine
    def start(self):
        while True:
            v = yield from self.queue.get()
            if v == self.StopNow:
                break
            elif v == self.board.board:
                ret = yield from self.egtb.scoreAllMoves(v)
                self.on_scored(v, ret)
            self.queue.task_done()

    def shownChanged(self, boardview, shown):
        m = boardview.model
        if m is None or m.variant.variant != NORMALCHESS or m.isPlayingICSGame():
            if not (m.practice_game or m.lesson_game):
                return

        self.parent = self.empty_parent()
        self.board = m.getBoardAtPly(shown, boardview.shown_variation_idx)
        self.queue.put_nowait(self.board.board)

    def _del(self):
        try:
            self.queue.put_nowait(self.StopNow)
        except asyncio.QueueFull:
            log.warning("EndgameAdvisor.gamewidget_closed: Queue.Full")
        self.egtb_task.cancel()

    def on_scored(self, board, endings):
        m = self.boardview.model

        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

            if m.practice_game or m.lesson_game:
                m.hint = "%s %s %s" % (toSAN(self.board, move, True), result[0], details)
                return

            if m.isPlayingICSGame():
                return

            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

            play_or_add_move(self.boardview, board, move)