def player_has_moved(self, from_sq, to_sq, promotion=""):
        jgUsu = self.check_human_move(from_sq, to_sq, promotion)
        if not jgUsu:
            return False

        self.vtime += time.time() - self.iniTiempo

        jgObj = self.gameObj.move(self.posJugadaObj)

        siAnalizaJuez = True
        if self.book:
            fen = self.last_fen()
            siBookUsu = self.book.check_human(fen, from_sq, to_sq)
            siBookObj = self.book.check_human(fen, jgObj.from_sq, jgObj.to_sq)
            if siBookUsu and siBookObj:
                if jgObj.movimiento() != jgUsu.movimiento():
                    bmove = _("book move")
                    comment = "%s: %s %s<br>%s: %s %s" % (
                        self.nombreObj,
                        jgObj.pgn_translated(),
                        bmove,
                        self.configuration.x_player,
                        jgUsu.pgn_translated(),
                        bmove,
                    )
                    w = WindowJuicio.MensajeF(self.main_window, comment)
                    w.mostrar()
                siAnalizaJuez = False
            else:
                siAnalizaJuez = True
                if not siBookObj:
                    self.book = None

        analysis = None
        comment = None

        if siAnalizaJuez:
            um = QTUtil2.analizando(self.main_window)
            pvUsu = jgUsu.movimiento()
            pvObj = jgObj.movimiento()
            mrm = self.analizaMinimo(pvUsu, pvObj)
            position = self.game.last_position

            rmUsu, nada = mrm.buscaRM(pvUsu)
            rmObj, posObj = mrm.buscaRM(pvObj)

            analysis = mrm, posObj
            um.final()

            w = WindowJuicio.WJuicio(self, self.xanalyzer, self.nombreObj,
                                     position, mrm, rmObj, rmUsu, analysis)
            w.exec_()

            analysis = w.analysis
            if w.siAnalisisCambiado:
                self.siSave = True
            dpts = w.difPuntos()
            self.puntos += dpts

            dptsMax = w.difPuntosMax()
            self.puntosMax += dptsMax

            comentarioUsu = " %s" % (rmUsu.abrTexto())
            comentarioObj = " %s" % (rmObj.abrTexto())

            comentarioPuntos = "%s = %d %+d %+d = %d" % (
                _("Score"),
                self.puntos - dpts,
                rmUsu.centipawns_abs(),
                -rmObj.centipawns_abs(),
                self.puntos,
            )
            comment = "%s: %s %s\n%s: %s %s\n%s" % (
                self.nombreObj,
                jgObj.pgn_translated(),
                comentarioObj,
                self.configuration.x_player,
                jgUsu.pgn_translated(),
                comentarioUsu,
                comentarioPuntos,
            )
            self.ponPuntos()

        self.analizaFinal()

        self.add_move(True, analysis, comment)
        self.play_next_move()
        return True
示例#2
0
    def player_has_moved(self, from_sq, to_sq, promotion=""):
        jgUsu = self.check_human_move(from_sq, to_sq, promotion)
        if not jgUsu:
            return False

        jgObj = self.gameObj.move(self.posJugadaObj)

        analysis = None
        comment = None

        comentarioUsu = ""
        comentarioObj = ""

        siAnalizaJuez = jgUsu.movimiento() != jgObj.movimiento()
        if self.book:
            fen = self.last_fen()
            siBookUsu = self.book.check_human(fen, from_sq, to_sq)
            siBookObj = self.book.check_human(fen, jgObj.from_sq, jgObj.to_sq)
            if siBookUsu:
                comentarioUsu = _("book move")
            if siBookObj:
                comentarioObj = _("book move")
            if siBookUsu and siBookObj:
                if jgObj.movimiento() != jgUsu.movimiento():
                    # comment = "%s: %s" % (_("Same book move"), jgObj.pgn_translated())
                    # else:
                    bmove = _("book move")
                    comment = "%s: %s %s\n%s: %s %s" % (
                        self.nombreObj,
                        jgObj.pgn_translated(),
                        bmove,
                        self.configuration.x_player,
                        jgUsu.pgn_translated(),
                        bmove,
                    )
                    w = WindowJuicio.MensajeF(self.main_window, comment)
                    w.mostrar()
                siAnalizaJuez = False
            else:
                if not siBookObj:
                    self.book = None

        if siAnalizaJuez:
            um = QTUtil2.analizando(self.main_window)
            if not self.continueTt:
                self.analizaInicio()
            mrm = self.analizaMinimo(5000)
            position = self.game.last_position

            rmUsu, nada = mrm.buscaRM(jgUsu.movimiento())
            if rmUsu is None:
                self.analizaFinal()
                rmUsu = self.xtutor.valora(position, jgUsu.from_sq,
                                           jgUsu.to_sq, jgUsu.promotion)
                mrm.agregaRM(rmUsu)
                self.analizaInicio()

            rmObj, posObj = mrm.buscaRM(jgObj.movimiento())
            if rmObj is None:
                self.analizaFinal()
                rmObj = self.xtutor.valora(position, jgObj.from_sq,
                                           jgObj.to_sq, jgObj.promotion)
                posObj = mrm.agregaRM(rmObj)
                self.analizaInicio()

            analysis = mrm, posObj
            um.final()

            w = WindowJuicio.WJuicio(self, self.xtutor, self.nombreObj,
                                     position, mrm, rmObj, rmUsu, analysis)
            w.exec_()

            analysis = w.analysis
            dpts = w.difPuntos()

            self.puntos += dpts
            self.ponPuntos()

            comentarioUsu += " %s" % (rmUsu.abrTexto())
            comentarioObj += " %s" % (rmObj.abrTexto())

            comentarioPuntos = "%s = %d %+d %+d = %d" % (
                _("Points"),
                self.puntos - dpts,
                rmUsu.centipawns_abs(),
                -rmObj.centipawns_abs(),
                self.puntos,
            )

            comment = "%s: %s %s\n%s: %s %s\n%s" % (
                self.nombreObj,
                jgObj.pgn_translated(),
                comentarioObj,
                self.configuration.x_player,
                jgUsu.pgn_translated(),
                comentarioUsu,
                comentarioPuntos,
            )

        self.analizaFinal()

        self.add_move(True, comment, analysis)
        self.play_next_move()
        return True
