def seleccionaLibro(self): listaLibros = Books.ListaLibros() listaLibros.recuperaVar(self.configuracion.ficheroBooks) listaLibros.comprueba() menu = QTVarios.LCMenu(self) rondo = QTVarios.rondoPuntos() for book in listaLibros.lista: menu.opcion(("x", book), book.nombre, rondo.otro()) menu.separador() menu.opcion(("n", None), _("Install new book"), Iconos.Nuevo()) resp = menu.lanza() if resp: orden, book = resp if orden == "x": pass elif orden == "n": fbin = QTUtil2.leeFichero(self, listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: listaLibros.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] book = Books.Libro("P", nombre, fbin, True) listaLibros.nuevo(book) listaLibros.guardaVar(self.configuracion.ficheroBooks) else: book = None return book
def __init__(self, gestor, cromo): self.cromo = cromo self.gestor = gestor self.partida = gestor.partida self.nombre = cromo.nombre self.xirina = None self.xsimilar = None conf_motor = self.gestor.configuracion.buscaRival("irina") self.xirina = XGestorMotor.GestorMotor(self.gestor.procesador, conf_motor) self.xirina.opciones(None, 1, False) self.apertura = self.cromo.apertura if self.apertura: bookdef = VarGen.tbookPTZ self.book = Books.Libro("P", bookdef.split("/")[1], bookdef, True) self.book.polyglot() # De compatibilidad self.motorTiempoJugada = 0 self.motorProfundidad = 0 atexit.register(self.cerrar)
def __init__(self, gestor, cromo): self.cromo = cromo self.gestor = gestor self.partida = gestor.partida self.mi = MotorInterno.MotorInterno() self.nombre = cromo.nombre self.xgaia = None self.xsimilar = None self.apertura = self.cromo.apertura if self.apertura: bookdef = VarGen.tbookPTZ self.book = Books.Libro("P", bookdef.split("/")[1], bookdef, True) self.book.polyglot() # De compatibilidad self.motorTiempoJugada = 0 self.motorProfundidad = 0 atexit.register(self.cerrar)
def aceptar(self): if not self.fichero: return me = QTUtil2.unMomento(self) # Creamos el pgn fichTemporal = self.wParent.damePGNtemporal() # Creamos la linea de ordenes if VarGen.isWindows: exe = 'Engines/Windows/_tools/polyglot/polyglot.exe' else: exe = 'Engines/Linux/_tools/polyglot/polyglot' li = [os.path.abspath(exe), 'make-book', "-pgn", fichTemporal, "-bin", self.fichero] Util.borraFichero(self.fichero) maxPly = self.sbMaxPly.valor() minGame = self.sbMinGame.valor() minScore = self.sbMinScore.valor() onlyWhite = self.chbOnlyWhite.valor() onlyBlack = self.chbOnlyBlack.valor() uniform = self.chbUniform.valor() if maxPly: li.append("-max-ply") li.append("%d" % maxPly) if minGame and minGame != 3: li.append("-min-game") li.append("%d" % minGame) if minScore: li.append("-min-score") li.append("%d" % minScore) if onlyBlack: li.append("-only-black") if onlyWhite: li.append("-only-white") if uniform: li.append("-uniform") # Ejecutamos process = subprocess.Popen(li, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # Mostramos el resultado txt = process.stdout.read() if os.path.isfile(self.fichero): txt += "\n" + _X(_("Book created : %1"), self.fichero) me.final() QTUtil2.mensaje(self, txt) Util.borraFichero(fichTemporal) nombre = os.path.basename(self.fichero)[:-4] b = Books.Libro("P", nombre, self.fichero, False) self.listaLibros.nuevo(b) fvar = self.configuracion.ficheroBooks self.listaLibros.guardaVar(fvar) self.accept()
def nuevo(self): fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] b = Books.Libro("P", nombre, fbin, False) self.listaLibros.nuevo(b) self.siCambios = True self.rehacerCB(b)
def nuevoBook(self): fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] b = Books.Libro("P", nombre, fbin, False) self.listaLibros.nuevo(b) fvar = self.configuracion.ficheroBooks self.listaLibros.guardaVar(fvar) li = [(x.nombre, x) for x in self.listaLibros.lista] self.cbBooks.rehacer(li, b)
def eligeJugadaBookAjustada(self): if self.nAjustarFuerza < 1000: return False, None, None, None dicPersonalidad = self.configuracion.liPersonalidades[self.nAjustarFuerza - 1000] nombook = dicPersonalidad.get("BOOK", None) if (nombook is None) or (not Util.existeFichero(nombook)): return False, None, None, None book = Books.Libro("P", nombook, nombook, True) book.polyglot() return self.eligeJugadaBookBase(book, "pr")
def nuevoBook(self): fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] b = Books.Libro("P", nombre, fbin, False) self.listaLibros.nuevo(b) fvar = VarGen.configuracion.ficheroBooks self.listaLibros.guardaVar(fvar) li = [(x.nombre, x.path) for x in self.listaLibros.lista] li.insert(0, ("* " + _("Engine book"), "-")) li.insert(0, ("* " + _("Default"), "*")) self.cbBooks.rehacer(li, b.path)
def inicio(self, route): GestorRoutes.inicio(self, route) line = route.get_line() opening = line.opening siBlancas = opening.is_white if opening.is_white is not None else random.choice( [True, False]) self.liPVopening = opening.pv.split(" ") self.posOpening = 0 self.is_opening = len(opening.pv) > 0 self.book = Books.Libro("P", VarGen.tbookI, VarGen.tbookI, True) self.book.polyglot() self.engine = GR_Engine(self.procesador, line.engine) self.must_win = route.must_win() self.rivalPensando = False self.siJuegaHumano = False self.estado = kJugando self.siJugamosConBlancas = siBlancas self.siRivalConBlancas = not siBlancas self.pantalla.ponActivarTutor(False) self.ayudasPGN = 0 liOpciones = [k_mainmenu, k_configurar, k_reiniciar] self.pantalla.ponToolBar(liOpciones) self.pantalla.activaJuego(True, False, siAyudas=False) self.pantalla.quitaAyudas(True) self.ponRotulo1(self.engine.label) if self.must_win: self.ponRotulo2(_("You must win to pass this game")) self.ponMensajero(self.mueveHumano) self.ponPosicion(self.partida.ultPosicion) self.mostrarIndicador(True) self.ponPiezasAbajo(siBlancas) self.pgnRefresh(True) QTUtil.xrefreshGUI() self.ponPosicionDGT() self.siguienteJugada()
def menuLibros(self): menu = QTVarios.LCMenu(self) nBooks = len(self.listaLibros.lista) for book in self.listaLibros.lista: ico = Iconos.PuntoVerde( ) if book == self.book else Iconos.PuntoNaranja() menu.opcion(("x", book), book.nombre, ico) menu.separador() menu.opcion(("n", None), _("Install new book"), Iconos.Nuevo()) if nBooks > 1: menu.separador() menub = menu.submenu(_("Remove a book from the list"), Iconos.Delete()) for book in self.listaLibros.lista: if not book.pordefecto: menub.opcion(("b", book), book.nombre, Iconos.Delete()) menu.separador() menu.opcion(("1", None), _("Find Next") + " <F3>", Iconos.Buscar()) resp = menu.lanza() if resp: orden, book = resp if orden == "x": self.cambiaLibro(book) elif orden == "n": fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] book = Books.Libro("P", nombre, fbin, True) self.listaLibros.nuevo(book) self.cambiaLibro(book) elif orden == "b": self.listaLibros.borra(book) self.listaLibros.guardaVar(self.fvar) elif orden == "1": self.buscaSiguiente()
def grabarPolyglot(self, ventana, ficheroBIN, depth, whiteBest, blackBest): titulo = _("Import a polyglot book") tmpBP2 = QTUtil2.BarraProgreso2(ventana, titulo) tmpBP2.ponTotal(1, 1) tmpBP2.ponRotulo( 1, "1. " + _X(_("Reading %1"), os.path.basename(ficheroBIN))) tmpBP2.ponTotal(2, 1) tmpBP2.ponRotulo(2, "") tmpBP2.mostrar() basePos = self.ultPos book = Books.Libro("P", ficheroBIN, ficheroBIN, True) book.polyglot() cp = ControlPosicion.ControlPosicion() lireg = [] stFenM2 = set() # para que no se produzca un circulo vicioso def hazFEN(fen, ply, seq): plyN = ply + 1 siWhite = " w " in fen siMax = False if whiteBest: siMax = siWhite if blackBest: siMax = siMax or not siWhite liPV = book.miraListaPV(fen, siMax) for pv in liPV: cp.leeFen(fen) cp.mover(pv[:2], pv[2:4], pv[4:]) fenN = cp.fen() reg = SQLDBF.Almacen() lireg.append(reg) reg.PV = pv seqN = seq + LCEngine.pv2xpv(pv) reg.XPV = seqN reg.COMMENT = "" reg.NAG = 0 reg.FEN = fenN reg.ADV = 0 self.ultPos += 1 reg.POS = self.ultPos tmpBP2.ponTotal(1, self.ultPos - basePos) tmpBP2.pon(1, self.ultPos - basePos) if plyN < depth: fenM2 = cp.fenM2() if fenM2 not in stFenM2: stFenM2.add(fenM2) hazFEN(fenN, plyN, seqN) hazFEN(ControlPosicion.FEN_INICIAL, 0, "") select = "XPV,PV,COMMENT,NAG,ADV,FEN,POS" dbf = SQLDBF.DBF(self.conexion, self.tablaDatos, select) tmpBP2.ponTotal(2, len(lireg)) tmpBP2.ponRotulo(2, _("Writing...")) def dispatch(num): tmpBP2.pon(2, num) dbf.insertarLista(lireg, dispatch) dbf.cerrar() tmpBP2.cerrar() return len(lireg) > 0
def inicio(self, datosMotor, minutos, segundos, siCompetitivo, aplazamiento=None): self.tipoJuego = kJugMicElo self.resultado = None self.siJuegaHumano = False self.estado = kJugando self.siCompetitivo = siCompetitivo self.puestoResultado = False # Problema doble asignacion de ptos Thomas if aplazamiento: siBlancas = aplazamiento["SIBLANCAS"] else: siBlancas = self.determinaColor(datosMotor) self.siJugamosConBlancas = siBlancas self.siRivalConBlancas = not siBlancas self.rmRival = None self.liRMrival = [] self.noMolestar = 0 self.resignPTS = -1000 self.siTutorActivado = False self.pantalla.ponActivarTutor(False) self.ayudasPGN = self.ayudas = 0 self.tiempo = {} self.maxSegundos = minutos * 60 self.segundosJugada = segundos # -Aplazamiento 1/2-------------------------------------------------- if aplazamiento: self.partida.recuperaDeTexto(aplazamiento["JUGADAS"]) self.datosMotor = self.engineAplazado(aplazamiento["ALIAS"], aplazamiento["BASEELO"]) self.tiempo[True] = Util.Timer(aplazamiento["TIEMPOBLANCAS"]) self.tiempo[False] = Util.Timer(aplazamiento["TIEMPONEGRAS"]) self.maxSegundos = aplazamiento["MAXSEGUNDOS"] self.segundosJugada = aplazamiento["SEGUNDOSJUGADA"] self.listaAperturasStd.asignaApertura(self.partida) else: self.datosMotor = datosMotor self.tiempo[True] = Util.Timer(self.maxSegundos) self.tiempo[False] = Util.Timer(self.maxSegundos) cbook = self.datosMotor.book if self.datosMotor.book else VarGen.tbook self.book = Books.Libro("P", cbook, cbook, True) self.book.polyglot() elo = self.datosMotor.elo self.maxMoveBook = elo / 200 if 0 <= elo <= 1700 else 9999 eloengine = self.datosMotor.elo eloplayer = self.configuracion.miceloActivo(siCompetitivo) self.whiteElo = eloplayer if siBlancas else eloengine self.blackElo = eloplayer if not siBlancas else eloengine self.xrival = self.procesador.creaGestorMotor(self.datosMotor, None, None, siMultiPV=self.datosMotor.multiPV > 0) self.pteToolRendirse = False if not self.siCompetitivo: self.pteToolRendirse = True self.maxPlyRendirse = 6 elif self.siJugamosConBlancas: self.pteToolRendirse = True self.maxPlyRendirse = 1 else: self.maxPlyRendirse = 0 if aplazamiento and self.partida.numJugadas() > self.maxPlyRendirse: self.pteToolRendirse = False self.ponToolBar() self.pantalla.activaJuego(True, True, siAyudas=False) self.ponMensajero(self.mueveHumano) self.ponPosicion(self.partida.ultPosicion) self.ponPiezasAbajo(siBlancas) self.quitaAyudas(True, siQuitarAtras=siCompetitivo) self.mostrarIndicador(True) nbsp = " " * 3 txt = "%s:%+d%s%s:%+d%s%s:%+d" % (_("Win"), self.datosMotor.pgana, nbsp, _("Draw"), self.datosMotor.ptablas, nbsp, _("Lost"), self.datosMotor.ppierde) self.ponRotulo1("<center>%s</center>" % txt) self.ponRotulo2("") self.pgnRefresh(True) self.ponCapInfoPorDefecto() # -Aplazamiento 2/2-------------------------------------------------- if aplazamiento: self.mueveJugada(kMoverFinal) self.siPrimeraJugadaHecha = True else: self.siPrimeraJugadaHecha = False tpBL = self.tiempo[True].etiqueta() tpNG = self.tiempo[False].etiqueta() self.rival = rival = self.datosMotor.alias + " (%d)" % self.datosMotor.elo jugador = self.configuracion.jugador + " (%d)" % self.configuracion.miceloActivo(siCompetitivo) bl, ng = jugador, rival if self.siRivalConBlancas: bl, ng = ng, bl self.pantalla.ponDatosReloj(bl, tpBL, ng, tpNG) self.refresh() self.ponPosicionDGT() self.siguienteJugada()
def siguienteJuego(self, gm, ngame, numGames): self.estado = kJugando self.gm = gm self.maxSegundos = self.gm.minutos() * 60.0 self.segundosJugada = self.gm.segundosJugada() rival = { True: self.torneo.buscaHEngine(self.gm.hwhite()), False: self.torneo.buscaHEngine(self.gm.hblack()), } self.tiempo = {} self.book = {} self.bookRR = {} self.xmotor = {} for color in (True, False): rv = rival[color] self.xmotor[color] = XGestorMotor.GestorMotor( self.procesador, rv.configMotor()) self.xmotor[color].opciones(rv.time() * 1000, rv.depth(), False) self.xmotor[color].ponGuiDispatch(self.guiDispatch) self.tiempo[color] = Util.Timer(self.maxSegundos) bk = rv.book() if bk == "*": bk = VarGen.tbook elif bk == "-": bk = None if bk: self.book[color] = Books.Libro("P", bk, bk, True) self.book[color].polyglot() else: self.book[color] = None self.bookRR[color] = rv.bookRR() self.partida = Partida.Partida(fen=self.fenInicial) self.pgn.partida = self.partida self.alturaRotulo3(32) self.desactivaTodas() self.ponPosicion(self.partida.ultPosicion) self.pgnRefresh(True) # self.siPrimeraJugadaHecha = False tpBL = self.tiempo[True].etiqueta() tpNG = self.tiempo[False].etiqueta() bl = self.xmotor[True].nombre ng = self.xmotor[False].nombre self.pantalla.activaJuego(True, True, siAyudas=False) self.ponRotulo1("<center><b>%s %d/%d</b></center>" % (_("Game"), ngame, numGames)) self.ponRotulo2(None) self.quitaAyudas() self.pantalla.ponDatosReloj(bl, tpBL, ng, tpNG) self.refresh() self.finPorTiempo = None while self.siguienteJugada(): pass self.xmotor[True].terminar() self.xmotor[False].terminar() self.pantalla.paraReloj()
def inicio(self, dic, aplazamiento=None, siPrimeraJugadaHecha=False): if aplazamiento: dic = aplazamiento["EMDIC"] self.reinicio = dic self.tipoJuego = kJugEntMaq self.resultado = None self.siJuegaHumano = False self.siJuegaPorMi = True self.estado = kJugando self.siAnalizando = False self.timekeeper = Util.Timekeeper() self.summary = {} # numJugada : "a"ccepted, "s"ame, "r"ejected, dif points, time used self.siSummary = dic.get("SUMMARY", False) siBlancas = dic["SIBLANCAS"] self.siJugamosConBlancas = siBlancas self.siRivalConBlancas = not siBlancas self.cm = dic["RIVAL"].get("CM", None) if self.cm: if hasattr(self.cm, "icono"): delattr(self.cm, "icono") # problem with configuracion.escVariables and saving qt variables self.siAtras = dic["ATRAS"] self.rmRival = None self.liRMrival = [] self.noMolestar = 0 self.resignPTS = -99999 # never self.aperturaObl = self.aperturaStd = None self.fen = dic["FEN"] if self.fen: cp = ControlPosicion.ControlPosicion() cp.leeFen(self.fen) self.partida.reset(cp) self.partida.pendienteApertura = False if "MOVE" in dic: self.partida.leerPV(dic["MOVE"]) else: if dic["APERTURA"]: self.aperturaObl = Apertura.JuegaApertura(dic["APERTURA"].a1h8) self.primeroBook = False # la apertura es obligatoria self.pensando(True) self.book = dic.get("BOOK", None) elo = getattr(self.cm, "elo", 0) self.maxMoveBook = elo / 200 if 0 < elo <= 1700 else 9999 if self.book: self.book.polyglot() self.bookRR = dic.get("BOOKRR", "mp") self.bookMandatory = dic.get("BOOKMANDATORY", False) elif dic["RIVAL"].get("TIPO", None) in (Motores.MICGM, Motores.MICPER): if self.cm.book: self.book = Books.Libro("P", self.cm.book, self.cm.book, True) self.book.polyglot() self.bookRR = "mp" self.bookMandatory = None self.maxMoveBook = 0 self.siTutorActivado = (VarGen.dgtDispatch is None) and self.configuracion.tutorActivoPorDefecto self.pantalla.ponActivarTutor(self.siTutorActivado) self.ayudas = dic["AYUDAS"] self.ayudasPGN = self.ayudas # Se guarda para guardar el PGN self.nArrows = dic.get("ARROWS", 0) nBoxHeight = dic.get("BOXHEIGHT", 24) self.thoughtOp = dic.get("THOUGHTOP", -1) self.thoughtTt = dic.get("THOUGHTTT", -1) self.continueTt = dic.get("CONTINUETT", False) self.nArrowsTt = dic.get("ARROWSTT", 0) self.chance = dic.get("2CHANCE", True) if self.nArrowsTt and self.ayudas == 0: self.nArrowsTt = 0 self.childmode = self.nArrowsTt > 0 and self.ayudas > 0 mx = max(self.thoughtOp, self.thoughtTt) if mx > -1: self.alturaRotulo3(nBoxHeight) dr = dic["RIVAL"] rival = dr["CM"] if dr["TIPO"] == Motores.ELO: r_t = 0 r_p = rival.fixed_depth self.nAjustarFuerza = kAjustarMejor else: r_t = dr["TIEMPO"] * 100 # Se guarda en decimas -> milesimas r_p = dr["PROFUNDIDAD"] self.nAjustarFuerza = dic.get("AJUSTAR", kAjustarMejor) if not self.xrival: # reiniciando is not None if r_t <= 0: r_t = None if r_p <= 0: r_p = None if r_t is None and r_p is None and not dic["SITIEMPO"]: r_t = 1000 self.xrival = self.procesador.creaGestorMotor(rival, r_t, r_p, self.nAjustarFuerza != kAjustarMejor) if self.nAjustarFuerza != kAjustarMejor: self.xrival.maximizaMultiPV() self.resignPTS = dr["RESIGN"] self.siBookAjustarFuerza = self.nAjustarFuerza != kAjustarMejor self.xrival.ponGuiDispatch(self.guiDispatch, whoDispatch=False) self.xtutor.ponGuiDispatch(self.guiDispatch, whoDispatch=True) self.xrival.siBlancas = self.siRivalConBlancas self.siPrimeraJugadaHecha = siPrimeraJugadaHecha self.siTiempo = dic["SITIEMPO"] if self.siTiempo: self.maxSegundos = dic["MINUTOS"] * 60.0 self.segundosJugada = dic["SEGUNDOS"] self.segExtra = dic.get("MINEXTRA", 0) * 60.0 self.zeitnot = dic.get("ZEITNOT", 0) self.tiempo = {} self.tiempo[True] = Util.Timer(self.maxSegundos) self.tiempo[False] = Util.Timer(self.maxSegundos) if self.segExtra: self.tiempo[self.siJugamosConBlancas].ponSegExtra(self.segExtra) self.pensando(False) # -Aplazamiento 1/2-------------------------------------------------- if aplazamiento: self.partida.recuperaDeTexto(aplazamiento["JUGADAS"]) self.partida.pendienteApertura = aplazamiento["PENDIENTEAPERTURA"] self.partida.apertura = None if aplazamiento["APERTURA"] is None else self.listaAperturasStd.dic[ aplazamiento["APERTURA"]] self.siTutorActivado = aplazamiento["SITUTOR"] self.pantalla.ponActivarTutor(self.siTutorActivado) self.ayudas = aplazamiento["AYUDAS"] self.summary = aplazamiento["SUMMARY"] self.siTiempo = aplazamiento["SITIEMPO"] if self.siTiempo: self.maxSegundos = aplazamiento["MAXSEGUNDOS"] self.segundosJugada = aplazamiento["SEGUNDOSJUGADA"] self.segExtra = aplazamiento.get("SEGEXTRA", 0) self.tiempo = {} self.tiempo[True] = Util.Timer(aplazamiento["TIEMPOBLANCAS"]) self.tiempo[False] = Util.Timer(aplazamiento["TIEMPONEGRAS"]) if self.segExtra: self.tiempo[self.siJugamosConBlancas].ponSegExtra(self.segExtra) self.siPrimeraJugadaHecha = False li = [k_cancelar, k_rendirse, k_tablas, k_atras, k_ayudaMover, k_reiniciar, k_aplazar, k_peliculaPausa, k_configurar, k_utilidades] if not self.siAtras: del li[3] self.pantalla.ponToolBar(li) self.pantalla.mostrarOpcionToolbar(k_tablas, True) self.pantalla.activaJuego(True, self.siTiempo) self.ponMensajero(self.mueveHumano) self.ponPosicion(self.partida.ultPosicion) self.mostrarIndicador(True) if self.ayudasPGN: self.ponAyudasEM() else: self.quitaAyudas(siQuitarAtras=not self.siAtras) self.ponPiezasAbajo(siBlancas) self.ponRotuloBasico() if self.ayudasPGN: self.ponRotulo2(_("Tutor") + ": <b>" + self.xtutor.nombre) else: self.ponRotulo2("") self.ponCapInfoPorDefecto() self.pgnRefresh(True) # -Aplazamiento 2/2-------------------------------------------------- if aplazamiento or "MOVE" in dic: self.mueveJugada(kMoverFinal) if self.siTiempo: self.siPrimeraJugadaHecha = siPrimeraJugadaHecha tpBL = self.tiempo[True].etiqueta() tpNG = self.tiempo[False].etiqueta() rival = self.xrival.nombre jugador = self.configuracion.jugador bl, ng = jugador, rival if self.siRivalConBlancas: bl, ng = ng, bl self.pantalla.ponDatosReloj(bl, tpBL, ng, tpNG) self.refresh() self.siAnalizadoTutor = False self.ponPosicionDGT() if self.childmode: self.pantalla.base.btActivarTutor.setVisible(False) self.siguienteJugada()