Exemple #1
0
def rawPGN(pgn):
    g = PGNreader.read1Game(pgn)
    p = Partida.Partida(fen=g.fen)
    p.leerPV(g.pv())

    txt = ""
    for k,v in g.labels.iteritems():
        txt += "[%s \"%s\"]\n"%(k,v)
    txt += "\n\n"
    txt += p.pgnBase()

    return txt
Exemple #2
0
def rawPGN(pgn):
    g = PGNreader.read1Game(pgn)
    p = Partida.Partida(fen=g.fen)
    p.leerPV(g.pv())

    txt = ""
    for k, v in g.labels.iteritems():
        txt += "[%s \"%s\"]\n" % (k, v)
    txt += "\n\n"
    txt += p.pgnBase()

    return txt
    def read_line(self, line):
        li = line.strip().split("|")
        self.fen, self.label, pgn_moves = li[0], li[1], li[2]

        self.pgn = '[FEN "%s"]\n\n%s' % (self.fen, pgn_moves)
        g = PGNreader.read1Game(self.pgn)
        self.pv = g.pv()
        self.limoves = self.pv.split(" ")

        nmoves = len(self.limoves)
        self.num_moves = int(len(self.limoves) / 2)
        if nmoves % 2 == 1:
            self.num_moves += 1
        return self
Exemple #4
0
    def leeTexto(self, texto):
        game = PGNreader.read1Game(texto)
        if game.erroneo:
            return False
        cp = ControlPosicion.ControlPosicion()
        cp.leeFen(game.fen)
        p = Partida.Partida(cp)
        p.firstComment = game.moves.firstComment

        for mv in game.moves.liMoves:
            cpBase = ControlPosicion.ControlPosicion()
            cpBase.leeFen(mv.fenPrev)
            cpActual = ControlPosicion.ControlPosicion()
            cpActual.leeFen(mv.fen)
            jg = Jugada.Jugada()
            jg.ponDatos(cpBase, cpActual, mv.desde, mv.hasta, mv.coronacion)

            if mv.criticas:
                li = []
                for una in mv.criticas:
                    if una:
                        if una.isdigit():
                            li.append(una)
                        elif una[0] == "$":
                            una = una[1:]
                            if una:
                                li.append(una)
                        elif una[0] in "?!":
                            jg.criticaDirecta = una
                jg.critica = " ".join(li)
            if mv.comentarios:
                jg.comentario = "\n".join(mv.comentarios)
            if mv.variantes:
                li = []
                for una in mv.variantes:
                    li.append(una.toPGN())
                jg.variantes = "\n\n".join(li)
            p.append_jg(jg)
        if game.moves:
            p.ultPosicion = cpActual if game.moves.liMoves else cp.copia()
        self.partida = p
        self.dic = game.labels
        self.siError = False
        self.texto = texto
        return True
Exemple #5
0
    def leeTexto(self, texto):
        game = PGNreader.read1Game(unicode(texto))
        cp = ControlPosicion.ControlPosicion()
        cp.leeFen(game.fen)
        p = Partida.Partida(cp)
        p.firstComment = game.moves.firstComment

        for mv in game.moves.liMoves:
            cpBase = ControlPosicion.ControlPosicion()
            cpBase.leeFen(mv.fenPrev)
            cpActual = ControlPosicion.ControlPosicion()
            cpActual.leeFen(mv.fen)
            jg = Jugada.Jugada()
            jg.ponDatos(cpBase, cpActual, mv.desde, mv.hasta, mv.coronacion)
            if mv.criticas:
                li = []
                for una in mv.criticas:
                    if una:
                        if una.isdigit():
                            li.append(una)
                        elif una[0] == "$":
                            una = una[1:]
                            if una:
                                li.append(una)
                        elif una[0] in "?!":
                            jg.criticaDirecta = una
                jg.critica = " ".join(li)
            if mv.comentarios:
                jg.comentario = "\n".join(mv.comentarios)
            if mv.variantes:
                li = []
                for una in mv.variantes:
                    li.append(una.toPGN())
                jg.variantes = "\n\n".join(li)
            p.liJugadas.append(jg)
        if game.moves:
            p.ultPosicion = cpActual if game.moves.liMoves else cp.copia()
        self.partida = p
        self.dic = game.labels
        self.siError = False
        self.texto = texto