示例#3
0
    def player_has_moved(self, from_sq, to_sq, promotion=""):
        jgUsu = self.check_human_move(from_sq, to_sq, promotion)
        if not jgUsu:
            return False

        self.vtime += time.time() - self.iniTiempo

        jgObj = self.gameObj.move(self.posJugadaObj)
        fen = jgObj.position_before.fen()

        siAnalizaJuez = True
        if self.book:
            siBookUsu = self.book.check_human(fen, from_sq, to_sq)
            siBookObj = self.book.check_human(fen, jgObj.from_sq, jgObj.to_sq)
            if siBookUsu and siBookObj:
                if jgObj.movimiento() != jgUsu.movimiento():
                    bmove = _("book move")
                    comment = "%s: %s %s<br>%s: %s %s" % (
                        self.nombreObj,
                        jgObj.pgn_translated(),
                        bmove,
                        self.configuration.x_player,
                        jgUsu.pgn_translated(),
                        bmove,
                    )
                    w = WindowJuicio.MensajeF(self.main_window, comment)
                    w.mostrar()
                siAnalizaJuez = False
            else:
                siAnalizaJuez = True
                if not siBookObj:
                    self.book = None

        analysis = None
        comment = None

        if siAnalizaJuez:
            position = self.game.last_position
            saved = fen in self.dic_analysis
            if saved:
                rmObj, posObj, analysis, mrm = self.dic_analysis[fen]
            else:
                if self.continueTt:
                    um = QTUtil2.analizando(self.main_window)
                    mrm = self.analizaMinimo(
                        3000) if self.continueTt else self.mrm
                    um.final()
                else:
                    self.analizaNoContinuoFinal()
                    mrm = self.mrm
                rmObj, posObj = mrm.buscaRM(jgObj.movimiento())
                analysis = mrm, posObj
                self.dic_analysis[fen] = [rmObj, posObj, analysis, mrm]

            rmUsu, posUsu = mrm.buscaRM(jgUsu.movimiento())
            if rmUsu is None:
                um = QTUtil2.analizando(self.main_window)
                self.analizaFinal()
                rmUsu = self.xanalyzer.valora(position, from_sq, to_sq,
                                              promotion)
                mrm.agregaRM(rmUsu)
                self.analizaInicio()
                um.final()

            w = WindowJuicio.WJuicio(self,
                                     self.xanalyzer,
                                     self.nombreObj,
                                     position,
                                     mrm,
                                     rmObj,
                                     rmUsu,
                                     analysis,
                                     is_competitive=False)
            w.exec_()

            if not saved:
                analysis = w.analysis
                self.dic_analysis[fen][2] = analysis

            dpts = w.difPuntos()
            self.puntos += dpts
            self.ponPuntos()

            if posUsu != posObj:
                comentarioUsu = " %s" % (rmUsu.abrTexto())
                comentarioObj = " %s" % (rmObj.abrTexto())

                comentarioPuntos = "%s = %d %+d %+d = %d" % (
                    _("Score"),
                    self.puntos - dpts,
                    rmUsu.centipawns_abs(),
                    -rmObj.centipawns_abs(),
                    self.puntos,
                )
                comment = "%s: %s %s\n%s: %s %s\n%s" % (
                    self.nombreObj,
                    jgObj.pgn_translated(),
                    comentarioObj,
                    self.configuration.x_player,
                    jgUsu.pgn_translated(),
                    comentarioUsu,
                    comentarioPuntos,
                )
        if not self.continueTt:
            self.terminaNoContinuo()

        self.analizaFinal()

        self.add_move(True, analysis, comment)

        self.play_next_move()
        return True
