Esempio n. 1
0
    def miraBuffer(self):
        self.lock = True

        li = self.buffer.split("\n")
        if self.buffer.endswith("\n"):
            self.buffer = ""
        else:
            self.buffer = li[-1]
            li = li[:-1]
        mrm = XMotorRespuesta.MRespuestaMotor("", " w " in self.fen)
        mrm.dispatch("\n".join(li))
        mrm.maxTiempo = None
        mrm.maxProfundidad = 9999
        mrm.ordena()

        if mrm.liMultiPV:
            rm = mrm.liMultiPV[0]
            p = Partida.Partida(fen=self.fen)
            p.leerPV(rm.pv)
            li = p.pgnSP().split(" ")
            if len(li) > 20:
                li = li[:20]

            self.em.ponHtml("[%02d] %s | %s" % (rm.depth, rm.abrTexto(), " ".join(li)))

        self.lock = False
Esempio n. 2
0
    def _mejorMov(self, maxTiempo, maxProfundidad, siReturnTxt, siBlancas):
        env = "go"
        if maxProfundidad:
            env += " depth %d" % maxProfundidad
        elif maxTiempo:
            env += " movetime %d" % maxTiempo

        msTiempo = 10000
        if maxTiempo:
            msTiempo = maxTiempo
        elif maxProfundidad:
            msTiempo = int(maxProfundidad * msTiempo / 3.0)

        resp = self.orden_bestmove(env, msTiempo)
        if not resp:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        mrm.dispatch(resp, maxTiempo, maxProfundidad)
        mrm.maxTiempo = maxTiempo
        mrm.maxProfundidad = maxProfundidad
        if siReturnTxt:
            return mrm, resp
        else:
            return mrm
    def _mejorMov(self, maxTiempo, maxProfundidad, siBlancas):
        env = "go"
        if maxProfundidad:
            env += " depth %d" % maxProfundidad
        elif maxTiempo:
            env += " movetime %d" % maxTiempo

        msTiempo = 10000
        if maxTiempo:
            msTiempo = maxTiempo
        elif maxProfundidad:
            msTiempo = int(maxProfundidad * msTiempo / 3.0)

        if self.guiDispatch:
            li_resp, result = self.pwait_list_dispatch(env, "bestmove",
                                                       msTiempo)
        else:
            li_resp, result = self.pwait_list(env, "bestmove", msTiempo)

        if not result:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        for linea in li_resp:
            mrm.dispatch(linea)
        mrm.maxTiempo = maxTiempo
        mrm.maxProfundidad = maxProfundidad
        mrm.ordena()
        return mrm
Esempio n. 4
0
 def ac_inicio(self, partida):
     self.lockAC = True
     self.posicionPartida(partida)
     self.siBlancas = partida.ultPosicion.siBlancas
     self.connect(self, QtCore.SIGNAL("readyReadStandardOutput()"),
                  self.ac_lee)
     self.mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, self.siBlancas)
     self.flush()
     self.escribe("go infinite")
     self.waitForReadyRead(90)
     self.lockAC = False
Esempio n. 5
0
    def _mejorMovInfinitoTiempo(self, maxTiempo, siBlancas):
        busca = " @@ "  # que no busque nada
        resp = self.orden_infinito(busca, maxTiempo)
        if not resp:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        mrm.dispatch(resp, maxTiempo, None)
        mrm.maxTiempo = maxTiempo
        mrm.maxProfundidad = None
        return mrm
Esempio n. 6
0
    def _mejorMovTiempo(self, fen, tiempoBlancas, tiempoNegras, tiempoJugada,
                        siBlancas):
        env = "go wtime %d btime %d" % (tiempoBlancas, tiempoNegras)
        if tiempoJugada:
            env += " winc %d" % tiempoJugada
        maxtiempo = tiempoBlancas if " w " in fen else tiempoNegras
        resp = self.orden_bestmove(env, maxtiempo)
        if not resp:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        mrm.dispatch(resp, None, None)
        return mrm
Esempio n. 7
0
    def _mejorMovInfinito(self, maxProfundidad, siBlancas):
        busca = " depth %d " % maxProfundidad

        tiempo = maxProfundidad * 2000
        if maxProfundidad > 9:
            tiempo += (maxProfundidad - 9) * 20000

        resp = self.orden_infinito(busca, tiempo)
        if not resp:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        mrm.dispatch(resp, None, maxProfundidad)
        mrm.maxTiempo = None
        mrm.maxProfundidad = maxProfundidad
        return mrm