Exemple #6
0
 def numPlies(self, jugadas):
     game = PGNreader.read1Game(jugadas)
     return game.plies()
Exemple #7
0
 def numPlies(self, jugadas):
     game = PGNreader.read1Game(jugadas)
     return game.plies()
    def mas(self):
        path = QTVarios.select_pgn(self)
        if not path:
            return

        fpgn = PGN.PGN()

        dicDB = fpgn.leeFichero(self, path)
        if dicDB is None:
            return

        bd = SQLBase.DBBase(dicDB["PATHDB"])

        dClavesTam = dicDB["DCLAVES"]
        dbf = bd.dbf("GAMES", ",".join(dClavesTam.keys()))
        dbf.leer()

        nreccount = dbf.reccount()

        plant = ""
        shuffle = False
        reverse = False
        todos = range(1, nreccount + 1)
        li_regs = None
        while True:
            sep = FormLayout.separador
            liGen = []
            liGen.append((None, "%s: %d" % (_("Total games"), nreccount)))
            liGen.append(sep)
            config = FormLayout.Editbox(_("Select games") + "<br>" +
                                        _("By example:") + " -5,7-9,14,19-" +
                                        "<br>" + _("Empty means all games"),
                                        rx="[0-9,\-,\,]*")
            liGen.append((config, plant))

            liGen.append(sep)

            liGen.append((_("Shuffle") + ":", shuffle))

            liGen.append(sep)

            liGen.append((_("Reverse") + ":", reverse))

            liGen.append(sep)

            config = FormLayout.Spinbox(_("Max moves"), 0, 999, 50)
            liGen.append((config, 0))

            resultado = FormLayout.fedit(liGen,
                                         title=_("Select games"),
                                         parent=self,
                                         anchoMinimo=200,
                                         icon=Iconos.Opciones())
            if resultado:
                accion, liResp = resultado
                plant, shuffle, reverse, max_moves = liResp
                if plant:
                    ln = Util.ListaNumerosImpresion(plant)
                    li_regs = ln.selected(todos)
                else:
                    li_regs = todos
                nregs = len(li_regs)
                if 12 <= nregs <= 500:
                    break
                else:
                    QTUtil2.mensError(
                        self, "%s (%d)" %
                        (_("Number of games must be in range 12-500"), nregs))
                    li_regs = None
            else:
                break

        if li_regs:
            if shuffle:
                random.shuffle(li_regs)
            if reverse:
                li_regs.sort(reverse=True)
            li_regs = [x - 1 for x in li_regs]  # 0 init

            dic = {}
            dic["TOURNEY"] = os.path.basename(path)[:-4]
            games = dic["GAMES"] = []

            for recno in li_regs:
                pgn = dbf.leeOtroCampo(recno, "PGN")
                g = PGNReader.read1Game(pgn)
                pv = g.pv()
                if max_moves:
                    lipv = pv.strip().split(" ")
                    if len(lipv) > max_moves:
                        pv = " ".join(lipv[:max_moves])
                dt = {
                    "LABELS": [(k, v) for k, v in g.labels.items()],
                    "XPV": LCEngine.pv2xpv(pv)
                }
                games.append(dt)

            self.litourneys.append(dic)

            li = [("%s (%d)" % (tourney["TOURNEY"], len(tourney["GAMES"])),
                   tourney) for tourney in self.litourneys]
            self.cbtourney.rehacer(li, dic)

        dbf.cerrar()
        bd.cerrar()