示例#4
0
    def player_has_moved(self, from_sq, to_sq, promotion=""):
        jgUsu = self.check_human_move(from_sq, to_sq, promotion)
        if not jgUsu:
            return False

        movimiento = jgUsu.movimiento()
        position = self.game.last_position
        isValid = self.motorGM.is_valid_move(movimiento)
        analysis = None

        if not isValid:
            self.board.set_position(position)
            self.board.activate_side(self.human_side)
            li_moves = self.motorGM.get_moves_txt(position, True)
            desdeGM, hastaGM, promotionGM = WindowGM.select_move(
                self, li_moves, True)
            siAnalizaJuez = self.with_adjudicator
            if siAnalizaJuez:
                if self.book:
                    fen = self.last_fen()
                    siH = self.book.check_human(fen, from_sq, to_sq)
                    is_gm = self.book.check_human(fen, desdeGM, hastaGM)
                    if is_gm and siH:
                        siAnalizaJuez = False
                    else:
                        self.book = False
        else:
            siAnalizaJuez = self.with_adjudicator and self.mostrar is None  # None es ver siempre False no ver nunca True ver si diferentes
            if len(movimiento) == 5:
                promotion = movimiento[4].lower()
            desdeGM, hastaGM, promotionGM = from_sq, to_sq, promotion

        ok, mens, jgGM = Move.get_game_move(self.game, position, desdeGM,
                                            hastaGM, promotionGM)
        movGM = jgGM.pgn_translated()
        movUsu = jgUsu.pgn_translated()

        if siAnalizaJuez:
            um = QTUtil2.analizando(self.main_window)
            mrm = self.analizaMinimo(self.vtime * 100)

            import time

            t = time.time()

            rmUsu, nada = mrm.buscaRM(jgUsu.movimiento())
            if rmUsu is None:
                um = QTUtil2.analizando(self.main_window)
                self.analizaFinal()
                rmUsu = self.xtutor.valora(position, from_sq, to_sq, promotion)
                mrm.agregaRM(rmUsu)
                self.analizaInicio()
                um.final()

            rmGM, pos_gm = mrm.buscaRM(jgGM.movimiento())
            if rmGM is None:
                self.analizaFinal()
                rmGM = self.xtutor.valora(position, desdeGM, hastaGM,
                                          promotionGM)
                pos_gm = mrm.agregaRM(rmGM)
                self.analizaInicio()

            um.final()

            analysis = mrm, pos_gm
            dpts = rmUsu.centipawns_abs() - rmGM.centipawns_abs()

            if self.mostrar is None or ((self.mostrar is True)
                                        and not isValid):
                w = WindowJuicio.WJuicio(self,
                                         self.xtutor,
                                         self.nombreGM,
                                         position,
                                         mrm,
                                         rmGM,
                                         rmUsu,
                                         analysis,
                                         is_competitive=not self.show_evals)
                w.exec_()

                rm, pos_gm = w.analysis[0].buscaRM(jgGM.movimiento())
                analysis = w.analysis[0], pos_gm

                dpts = w.difPuntos()

            self.puntos += dpts

            comentario0 = "<b>%s</b> : %s = %s<br>" % (
                self.configuration.x_player, movUsu, rmUsu.texto())
            comentario0 += "<b>%s</b> : %s = %s<br>" % (self.nombreGM, movGM,
                                                        rmGM.texto())
            comentario1 = "<br><b>%s</b> = %+d<br>" % (_("Difference"), dpts)
            comentario2 = "<b>%s</b> = %+d<br>" % (_("Centipawns accumulated"),
                                                   self.puntos)
            self.textoPuntuacion = comentario2
            self.ponRotuloSecundario()

            if not isValid:
                jgGM.comment = (comentario0 + comentario1 +
                                comentario2).replace("<b>", "").replace(
                                    "</b>", "").replace("<br>", "\n")

        self.analizaFinal()

        self.move_the_pieces(jgGM.liMovs)

        jgGM.analysis = analysis
        self.add_move(jgGM, True)
        self.error = ""
        self.play_next_move()
        return True