Esempio n. 8
0
 def dispatch(self):
     QtCore.QCoreApplication.processEvents(
         QtCore.QEventLoop.ExcludeUserInputEvents)
     if self.guiDispatch:
         tm = time.time()
         if tm - self.ultDispatch < self.minDispatch:
             return True
         self.ultDispatch = tm
         mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, self.siBlancas)
         if self._buffer.endswith("\n"):
             b = self._buffer
         else:
             n = self._buffer.rfind("\n")
             b = self._buffer[:-n + 1] if n > 1 else ""
         mrm.dispatch(b)
         mrm.ordena()
         rm = mrm.mejorMov()
         rm.whoDispatch = self.whoDispatch
         if not self.guiDispatch(rm):
             return False
     return True
Esempio n. 9
0
    def juega(self):
        fen = self.procesador.gestor.partida.fenUltimo()

        if self.jugadasTutor == 0:
            siTutor = self.siJuegaTutor
            mrm = self.xtutor.control(fen, 3)
            rm = mrm.liMultiPV[0]
            self.siJuegaTutor = self.rmComparar.siMejorQue(rm, 0, 0)
        else:
            self.numJugada += 1
            siTutor = self.numJugada % self.jugadasTutor == 0

        if siTutor:
            mrm = self.xtutor.control(fen, 3)

        else:
            pv = self.funcion(fen)
            mrm = XMotorRespuesta.MRespuestaMotor("interno", "w" in fen)
            mrm.dispatch("bestmove " + pv, None, None)

        return mrm.liMultiPV[0]
 def pwait_list_dispatch(self, orden, txt_busca, maxtime):
     self.put_line(orden)
     ini = time.time()
     tm_dispatch = ini
     li = []
     mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, self.is_white)
     while time.time() - ini < maxtime:
         if (time.time() - tm_dispatch) >= 1.0:
             mrm.ordena()
             rm = mrm.mejorMov()
             if not self.guiDispatch(rm):
                 return li, False
             tm_dispatch = time.time()
         line = self.stdout.readline().strip()
         if self.log:
             self.log_write(line)
         li.append(line)
         mrm.dispatch(line)
         if line.startswith(txt_busca):
             return li, True
     return li, False
Esempio n. 11
0
    def _mejorMov(self, maxTiempo, maxProfundidad, siBlancas):
        env = "go"
        if maxProfundidad:
            env += " depth %d" % maxProfundidad
        elif maxTiempo:
            env += " movetime %d" % maxTiempo

        msTiempo = 10000
        if maxTiempo:
            msTiempo = maxTiempo
        elif maxProfundidad:
            msTiempo = int(maxProfundidad * msTiempo / 3.0)

        resp = self.orden_bestmove(env, msTiempo)
        if not resp:
            return None

        mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, siBlancas)
        for linea in resp.split("\n"):
            mrm.dispatch(linea.strip())
        mrm.maxTiempo = maxTiempo
        mrm.maxProfundidad = maxProfundidad
        mrm.ordena()
        return mrm
Esempio n. 12
0
    def miraBuffer(self):
        if self.lock:
            return
        self.lock = True

        li = self.buffer.split("\n")
        if self.buffer.endswith("\n"):
            self.buffer = ""
        else:
            self.buffer = li[-1]
            li = li[:-1]

        for linea in li:
            if linea.startswith("info ") and " pv " in linea and " depth " in linea and "multipv" in linea:
                n = linea.index("depth")
                depth = int(linea[n:].split(" ")[1].strip())
                n = linea.index("multipv")
                multipv = int(linea[n:].split(" ")[1].strip())
                if depth not in self.dicLineasDepth:
                    self.dicLineasDepth[depth] = {}
                self.dicLineasDepth[depth][multipv] = linea.strip()
        mxdepth = 0
        liBorrar = []
        for depth, lista in self.dicLineasDepth.iteritems():
            if len(lista) == self.numMovesDepth:
                if depth > mxdepth:
                    liBorrar.append(depth)
                    mxdepth = depth

        if mxdepth:
            mrm = XMotorRespuesta.MRespuestaMotor(self.cpu.titulo, self.siW)
            for multipv, linea in self.dicLineasDepth[mxdepth].iteritems():
                mrm.miraPV(linea)
            mrm.ordena()
            self.liData = mrm.liMultiPV

            # Borramos hasta esa depth
            for depth in liBorrar:
                del self.dicLineasDepth[depth]

            rm = mrm.liMultiPV[0]
            self.lbDepth.ponTexto("%s: %d" % (_("Depth"), rm.depth))
            partida = Partida.Partida(fen=self.fen)
            partida.leerPV(rm.pv)
            if partida.numJugadas():
                self.tablero.quitaFlechas()
                jg0 = partida.jugada(0)
                self.tablero.ponPosicion(jg0.posicion)
                tipo = "mt"
                opacidad = 100
                salto = (80 - 15) * 2 / (self.nArrows - 1) if self.nArrows > 1 else 1
                cambio = max(30, salto)

                for njg in range(min(partida.numJugadas(), self.nArrows)):
                    tipo = "ms" if tipo == "mt" else "mt"
                    jg = partida.jugada(njg)
                    self.tablero.creaFlechaMov(jg.desde, jg.hasta, tipo + str(opacidad))
                    if njg % 2 == 1:
                        opacidad -= cambio
                        cambio = salto

            self.grid.refresh()

        self.lock = False
