def on_analyze(self, engine, analysis): if self.boardview.animating: return if self.boardview.model.isPlayingICSGame(): return if not self.active: return is_FAN = conf.get("figuresInNotation", False) for i, line in enumerate(analysis): if line is None: self.store[self.path + (i, )] = self.textOnlyRow("") continue board0 = self.engine.board board = board0.clone() movstrs, score, depth = line try: pv = listToMoves(board, movstrs, validate=True) except ParsingError as e: # ParsingErrors may happen when parsing "old" lines from # analyzing engines, which haven't yet noticed their new tasks log.debug("__parseLine: Ignored (%s) from analyzer: ParsingError%s" % (' '.join(movstrs), e)) return except: return move = None if pv: move = pv[0] ply0 = board.ply if self.mode == HINT else board.ply + 1 counted_pv = [] for j, pvmove in enumerate(pv): ply = ply0 + j if ply % 2 == 0: mvcount = "%d." % (ply / 2 + 1) elif j == 0: mvcount = "%d..." % (ply / 2 + 1) else: mvcount = "" counted_pv.append("%s%s" % (mvcount, toFAN(board, pvmove) if is_FAN else toSAN(board, pvmove, True))) board = board.move(pvmove) goodness = (min(max(score, -250), 250) + 250) / 500.0 if self.engine.board.color == BLACK: score = -score self.store[self.path + (i, )] = [ (board0, move, pv), (prettyPrintScore(score, depth), 1, goodness), 0, False, " ".join(counted_pv), False, False ]
def on_analyze(self, engine, analysis): if self.boardview.animating: return if self.boardview.model.isPlayingICSGame(): return if not self.active: return is_FAN = conf.get("figuresInNotation", False) for i, line in enumerate(analysis): if line is None: self.store[self.path + (i, )] = self.textOnlyRow("") continue board0 = self.engine.board board = board0.clone() movstrs, score, depth = line try: pv = listToMoves(board, movstrs, validate=True) except ParsingError as e: # ParsingErrors may happen when parsing "old" lines from # analyzing engines, which haven't yet noticed their new tasks log.debug( "__parseLine: Ignored (%s) from analyzer: ParsingError%s" % (' '.join(movstrs), e)) return except: return move = None if pv: move = pv[0] ply0 = board.ply if self.mode == HINT else board.ply + 1 counted_pv = [] for j, pvmove in enumerate(pv): ply = ply0 + j if ply % 2 == 0: mvcount = "%d." % (ply / 2 + 1) elif j == 0: mvcount = "%d..." % (ply / 2 + 1) else: mvcount = "" counted_pv.append("%s%s" % (mvcount, toFAN( board, pvmove) if is_FAN else toSAN(board, pvmove, True))) board = board.move(pvmove) goodness = (min(max(score, -250), 250) + 250) / 500.0 if self.engine.board.color == BLACK: score = -score self.store[self.path + (i, )] = [ (board0, move, pv), (prettyPrintScore(score, depth), 1, goodness), 0, False, " ".join(counted_pv), False, False ]
def __addMove(self, game, ply): # print "Am I doing anything?" row, view, other = self._ply_to_row_col_other(ply) if conf.get("figuresInNotation", False): notat = toFAN( game.getBoardAtPly(ply - 1), game.getMoveAtPly(ply - 1)) else: notat = toSAN( game.getBoardAtPly(ply - 1), game.getMoveAtPly(ply - 1), localRepr=True) # Test if the row is 'filled' if len(view.get_model()) == len(self.numbers.get_model()): num = str((ply + 1) // 2) + "." self.numbers.get_model().append([num]) # Test if the move is black first move. This will be the case if the # game was loaded from a fen/epd starting at black if view == self.right and len(view.get_model()) == len(other.get_model( )): self.left.get_model().append([""]) view.get_model().append([notat])
def shown_changed(self, board, shown): self.openings = getOpenings(self.board.model.getBoardAtPly(shown)) self.openings.sort(lambda a, b: sum(b[1:]) - sum(a[1:])) self.board.bluearrow = None self.store.clear() if not self.openings and self.sw.get_child() == self.tv: self.sw.remove(self.tv) label = gtk.Label(_("In this position,\nthere is no book move.")) label.set_property("yalign", 0.1) self.sw.add_with_viewport(label) self.sw.get_child().set_shadow_type(gtk.SHADOW_NONE) self.sw.show_all() return if self.openings and self.sw.get_child() != self.tv: self.sw.remove(self.sw.get_child()) self.sw.add(self.tv) i = 0 for move, wins, draws, loses in self.openings: games = wins + draws + loses if not games: continue wins, draws, loses = \ map(lambda x: x/float(games), (wins, draws, loses)) b = self.board.model.getBoardAtPly(shown) if conf.get("figuresInNotation", False): move = toFAN(b, parseSAN(b, move)) else: move = toSAN(b, parseSAN(b, move), True) self.store.append([move, str(games), (wins, draws, loses)])
def shown_changed (self, board, shown): self.openings = getOpenings(self.board.model.getBoardAtPly(shown)) self.openings.sort(lambda a, b: sum(b[1:])-sum(a[1:])) self.board.bluearrow = None self.store.clear() if not self.openings and self.sw.get_child() == self.tv: self.sw.remove(self.tv) label = gtk.Label(_("In this position,\nthere is no book move.")) label.set_property("yalign",0.1) self.sw.add_with_viewport(label) self.sw.get_child().set_shadow_type(gtk.SHADOW_NONE) self.sw.show_all() return if self.openings and self.sw.get_child() != self.tv: self.sw.remove(self.sw.get_child()) self.sw.add(self.tv) i = 0 for move, wins, draws, loses in self.openings: games = wins+draws+loses if not games: continue wins, draws, loses = \ map(lambda x: x/float(games), (wins, draws, loses)) b = self.board.model.getBoardAtPly(shown) if conf.get("figuresInNotation", False): move = toFAN(b, parseSAN(b, move)) else: move = toSAN(b, parseSAN(b, move), True) self.store.append ([move, str(games), (wins,draws,loses)])
def getMoveText(column, cell, store, iter, data): board, move, pv = store[iter][0] if not move: cell.set_property("text", "") else: if conf.get("figuresInNotation", False): cell.set_property("text", toFAN(board, move)) else: cell.set_property("text", toSAN(board, move, True))
def figuresInNotationCallback (none): game = self.boardview.model for board, move in zip(game.variations[0], game.moves): if conf.get("figuresInNotation", False): notat = toFAN(board, move) else: notat = toSAN(board, move, True) row, col, other = self._ply_to_row_col_other(board.ply+1) iter = col.get_model().get_iter((row,)) col.get_model().set(iter, 0, notat)
def figuresInNotationCallback(none): game = self.boardview.model for board, move in zip(game.variations[0], game.moves): if conf.get("figuresInNotation", False): notat = toFAN(board, move) else: notat = toSAN(board, move, True) row, col, other = self._ply_to_row_col_other(board.ply + 1) iter = col.get_model().get_iter((row, )) col.get_model().set(iter, 0, notat)
def add_move(self, gamemodel, ply): if ply == gamemodel.lowply: self.store.append([ "%4s." % gamemodel.lowply, "1234567", "1234567", 0, self.get_background_rgba(), self.get_background_rgba(), ]) return if self.figuresInNotation: notat = toFAN(gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1)) else: notat = toSAN( gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1), localRepr=True, ) row, column = self.ply_to_row_col(ply) if len(self.store) - 1 < row: mvcount = "%s." % ((ply + 1) // 2) if column == self.white_column: self.store.append([ mvcount, notat, "", row, self.get_background_rgba(), self.get_background_rgba(), ]) else: self.store.append([ mvcount, "", notat, row, self.get_background_rgba(), self.get_background_rgba(), ]) else: treeiter = self.store.get_iter(Gtk.TreePath(row)) col = 1 if column == self.white_column else 2 self.store.set_value(treeiter, col, notat)
def on_analyze(self, engine, analysis): m = self.boardview.model if m.isPlayingICSGame(): return if not self.active: return is_FAN = conf.get("figuresInNotation", False) for i, line in enumerate(analysis): if line is None: self.store[self.path + (i, )] = self.textOnlyRow("") continue pv, score, depth = line move = None if pv: move = pv[0] board0 = self.engine.board board = board0.clone() ply0 = board.ply if self.mode == HINT else board.ply + 1 counted_pv = [] for j, pvmove in enumerate(pv): ply = ply0 + j if ply % 2 == 0: mvcount = "%d." % (ply / 2 + 1) elif j == 0: mvcount = "%d..." % (ply / 2 + 1) else: mvcount = "" counted_pv.append("%s%s" % (mvcount, toFAN( board, pvmove) if is_FAN else toSAN(board, pvmove, True))) board = board.move(pvmove) # TODO make a move's "goodness" relative to other moves or past scores goodness = (min(max(score, -250), 250) + 250) / 500.0 if self.engine.board.color == BLACK: score = -score self.store[self.path + (i, )] = [ (board0, move, pv), (prettyPrintScore(score, depth), 1, goodness), 0, False, " ".join(counted_pv), False, False ]
def figuresInNotationCallback(none): game = self.boardview.model if game.lesson_game: return for i, move in enumerate(game.moves): board = game.variations[0][i] ply = game.lowply + i + 1 if conf.get("figuresInNotation", False): notat = toFAN(board, move) else: notat = toSAN(board, move, True) row, column = self.ply_to_row_col(ply) col = 2 if column == self.black_column else 1 treeiter = self.store.get_iter(Gtk.TreePath(row)) self.store.set_value(treeiter, col, notat)
def on_analyze (self, engine, analysis): m = self.boardview.model if m.isPlayingICSGame(): return if not self.active: return is_FAN = conf.get("figuresInNotation", False) for i, line in enumerate(analysis): if line is None: self.store[self.path + (i,)] = self.textOnlyRow("") continue pv, score, depth = line move = None if pv: move = pv[0] board0 = self.engine.board board = board0.clone() ply0 = board.ply if self.mode == HINT else board.ply+1 counted_pv = [] for j, pvmove in enumerate(pv): ply = ply0 + j if ply % 2 == 0: mvcount = "%d." % (ply/2+1) elif j==0: mvcount = "%d..." % (ply/2+1) else: mvcount = "" counted_pv.append("%s%s" % (mvcount, toFAN(board, pvmove) if is_FAN else toSAN(board, pvmove, True))) board = board.move(pvmove) # TODO make a move's "goodness" relative to other moves or past scores goodness = (min(max(score, -250), 250) + 250) / 500.0 if self.engine.board.color == BLACK: score = -score self.store[self.path + (i,)] = [(board0, move, pv), (prettyPrintScore(score, depth), 1, goodness), 0, False, " ".join(counted_pv), False, False]
def add_move(self, gamemodel, ply): if ply == gamemodel.lowply: self.store.append(["%4s." % gamemodel.lowply, "1234567", "1234567", 0, self.get_background_rgba(), self.get_background_rgba()]) return if conf.get("figuresInNotation", False): notat = toFAN(gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1)) else: notat = toSAN(gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1), localRepr=True) row, column = self.ply_to_row_col(ply) if len(self.store) - 1 < row: mvcount = "%s." % ((ply + 1) // 2) if column == self.white_column: self.store.append([mvcount, notat, "", row, self.get_background_rgba(), self.get_background_rgba()]) else: self.store.append([mvcount, "", notat, row, self.get_background_rgba(), self.get_background_rgba()]) else: treeiter = self.store.get_iter(Gtk.TreePath(row)) col = 1 if column == self.white_column else 2 self.store.set_value(treeiter, col, notat)
def __addMove(self, game, ply): # print "Am I doing anything?" row, view, other = self._ply_to_row_col_other(ply) if conf.get("figuresInNotation", False): notat = toFAN(game.getBoardAtPly(ply - 1), game.getMoveAtPly(ply - 1)) else: notat = toSAN(game.getBoardAtPly(ply - 1), game.getMoveAtPly(ply - 1), localRepr=True) # Test if the row is 'filled' if len(view.get_model()) == len(self.numbers.get_model()): num = str((ply + 1) // 2) + "." self.numbers.get_model().append([num]) # Test if the move is black first move. This will be the case if the # game was loaded from a fen/epd starting at black if view == self.right and len(view.get_model()) == len( other.get_model()): self.left.get_model().append([""]) view.get_model().append([notat])