def seleccionaLibro(self): listaLibros = Books.ListaLibros() listaLibros.restore_pickle(self.configuracion.ficheroBooks) listaLibros.comprueba() menu = QTVarios.LCMenu(self) rondo = QTVarios.rondoPuntos() for book in listaLibros.lista: menu.opcion(("x", book), book.name, 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) name = os.path.basename(fbin)[:-4] book = Books.Libro("P", name, fbin, True) listaLibros.nuevo(book) listaLibros.save_pickle(self.configuracion.ficheroBooks) else: book = None return book
def __init__(self, gestor, cromo): self.cromo = cromo self.gestor = gestor self.game = gestor.game self.name = cromo.name self.xirina = None self.xsimilar = None conf_engine = self.gestor.configuracion.buscaRival("irina") self.xirina = EngineManager.EngineManager(self.gestor.procesador, conf_engine) self.xirina.opciones(None, 1, False) self.opening = self.cromo.opening if self.opening: bookdef = Code.tbookPTZ name = os.path.basename(bookdef)[:-4] self.book = Books.Libro("P", name, bookdef, True) self.book.polyglot() # De compatibilidad self.motorTiempoJugada = 0 self.motorProfundidad = 0 atexit.register(self.cerrar)
def nuevoBook(self): fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] b = Books.Libro("P", name, fbin, False) self.listaLibros.nuevo(b) fvar = self.configuracion.ficheroBooks self.listaLibros.save_pickle(fvar) li = [(x.name, 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.exist_file(nombook)): return False, None, None, None book = Books.Libro("P", nombook, nombook, True) book.polyglot() return self.eligeJugadaBookBase(book, "pr")
def polyglot_install(self, listaLibros): fbin = QTUtil2.leeFichero(self, listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: listaLibros.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] book = Books.Libro("P", name, fbin, True) listaLibros.nuevo(book) listaLibros.save_pickle(self.configuracion.ficheroBooks) num = self.kibitzers.nuevo_polyglot(book) self.goto(num)
def inicio(self, route): GestorRoutes.inicio(self, route) line = route.get_line() opening = line.opening is_white = 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", Code.tbookI, Code.tbookI, True) self.book.polyglot() self.engine = GR_Engine(self.procesador, line.engine) self.must_win = route.must_win() self.is_rival_thinking = False self.human_is_playing = False self.state = ST_PLAYING self.is_human_side_white = is_white self.is_engine_side_white = not is_white self.main_window.ponActivarTutor(False) self.ayudas_iniciales = 0 li_options = [TB_CLOSE, TB_CONFIG, TB_REINIT] self.main_window.pon_toolbar(li_options) self.main_window.activaJuego(True, False, siAyudas=False) self.main_window.quitaAyudas(True) self.ponRotulo1(self.engine.label) if self.must_win: self.ponRotulo2(_("You must win to pass this game")) self.set_dispatcher(self.mueve_humano) self.setposition(self.game.last_position) self.mostrarIndicador(True) self.ponPiezasAbajo(is_white) self.pgnRefresh(True) QTUtil.refresh_gui() self.dgt_setposition() self.siguiente_jugada()
def nuevoBook(self): fbin = QTUtil2.leeFichero(self, self.listaLibros.path, "bin", titulo=_("Polyglot book")) if fbin: self.listaLibros.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] b = Books.Libro("P", name, fbin, False) self.listaLibros.nuevo(b) fvar = Code.configuracion.ficheroBooks self.listaLibros.save_pickle(fvar) li = [(x.name, x.path) for x in self.listaLibros.lista] li.insert(0, ("* " + _("Engine book"), "-")) li.insert(0, ("* " + _("Default"), "*")) self.cbBooks.rehacer(li, b.path)
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.name, 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.name, 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) name = os.path.basename(fbin)[:-4] book = Books.Libro("P", name, fbin, True) self.listaLibros.nuevo(book) self.cambiaLibro(book) elif orden == "b": self.listaLibros.borra(book) self.listaLibros.save_pickle(self.fvar) elif orden == "1": self.buscaSiguiente()
def aceptar(self): if not self.fichero: return # Creamos el pgn fichTemporal = self.wParent.damePGNtemporal(self) if not fichTemporal: return me = QTUtil2.unMomento(self) # Creamos la linea de ordenes exe = "%s/_tools/polyglot/polyglot" % Code.folder_engines li = [ os.path.abspath(exe), "make-book", "-pgn", fichTemporal, "-bin", self.fichero ] Util.remove_file(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.message_bold(self, txt) Util.remove_file(fichTemporal) name = os.path.basename(self.fichero)[:-4] b = Books.Libro("P", name, self.fichero, False) self.listaLibros.nuevo(b) fvar = self.configuracion.ficheroBooks self.listaLibros.save_pickle(fvar) self.accept()
def procesa_game(self): self.pon_estado(ST_PLAYING) # ConfiguraciĆ³n self.fen_inicial = self.torneo.fenNorman() # Cerramos los motores anteriores si los hay Code.list_engine_managers.close_all() if self.torneo.adjudicator_active(): conf_engine = Code.configuracion.buscaRival( self.torneo.adjudicator()) self.xadjudicator = EngineManager.EngineManager(self, conf_engine) self.xadjudicator.opciones(self.torneo.adjudicator_time() * 1000, 0, False) self.xadjudicator.anulaMultiPV() else: self.xadjudicator = None self.next_control = 0 self.max_segundos = self.tournament_game.minutos * 60.0 self.segundos_jugada = self.tournament_game.segundos_jugada # abrimos motores rival = { WHITE: self.torneo.buscaHEngine(self.tournament_game.hwhite), BLACK: self.torneo.buscaHEngine(self.tournament_game.hblack), } for side in (WHITE, BLACK): self.lb_player[side].ponTexto(rival[side].name) self.vtime = {} self.book = {} self.bookRR = {} self.xengine = {} for side in (WHITE, BLACK): rv = rival[side] self.xengine[side] = EngineManager.EngineManager(self, rv) self.xengine[side].opciones(rv.time * 1000, rv.depth, False) self.xengine[side].ponGuiDispatch(self.gui_dispatch) self.vtime[side] = Util.Timer(self.max_segundos) bk = rv.book if bk == "*": bk = self.torneo.book() if bk == "-": # Puede que el torneo tenga "-" bk = None if bk: self.book[side] = Books.Libro("P", bk, bk, True) self.book[side].polyglot() else: self.book[side] = None self.bookRR[side] = rv.bookRR self.game = Game.Game(fen=self.fen_inicial) self.pgn.game = self.game self.lbRotulo3.altoFijo(32) self.tablero.disable_all() self.tablero.setposition(self.game.last_position) self.grid_pgn.refresh() for side in (WHITE, BLACK): ot = self.vtime[side] eti, eti2 = ot.etiquetaDif2() self.pon_reloj_side(side, eti, eti2) while self.state == ST_PAUSE or self.siguiente_jugada(): if self.state == ST_PAUSE: QTUtil.refresh_gui() time.sleep(0.1) if self.is_closed: break for side in (WHITE, BLACK): self.xengine[side].terminar() if not self.is_closed: if self.game_finished(): self.save_game_done()
def inicio(self, datosMotor, minutos, segundos, aplazamiento=None): self.game_type = GT_MICELO self.siCompetitivo = True self.resultado = None self.human_is_playing = False self.state = ST_PLAYING self.puestoResultado = False # Problema doble asignacion de ptos Thomas if aplazamiento: is_white = aplazamiento["ISWHITE"] else: is_white = self.determinaColor(datosMotor) self.is_human_side_white = is_white self.is_engine_side_white = not is_white self.lirm_engine = [] self.next_test_resign = 0 self.resign_limit = -1000 self.is_tutor_enabled = False self.main_window.ponActivarTutor(False) self.ayudas_iniciales = self.ayudas = 0 self.vtime = {} self.maxSegundos = minutos * 60 self.segundosJugada = segundos # -Aplazamiento 1/2-------------------------------------------------- if aplazamiento: self.game.restore(aplazamiento["JUGADAS"]) self.datosMotor = self.engineAplazado(aplazamiento["ALIAS"], aplazamiento["BASEELO"]) self.vtime[True] = Util.Timer(aplazamiento["TIEMPOBLANCAS"]) self.vtime[False] = Util.Timer(aplazamiento["TIEMPONEGRAS"]) self.maxSegundos = aplazamiento["MAXSEGUNDOS"] self.segundosJugada = aplazamiento["SEGUNDOSJUGADA"] self.game.assign_opening() else: self.datosMotor = datosMotor self.vtime[True] = Util.Timer(self.maxSegundos) self.vtime[False] = Util.Timer(self.maxSegundos) cbook = self.datosMotor.book if self.datosMotor.book else Code.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() self.whiteElo = eloplayer if is_white else eloengine self.blackElo = eloplayer if not is_white else eloengine self.xrival = self.procesador.creaGestorMotor( self.datosMotor, None, None, siMultiPV=self.datosMotor.multiPV > 0) self.pte_tool_resigndraw = False if self.is_human_side_white: self.pte_tool_resigndraw = True self.maxPlyRendirse = 1 else: self.maxPlyRendirse = 0 if aplazamiento and len(self.game) > self.maxPlyRendirse: self.pte_tool_resigndraw = False self.pon_toolbar() self.main_window.activaJuego(True, True, siAyudas=False) self.set_dispatcher(self.mueve_humano) self.setposition(self.game.last_position) self.ponPiezasAbajo(is_white) self.quitaAyudas(True, siQuitarAtras=True) self.mostrarIndicador(True) nbsp = " " * 3 txt = "%s:%+d%s%s:%+d%s%s:%+d" % ( _("Win"), self.datosMotor.pgana, nbsp, _("Draw"), self.datosMotor.ptablas, nbsp, _("Loss"), self.datosMotor.ppierde, ) self.ponRotulo1("<center>%s</center>" % txt) self.ponRotulo2("") self.pgnRefresh(True) self.ponCapInfoPorDefecto() # -Aplazamiento 2/2-------------------------------------------------- if aplazamiento: self.mueveJugada(GO_END) self.siPrimeraJugadaHecha = True else: self.siPrimeraJugadaHecha = False tpBL = self.vtime[True].etiqueta() tpNG = self.vtime[False].etiqueta() self.rival = rival = self.datosMotor.alias + " (%d)" % self.datosMotor.elo player = self.configuracion.x_player + " (%d)" % self.configuracion.miceloActivo( ) bl, ng = player, rival if self.is_engine_side_white: bl, ng = ng, bl self.main_window.ponDatosReloj(bl, tpBL, ng, tpNG) self.refresh() self.dgt_setposition() if not self.is_human_side_white: mensaje = _("Press the continue button to start.") self.mensajeEnPGN(mensaje) self.siguiente_jugada()
def __init__(self, cpu): QtWidgets.QDialog.__init__(self) self.cpu = cpu dicVideo = self.cpu.dic_video if not dicVideo: dicVideo = {} self.siTop = dicVideo.get("SITOP", True) self.siShowTablero = dicVideo.get("SHOW_TABLERO", True) self.position = Position.Position() self.fen = "" self.siPlay = True self.li_moves = [] self.history = [] self.setWindowTitle(cpu.titulo) self.setWindowIcon(Iconos.Book()) self.setWindowFlags( QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinimizeButtonHint ) self.setBackgroundRole(QtGui.QPalette.Light) Code.configuracion = cpu.configuracion Code.todasPiezas = Piezas.TodasPiezas() config_board = cpu.configuracion.config_board("kib" + cpu.kibitzer.huella, 24) self.tablero = Tablero.Tablero(self, config_board) self.tablero.crea() self.tablero.set_dispatcher(self.mensajero) Delegados.generaPM(self.tablero.piezas) self.book = Books.Libro("P", cpu.kibitzer.name, cpu.kibitzer.path_exe, True) self.book.polyglot() self.siFigurines = cpu.configuracion.x_pgn_withfigurines o_columns = Columnas.ListaColumnas() delegado = Delegados.EtiquetaPOS(True, siLineas=False) if self.siFigurines else None o_columns.nueva("MOVE", _("Move"), 80, centered=True, edicion=delegado) o_columns.nueva("PORC", "%", 60, centered=True) o_columns.nueva("WEIGHT", _("Weight"), 80, siDerecha=True) self.grid_moves = Grid.Grid(self, o_columns, dicVideo=dicVideo, siSelecFilas=True) li_acciones = ( (_("Quit"), Iconos.Kibitzer_Terminar(), self.terminar), (_("Continue"), Iconos.Kibitzer_Continuar(), self.play), (_("Pause"), Iconos.Kibitzer_Pausa(), self.pause), (_("Takeback"), Iconos.Atras(), self.takeback), (_("Manual position"), Iconos.Voyager(), self.set_position), (_("Show/hide board"), Iconos.Tablero(), self.config_board), ("%s: %s" % (_("Enable"), _("window on top")), Iconos.Top(), self.windowTop), ("%s: %s" % (_("Disable"), _("window on top")), Iconos.Bottom(), self.windowBottom), ) self.tb = Controles.TBrutina(self, li_acciones, siTexto=False, tamIcon=16) self.tb.setAccionVisible(self.play, False) ly1 = Colocacion.H().control(self.tb) ly2 = Colocacion.V().otro(ly1).control(self.grid_moves) layout = Colocacion.H().control(self.tablero).otro(ly2) self.setLayout(layout) self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.cpu.compruebaInput) self.timer.start(200) if not self.siShowTablero: self.tablero.hide() self.restore_video(dicVideo) self.ponFlags()
def base_inicio(self, dic_var): self.reinicio = dic_var self.cache = dic_var.get("cache", {}) self.game_type = GT_AGAINST_ENGINE self.human_is_playing = False self.plays_instead_of_me_option = True self.state = ST_PLAYING self.is_analyzing = False self.summary = { } # numJugada : "a"ccepted, "s"ame, "r"ejected, dif points, time used self.with_summary = dic_var.get("SUMMARY", False) is_white = dic_var["ISWHITE"] self.is_human_side_white = is_white self.is_engine_side_white = not is_white self.conf_engine = dic_var["RIVAL"].get("CM", None) self.lirm_engine = [] self.next_test_resign = 0 self.resign_limit = -99999 # never self.aperturaObl = self.aperturaStd = None self.fen = dic_var["FEN"] if self.fen: cp = Position.Position() cp.read_fen(self.fen) self.game.set_position(cp) self.game.pending_opening = False else: if dic_var["OPENING"]: self.aperturaObl = Apertura.JuegaApertura( dic_var["OPENING"].a1h8) self.primeroBook = False # la opening es obligatoria self.bookR = dic_var.get("BOOKR", None) if self.bookR: self.bookRdepth = dic_var.get("BOOKRDEPTH", 0) self.bookR.polyglot() self.bookRR = dic_var.get("BOOKRR", "mp") elif dic_var["RIVAL"].get("TIPO", None) in (SelectEngines.MICGM, SelectEngines.MICPER): if self.conf_engine.book: self.bookR = Books.Libro("P", self.conf_engine.book, self.conf_engine.book, True) self.bookR.polyglot() self.bookRR = "mp" self.bookRdepth = 0 self.bookP = dic_var.get("BOOKP", None) if self.bookP: self.bookPdepth = dic_var.get("BOOKPDEPTH", 0) self.bookP.polyglot() self.is_tutor_enabled = ( Code.dgtDispatch is None) and self.configuracion.x_default_tutor_active self.main_window.ponActivarTutor(self.is_tutor_enabled) self.ayudas = dic_var["HINTS"] self.ayudas_iniciales = self.ayudas # Se guarda para guardar el PGN self.nArrows = dic_var.get("ARROWS", 0) n_box_height = dic_var.get("BOXHEIGHT", 24) self.thoughtOp = dic_var.get("THOUGHTOP", -1) self.thoughtTt = dic_var.get("THOUGHTTT", -1) self.continueTt = dic_var.get("CONTINUETT", False) self.nArrowsTt = dic_var.get("ARROWSTT", 0) self.chance = dic_var.get("2CHANCE", True) if self.nArrowsTt != 0 and self.ayudas == 0: self.nArrowsTt = 0 self.with_takeback = dic_var.get("TAKEBACK", True) self.tutor_con_flechas = self.nArrowsTt > 0 and self.ayudas > 0 self.tutor_book = Books.BookGame(Code.tbook) mx = max(self.thoughtOp, self.thoughtTt) if mx > -1: self.alturaRotulo3(n_box_height) dr = dic_var["RIVAL"] rival = dr["CM"] if dr["TYPE"] == SelectEngines.ELO: r_t = 0 r_p = rival.fixed_depth self.nAjustarFuerza = ADJUST_BETTER else: r_t = dr["ENGINE_TIME"] * 100 # Se guarda en decimas -> milesimas r_p = dr["ENGINE_DEPTH"] self.nAjustarFuerza = dic_var.get("AJUSTAR", ADJUST_BETTER) 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_var["WITHTIME"]: r_t = 1000 self.xrival = self.procesador.creaGestorMotor( rival, r_t, r_p, self.nAjustarFuerza != ADJUST_BETTER) if self.nAjustarFuerza != ADJUST_BETTER: self.xrival.maximizaMultiPV() self.resign_limit = dic_var["RESIGN"] self.game.add_tag("Event", _("Play against an engine")) player = self.configuracion.nom_player() other = self.xrival.name w, b = (player, other) if self.is_human_side_white else (other, player) self.game.add_tag("White", w) self.game.add_tag("Black", b) self.siBookAjustarFuerza = self.nAjustarFuerza != ADJUST_BETTER self.xrival.is_white = self.is_engine_side_white self.siTiempo = dic_var["WITHTIME"] if self.siTiempo: self.maxSegundos = dic_var["MINUTES"] * 60.0 self.segundosJugada = dic_var["SECONDS"] self.segExtra = dic_var.get("MINEXTRA", 0) * 60.0 self.zeitnot = dic_var.get("ZEITNOT", 0) self.vtime = { WHITE: Util.Timer(self.maxSegundos), BLACK: Util.Timer(self.maxSegundos) } if self.segExtra: self.vtime[self.is_human_side_white].ponSegExtra(self.segExtra) time_control = "%d" % int(self.maxSegundos) if self.segundosJugada: time_control += "+%d" % self.segundosJugada self.game.add_tag("TimeControl", time_control) if self.segExtra: self.game.add_tag( "TimeExtra" + "White" if self.is_human_side_white else "Black", "%d" % self.segExtra) self.pon_toolbar() self.main_window.activaJuego(True, self.siTiempo) self.set_dispatcher(self.mueve_humano) self.setposition(self.game.last_position) self.mostrarIndicador(True) if self.ayudas_iniciales: self.ponAyudasEM() else: self.quitaAyudas(siQuitarAtras=False) self.ponPiezasAbajo(is_white) self.ponRotuloBasico() self.ponRotulo2("") if self.nAjustarFuerza != ADJUST_BETTER: pers = Personalidades.Personalidades(None, self.configuracion) label = pers.label(self.nAjustarFuerza) if label: self.game.add_tag("Strength", label) self.ponCapInfoPorDefecto() self.pgnRefresh(True) rival = self.xrival.name player = self.configuracion.x_player bl, ng = player, rival if self.is_engine_side_white: bl, ng = ng, bl active_clock = max(self.thoughtOp, self.thoughtTt) > -1 if self.siTiempo: tp_bl = self.vtime[True].etiqueta() tp_ng = self.vtime[False].etiqueta() self.main_window.ponDatosReloj(bl, tp_bl, ng, tp_ng) active_clock = True self.refresh() else: self.main_window.base.change_player_labels(bl, ng) if active_clock: self.main_window.start_clock(self.set_clock, 400) self.main_window.set_notify(self.mueve_rival_base) self.is_analyzed_by_tutor = False self.dgt_setposition()