Esempio n. 13
0
    def miraBuffer(self):
        if not self.siPlay:
            return
        self.lock = True

        li = self.buffer.split("\n")
        if self.buffer.endswith("\n"):
            self.buffer = ""
        else:
            self.buffer = li[-1]
            li = li[:-1]
        mrm = XMotorRespuesta.MRespuestaMotor("", " w " in self.fen)
        mrm.dispatch("\n".join(li))
        mrm.ordena()
        mrm.maxTiempo = None
        mrm.maxProfundidad = 9999

        if mrm.liMultiPV:

            cp = ControlPosicion.ControlPosicion()
            cp.leeFen(self.fen)

            litxt = ['<table border="1" cellpadding="4" cellspacing="0" style="border-color: #ACA899">', ]

            def tr(tp, mas=""):
                litxt.append('<tr><th>%s</th><td align="right">%.01f%%</td><td>%s%s</td></tr>' % (tp[0], tp[1], mas, tp[2]))

            tp = AnalisisIndexes.tp_gamestage(cp, mrm)
            litxt.append('<tr><th>%s</th><td align="right">%d</td><td>%s</td></tr>' % (tp[0], tp[1], tp[2]))

            pts = mrm.liMultiPV[0].puntosABS()
            if pts:
                w, b = _("White"), _("Black")
                siW = "w" in self.fen
                if pts > 0:
                    mas = w if siW else b
                elif pts < 0:
                    mas = b if siW else w
                mas += "-"
            else:
                mas = ""

            tr(AnalisisIndexes.tp_winprobability(cp, mrm), mas)
            tr(AnalisisIndexes.tp_complexity(cp, mrm))
            tr(AnalisisIndexes.tp_efficientmobility(cp, mrm))

            tr(AnalisisIndexes.tp_narrowness(cp, mrm))
            tr(AnalisisIndexes.tp_piecesactivity(cp, mrm))
            tr(AnalisisIndexes.tp_exchangetendency(cp, mrm))

            tp = AnalisisIndexes.tp_positionalpressure(cp, mrm)
            litxt.append('<tr><th>%s</th><td align="right">%dcp</td><td></td></tr>' % (tp[0], int(tp[1])))

            tr(AnalisisIndexes.tp_materialasymmetry(cp, mrm))

            # tr(AnalisisIndexes.tp_test1(cp, mrm))
            # tr(AnalisisIndexes.tp_test2(cp, mrm))
            # tr(AnalisisIndexes.tp_test3(cp, mrm))
            # tr(AnalisisIndexes.tp_test4(cp, mrm))
            # tr(AnalisisIndexes.tp_test5(cp, mrm))

            litxt.append("</table>")

            self.em.ponHtml("".join(litxt))

        self.lock = False
Esempio n. 14
0
 def reset(self):
     self.get_lines()
     self.mrm = XMotorRespuesta.MRespuestaMotor(self.nombre, self.is_white)
Esempio n. 15
0
 def juega_captura(self, fen):
     pv = self.mi.mp2(fen)
     mrm = XMotorRespuesta.MRespuestaMotor("interno", "w" in fen)
     mrm.dispatch("bestmove " + pv, None, None)
     return mrm.liMultiPV[0]