def polyglot_install(self): list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() menu = QTVarios.LCMenu(self.main_window) for book in list_books.lista: if not Util.same_path(book.path, Code.tbook): menu.opcion(("x", book), book.name, Iconos.Delete()) menu.separador() menu.opcion(("n", None), _("Install new book"), Iconos.Nuevo()) resp = menu.lanza() if resp: orden, book = resp if orden == "x": if QTUtil2.pregunta(self.main_window, _("Do you want to delete %s?") % book.name): list_books.borra(book) list_books.save_pickle(self.configuration.file_books) elif orden == "n": fbin = QTUtil2.leeFichero(self.main_window, list_books.path, "bin", titulo=_("Polyglot book")) if fbin: list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] book = Books.Book("P", name, fbin, True) list_books.nuevo(book) list_books.save_pickle(self.configuration.file_books)
def seleccionaLibro(self): list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() menu = QTVarios.LCMenu(self) rondo = QTVarios.rondoPuntos() for book in list_books.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, list_books.path, "bin", titulo=_("Polyglot book")) if fbin: list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] book = Books.Book("P", name, fbin, True) list_books.nuevo(book) list_books.save_pickle(self.configuration.file_books) else: book = None return book
def __init__(self, manager, cromo): self.cromo = cromo self.manager = manager self.game = manager.game self.name = cromo.name self.xirina = None self.xsimilar = None conf_engine = self.manager.configuration.buscaRival("irina") self.xirina = EngineManager.EngineManager(self.manager.procesador, conf_engine) self.xirina.options(None, 1, False) self.opening = self.cromo.opening if self.opening: bookdef = Code.tbookPTZ name = os.path.basename(bookdef)[:-4] self.book = Books.Book("P", name, bookdef, True) self.book.polyglot() # De compatibilidad self.motorTiempoJugada = 0 self.motorProfundidad = 0 atexit.register(self.cerrar)
def nuevo(self): fbin = QTUtil2.leeFichero(self, self.list_books.path, "bin", titulo=_("Polyglot book")) if fbin: self.list_books.path = os.path.dirname(fbin) nombre = os.path.basename(fbin)[:-4] b = Books.Book("P", nombre, fbin, False) self.list_books.nuevo(b) self.rehacer_cb(b)
def aceptar(self): if not self.file: return # Creamos el pgn fichTemporal = self.w_parent.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.file] Util.remove_file(self.file) 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.file): txt += "\n" + _X(_("Book created : %1"), self.file) me.final() QTUtil2.message_bold(self, txt) Util.remove_file(fichTemporal) name = os.path.basename(self.file)[:-4] b = Books.Book("P", name, self.file, False) self.list_books.nuevo(b) fvar = self.configuration.file_books self.list_books.save_pickle(fvar) self.accept()
def eligeJugadaBookAjustada(self): if self.nAjustarFuerza < 1000: return False, None, None, None dicPersonalidad = self.configuration.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.Book("P", nombook, nombook, True) book.polyglot() return self.eligeJugadaBookBase(book, "pr")
def __init__(self, max_nivel, elo=None): if elo: si_ptz = elo < 1700 else: si_ptz = 1 <= max_nivel <= 2 self.file = Code.tbookPTZ if si_ptz else Code.tbook self.book = Books.Polyglot() self.activa = True self.max_level = max_nivel * 2 self.nivel_actual = 0 self.si_obligatoria = False
def importarPolyglot(self, game): list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() dicData = self.dbop.getconfig("IMPORT_POLYGLOT") bookW = list_books.lista[0] bookB = list_books.lista[0] if dicData: book = list_books.buscaLibro(dicData["BOOKW"]) if book: bookW = book book = list_books.buscaLibro(dicData["BOOKB"]) if book: bookB = book liGen = [FormLayout.separador] li = [(bookx.name, bookx) for bookx in list_books.lista] config = FormLayout.Combobox(_("Book that plays white side"), li) liGen.append((config, bookW)) liGen.append(FormLayout.separador) config = FormLayout.Combobox(_("Book that plays black side"), li) liGen.append((config, bookB)) liGen.append(FormLayout.separador) resultado = FormLayout.fedit(liGen, title=_("Polyglot book"), parent=self, anchoMinimo=360, icon=Iconos.Libros()) if resultado: accion, liResp = resultado bookW, bookB = liResp dicData = {"BOOKW": bookW.name, "BOOKB": bookB.name} self.dbop.setconfig("IMPORT_POLYGLOT", dicData) else: return bookW.polyglot() bookB.polyglot() titulo = bookW.name if bookW == bookB else "%s/%s" % (bookW.name, bookB.name) dicData = self.importarLeeParam(titulo) if dicData: depth, siWhite, onlyone, minMoves = (dicData["DEPTH"], dicData["SIWHITE"], dicData["ONLYONE"], dicData["MINMOVES"]) self.dbop.importarPolyglot(self, game, bookW, bookB, titulo, depth, siWhite, onlyone, minMoves) self.glines.refresh() self.glines.gotop()
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 import_polyglot(self, game): list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() dicData = self.dbop.getconfig("IMPORT_POLYGLOT") bookW = list_books.lista[0] bookB = list_books.lista[0] if dicData: book = list_books.buscaLibro(dicData["BOOKW"]) if book: bookW = book book = list_books.buscaLibro(dicData["BOOKB"]) if book: bookB = book form = FormLayout.FormLayout(self, _("Polyglot book"), Iconos.Libros(), anchoMinimo=360) form.separador() li = [(bookx.name, bookx) for bookx in list_books.lista] form.combobox(_("Book that plays white side"), li, bookW) form.separador() form.combobox(_("Book that plays black side"), li, bookB) form.separador() resultado = form.run() if resultado: accion, liResp = resultado bookW, bookB = liResp dicData = {"BOOKW": bookW.name, "BOOKB": bookB.name} self.dbop.setconfig("IMPORT_POLYGLOT", dicData) else: return bookW.polyglot() bookB.polyglot() titulo = bookW.name if bookW == bookB else "%s/%s" % (bookW.name, bookB.name) dicData = self.import_param_books(titulo, True) if dicData: depth, siWhite, onlyone, minMoves, excl_transpositions = ( dicData["DEPTH"], dicData["SIWHITE"], dicData["ONLYONE"], dicData["MINMOVES"], dicData["EXCLTRANSPOSITIONS"]) self.dbop.import_polyglot(self, game, bookW, bookB, titulo, depth, siWhite, onlyone, minMoves, excl_transpositions) self.glines.refresh() self.glines.gotop()
def nuevoBook(self): fbin = QTUtil2.leeFichero(self, self.list_books.path, "bin", titulo=_("Polyglot book")) if fbin: self.list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] b = Books.Book("P", name, fbin, False) self.list_books.nuevo(b) fvar = self.configuration.file_books self.list_books.save_pickle(fvar) li = [(x.name, x.path) for x in self.list_books.lista] li.insert(0, ("* " + _("Default"), "*")) self.cbBooks.rehacer(li, b.path)
def polyglot_install(self, list_books): fbin = QTUtil2.leeFichero(self, list_books.path, "bin", titulo=_("Polyglot book")) if fbin: list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] book = Books.Book("P", name, fbin, True) list_books.nuevo(book) list_books.save_pickle(self.configuration.file_books) num = self.kibitzers.nuevo_polyglot(book) self.goto(num)
def start(self, route): ManagerRoutes.start(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.Book("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.human_side = is_white self.is_engine_side_white = not is_white self.main_window.set_activate_tutor(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.remove_hints(True) self.set_label1(self.engine.label) if self.must_win: self.set_label2(_("You must win to pass this game")) self.set_dispatcher(self.player_has_moved) self.set_position(self.game.last_position) self.show_side_indicator(True) self.put_pieces_bottom(is_white) self.pgnRefresh(True) QTUtil.refresh_gui() self.check_boards_setposition() self.play_next_move()
def nuevo(self): menu = QTVarios.LCMenu(self) menu.opcion(("engine", None), _("Engine"), Iconos.Motor()) menu.separador() submenu = menu.submenu(_("Polyglot book"), Iconos.Book()) list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() rondo = QTVarios.rondoPuntos() for book in list_books.lista: submenu.opcion(("book", book), book.name, rondo.otro()) submenu.separador() submenu.opcion(("installbook", None), _("Install new book"), Iconos.Nuevo()) menu.separador() si_gaviota = True si_index = True for kib in self.kibitzers.lista: if kib.tipo == Kibitzers.KIB_GAVIOTA: si_gaviota = False elif kib.tipo == Kibitzers.KIB_INDEXES: si_index = False if si_index: menu.opcion(("index", None), _("Indexes") + " - RodentII", Iconos.Camara()) menu.separador() if si_gaviota: menu.opcion(("gaviota", None), _("Gaviota Tablebases"), Iconos.Finales()) resp = menu.lanza() if resp: orden, extra = resp if orden == "engine": self.nuevo_engine() elif orden in "book": num = self.kibitzers.nuevo_polyglot(extra) self.goto(num) elif orden == "gaviota": num = self.kibitzers.nuevo_gaviota() self.goto(num) elif orden == "index": num = self.kibitzers.nuevo_index() self.goto(num) elif orden in "installbook": self.polyglot_install(list_books)
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.list_books.path, "bin", titulo=_("Polyglot book")) if fbin: self.list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] b = Books.Book("P", name, fbin, False) self.list_books.nuevo(b) fvar = self.configuration.file_books self.list_books.save_pickle(fvar) li = [(x.name, x) for x in self.list_books.lista] book_R = self.cbBooksR.valor() book_P = self.cbBooksP.valor() sender = self.sender() self.cbBooksR.rehacer(li, b if sender == self.btNuevoBookR else book_R) self.cbBooksP.rehacer(li, b if sender == self.btNuevoBookP else book_P)
def __init__(self, cpu): WKibCommon.WKibCommon.__init__(self, cpu, Iconos.Book()) self.book = Books.Book("P", cpu.kibitzer.name, cpu.kibitzer.path_exe, True) self.book.polyglot() o_columns = Columnas.ListaColumnas() delegado = Delegados.EtiquetaPOS( True, siLineas=False) if self.with_figurines 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 = Grid.Grid(self, o_columns, dicVideo=self.dicVideo, siSelecFilas=True) li_acciones = ( (_("Quit"), Iconos.Kibitzer_Close(), self.terminar), (_("Continue"), Iconos.Kibitzer_Play(), self.play), (_("Pause"), Iconos.Kibitzer_Pause(), self.pause), (_("Takeback"), Iconos.pmKibitzer_Back(), self.takeback), (_("Manual position"), Iconos.Kibitzer_Voyager(), self.set_position), (_("Show/hide board"), Iconos.Kibitzer_Board(), self.config_board), ("%s: %s" % (_("Enable"), _("window on top")), Iconos.Kibitzer_Up(), self.windowTop), ("%s: %s" % (_("Disable"), _("window on top")), Iconos.Kibitzer_Down(), self.windowBottom), ) self.tb = Controles.TBrutina(self, li_acciones, with_text=False, icon_size=24) self.tb.setAccionVisible(self.play, False) ly1 = Colocacion.H().control(self.board).control(self.grid) layout = Colocacion.V().control( self.tb).espacio(-8).otro(ly1).margen(3) self.setLayout(layout) self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.cpu.compruebaInput) self.timer.start(500) self.restore_video(self.dicVideo) self.ponFlags()
def __init__(self, w_parent): QtWidgets.QDialog.__init__(self, w_parent) self.w_parent = w_parent self.file = "" self.setWindowTitle(_("Create a new book")) self.setWindowIcon(Iconos.Libros()) self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint) f = Controles.TipoLetra(puntos=9, peso=75) self.configuration = Code.configuration fvar = self.configuration.file_books self.list_books = Books.ListBooks() self.list_books.restore_pickle(fvar) lbFichero = Controles.LB(self, _("Book to create") + ":").ponFuente(f) self.btFichero = Controles.PB(self, "", self.buscaFichero, False).anchoMinimo(450).ponFuente(f) lbMaxPly = Controles.LB(self, _("Maximum no. half moves (ply)") + ":").ponFuente(f) self.sbMaxPly = Controles.SB(self, 0, 0, 999).tamMaximo(50) lbMinGame = Controles.LB(self, _("Minimum number of games") + ":").ponFuente(f) self.sbMinGame = Controles.SB(self, 3, 1, 999).tamMaximo(50) lbMinScore = Controles.LB(self, _("Minimum score") + ":").ponFuente(f) self.sbMinScore = Controles.SB(self, 0, 0, 100).tamMaximo(50) self.chbOnlyWhite = Controles.CHB(self, _("White only"), False).ponFuente(f) self.chbOnlyBlack = Controles.CHB(self, _("Black only"), False).ponFuente(f) self.chbUniform = Controles.CHB(self, _("Uniform distribution"), False).ponFuente(f) lyf = Colocacion.H().control(lbFichero).control(self.btFichero) ly = Colocacion.G().margen(15) ly.otroc(lyf, 0, 0, 1, 2) ly.controld(lbMaxPly, 1, 0).control(self.sbMaxPly, 1, 1) ly.controld(lbMinGame, 2, 0).control(self.sbMinGame, 2, 1) ly.controld(lbMinScore, 3, 0).control(self.sbMinScore, 3, 1) ly.controlc(self.chbOnlyWhite, 4, 0, 1, 2) ly.controlc(self.chbOnlyBlack, 5, 0, 1, 2) ly.controlc(self.chbUniform, 6, 0, 1, 2) # Toolbar li_acciones = [(_("Accept"), Iconos.Aceptar(), "aceptar"), None, (_("Cancel"), Iconos.Cancelar(), "cancelar"), None] tb = Controles.TB(self, li_acciones) # Layout layout = Colocacion.V().control(tb).otro(ly).margen(3) self.setLayout(layout)
def __init__(self, manager, siEnVivo): titulo = _("Consult a book") icono = Iconos.Libros() extparam = "treebook" QTVarios.WDialogo.__init__(self, manager.main_window, titulo, icono, extparam) # Se lee la lista de libros1 self.list_books = Books.ListBooks() self.fvar = manager.configuration.file_books self.list_books.restore_pickle(self.fvar) # Comprobamos que todos esten accesibles self.list_books.check() self.book = self.list_books.porDefecto() # fens fenActivo = manager.fenActivoConInicio() # Posicion en el board fenUltimo = manager.last_fen() self.siEnviar = siEnVivo and (fenActivo == fenUltimo) self.listaMoves = ListaMoves(None, self.book, fenActivo) self.infoMove = InfoMove(manager.board.is_white_bottom, fenActivo) self.wmoves = WMoves(self, self.siEnviar) self.splitter = splitter = QtWidgets.QSplitter(self) splitter.addWidget(self.infoMove) splitter.addWidget(self.wmoves) ly = Colocacion.H().control(splitter).margen(0) self.setLayout(ly) self.wmoves.tree.setFocus() anchoBoard = self.infoMove.board.width() self.resize(600 - 278 + anchoBoard, anchoBoard + 30) self.splitter.setSizes([296 - 278 + anchoBoard, 290]) for col, ancho in enumerate((100, 59, 87, 0, 38)): self.wmoves.tree.setColumnWidth(col, ancho) self.ponTitulo(self.book)
def menuLibros(self): menu = QTVarios.LCMenu(self) nBooks = len(self.list_books.lista) for book in self.list_books.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.list_books.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.list_books.path, "bin", titulo=_("Polyglot book")) if fbin: self.list_books.path = os.path.dirname(fbin) name = os.path.basename(fbin)[:-4] book = Books.Book("P", name, fbin, True) self.list_books.nuevo(book) self.cambiaLibro(book) elif orden == "b": self.list_books.borra(book) self.list_books.save_pickle(self.fvar) elif orden == "1": self.buscaSiguiente()
def __init__(self, name, exe, liOpcionesUCI=None, nMultiPV=0, priority=None, args=None): RunEngine.__init__(self, name, exe, liOpcionesUCI, nMultiPV, priority, args) self.stopping = False level = int(name[5:]) book_name = "1100-1500.bin" if level <= 1500 else "1600-1900.bin" book_path = os.path.join(os.path.dirname(exe), book_name) self.book = Books.Book("P", book_name, book_path, True) self.book.polyglot() self.book_select = [] mp = (level - 1100) // 10 ap = 40 - 20 * (level - 1100) // 800 au = 100 - mp - ap self.book_select.extend(["mp"] * mp) self.book_select.extend(["ap"] * ap) self.book_select.extend(["au"] * au)
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.human_side = 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 = Opening.JuegaOpening( 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("TYPE", None) in (SelectEngines.MICGM, SelectEngines.MICPER): if self.conf_engine.book: self.bookR = Books.Book("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.configuration.x_default_tutor_active self.main_window.set_activate_tutor(self.is_tutor_enabled) self.hints = dic_var["HINTS"] self.ayudas_iniciales = self.hints # 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 = not Code.configuration.x_engine_notbackground self.nArrowsTt = dic_var.get("ARROWSTT", 0) self.chance = dic_var.get("2CHANCE", True) if self.nArrowsTt != 0 and self.hints == 0: self.nArrowsTt = 0 self.with_takeback = dic_var.get("TAKEBACK", True) self.tutor_con_flechas = self.nArrowsTt > 0 and self.hints > 0 self.tutor_book = Books.BookGame(Code.tbook) mx = max(self.thoughtOp, self.thoughtTt) if mx > -1: self.set_hight_label3(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("ADJUST", 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.creaManagerMotor( 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.set_tag("Event", _("Play against an engine")) player = self.configuration.nom_player() other = self.xrival.name w, b = (player, other) if self.human_side else (other, player) self.game.set_tag("White", w) self.game.set_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.human_side].ponSegExtra(self.segExtra) time_control = "%d" % int(self.maxSegundos) if self.segundosJugada: time_control += "+%d" % self.segundosJugada self.game.set_tag("TimeControl", time_control) if self.segExtra: self.game.set_tag( "TimeExtra" + "White" if self.human_side else "Black", "%d" % self.segExtra) self.pon_toolbar() self.main_window.activaJuego(True, self.siTiempo) self.set_dispatcher(self.player_has_moved) self.set_position(self.game.last_position) self.show_side_indicator(True) if self.ayudas_iniciales: self.ponAyudasEM() else: self.remove_hints(siQuitarAtras=False) self.put_pieces_bottom(is_white) self.ponRotuloBasico() self.set_label2("") if self.nAjustarFuerza != ADJUST_BETTER: pers = Personalities.Personalities(None, self.configuration) label = pers.label(self.nAjustarFuerza) if label: self.game.set_tag("Strength", label) self.ponCapInfoPorDefecto() self.pgnRefresh(True) rival = self.xrival.name player = self.configuration.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.game.tag_timestart() self.check_boards_setposition()
def __init__(self, procesador, titulo, save_at_end): QTVarios.WDialogo.__init__(self, procesador.main_window, titulo, Iconos.Libre(), "entMaquina") font = Controles.TipoLetra(puntos=procesador.configuracion.x_menu_points) self.save_at_end = save_at_end self.setFont(font) self.configuracion = procesador.configuracion self.procesador = procesador self.personalidades = Personalidades.Personalidades(self, self.configuracion) self.motores = SelectEngines.SelectEngines(self.configuracion) # Toolbar li_acciones = [ (_("Accept"), Iconos.Aceptar(), self.aceptar), None, (_("Cancel"), Iconos.Cancelar(), self.cancelar), None, (_("Configurations"), Iconos.Configurar(), self.configuraciones), None, ] tb = QTVarios.LCTB(self, li_acciones) # Tab tab = Controles.Tab() tab.dispatchChange(self.cambiada_tab) self.tab_advanced = 4 # está en la posición 4 self.tab_advanced_active = ( False ) # Para no tener que leer las opciones uci to_sq que no sean necesarias, afecta a gridNumDatos def nueva_tab(layout, titulo): ly = Colocacion.V() ly.otro(layout) ly.relleno() w = QtWidgets.QWidget(self) w.setLayout(ly) w.setFont(font) tab.nuevaTab(w, titulo) def nuevoG(): ly_g = Colocacion.G() ly_g.filaActual = 0 ly_g.setMargin(10) return ly_g gbStyle = """ QGroupBox { font: bold 16px; background-color: #F2F2EC;/*qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF);*/ border: 1px solid gray; border-radius: 3px; padding: 18px; margin-top: 5ex; /* leave space at the top for the title */ } QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; /* position at the top center */ padding: 8px; border: 1px solid gray; } """ def _label(ly_g, txt, xlayout, rutinaCHB=None, siCheck: object = False): groupbox = Controles.GB(self, txt, xlayout) if rutinaCHB: groupbox.conectar(rutinaCHB) elif siCheck: groupbox.setCheckable(True) groupbox.setChecked(False) groupbox.setStyleSheet(gbStyle) groupbox.setMinimumWidth(640) groupbox.setFont(font) ly_g.controlc(groupbox, ly_g.filaActual, 0) ly_g.filaActual += 1 return groupbox # ################################################################################################################################## # TAB General # ################################################################################################################################## lyG = nuevoG() # # Motores # ## Rival self.rival = self.procesador.XTutor().confMotor self.rivalTipo = SelectEngines.INTERNO self.btRival = Controles.PB(self, "", self.cambiaRival, plano=False).ponFuente(font).altoFijo(48) lbTiempoSegundosR = Controles.LB2P(self, _("Fixed time in seconds")).ponFuente(font) self.edRtiempo = ( Controles.ED(self).tipoFloat().anchoMaximo(50).ponFuente(font).capturaCambiado(self.cambiadoTiempo) ) bt_cancelar_tiempo = Controles.PB(self, "", rutina=self.cancelar_tiempo).ponIcono(Iconos.S_Cancelar()) ly_tiempo = Colocacion.H().control(self.edRtiempo).control(bt_cancelar_tiempo).relleno(1) lb_depth = Controles.LB2P(self, _("Fixed depth")).ponFuente(font) self.edRdepth = Controles.ED(self).tipoInt().anchoMaximo(50).ponFuente(font).capturaCambiado(self.cambiadoDepth) bt_cancelar_depth = Controles.PB(self, "", rutina=self.cancelar_depth).ponIcono(Iconos.S_Cancelar()) ly_depth = Colocacion.H().control(self.edRdepth).control(bt_cancelar_depth).relleno(1) ly = Colocacion.G() ly.controld(lbTiempoSegundosR, 0, 0).otro(ly_tiempo, 0, 1) ly.controld(lb_depth, 1, 0).otro(ly_depth, 1, 1) self.gb_thinks = Controles.GB(self, _("Limits of engine thinking"), ly) self.gb_thinks.setStyleSheet( """ QGroupBox { font: bold %d; background-color: #F2F2EC;/*qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF);*/ border: 1px solid gray; border-radius: 3px; padding: 18px; margin-top: 5ex; /* leave space at the top for the title */ } QGroupBox::title { subcontrol-position: top center; /* position at the top center */ padding: 8px; border: 1px solid gray; } """ % procesador.configuracion.x_menu_points ) lyV = Colocacion.V().espacio(20).control(self.btRival).espacio(20).control(self.gb_thinks) _label(lyG, _("Opponent"), lyV) # # Color self.rbBlancas = Controles.RB(self, "").activa() self.rbBlancas.setIcon(Iconos.PeonBlanco()) self.rbBlancas.setIconSize(QtCore.QSize(32, 32)) self.rbNegras = Controles.RB(self, "") self.rbNegras.setIcon(Iconos.PeonNegro()) self.rbNegras.setIconSize(QtCore.QSize(32, 32)) self.rbRandom = Controles.RB(self, _("Random")) self.rbRandom.setFont(Controles.TipoLetra(puntos=16)) hbox = ( Colocacion.H() .relleno() .control(self.rbBlancas) .espacio(30) .control(self.rbNegras) .espacio(30) .control(self.rbRandom) .relleno() ) _label(lyG, _("Side you play with"), hbox) nueva_tab(lyG, _("Basic configuration")) # ################################################################################################################################## # TAB Ayudas # ################################################################################################################################## self.chbSummary = Controles.CHB( self, _("Save a summary when the game is finished in the main comment"), False ).ponFuente(font) self.chbTakeback = Controles.CHB( self, _("Option takeback activated"), True ).ponFuente(font) # # Tutor lbAyudas = Controles.LB2P(self, _("Available hints")).ponFuente(font) liAyudas = [(_("Maximum"), 999)] for i in range(1, 21): liAyudas.append((str(i), i)) for i in range(25, 51, 5): liAyudas.append((str(i), i)) self.cbAyudas = Controles.CB(self, liAyudas, 999).ponFuente(font) self.chbChance = Controles.CHB(self, _("Second chance"), True).ponFuente(font) btTutorChange = ( Controles.PB(self, _("Tutor change"), self.tutorChange, plano=False) .ponIcono(Iconos.Tutor(), tamIcon=16) .ponFuente(font) ) liThinks = [(_("Nothing"), -1), (_("Score"), 0)] for i in range(1, 5): liThinks.append(("%d %s" % (i, _("ply") if i == 1 else _("plies")), i)) liThinks.append((_("All"), 9999)) lbThoughtTt = Controles.LB(self, _("It is showed") + ":").ponFuente(font) self.cbThoughtTt = Controles.CB(self, liThinks, -1).ponFuente(font) self.chbContinueTt = Controles.CHB(self, _("The tutor thinks while you think"), True).ponFuente(font) lbBoxHeight = Controles.LB2P(self, _("Box height")).ponFuente(font) self.sbBoxHeight = Controles.SB(self, 7, 0, 999).tamMaximo(50).ponFuente(font) lbArrows = Controles.LB2P(self, _("Arrows with the best moves")).ponFuente(font) self.sbArrowsTt = Controles.SB(self, 3, 0, 999).tamMaximo(50).ponFuente(font) lyT1 = Colocacion.H().control(lbAyudas).control(self.cbAyudas).relleno() lyT1.control(self.chbChance).relleno().control(btTutorChange) lyT2 = Colocacion.H().control(self.chbContinueTt).relleno() lyT2.control(lbBoxHeight).control(self.sbBoxHeight).relleno() lyT3 = Colocacion.H().control(lbThoughtTt).control(self.cbThoughtTt).relleno() lyT3.control(lbArrows).control(self.sbArrowsTt) ly = Colocacion.V().otro(lyT1).espacio(16).otro(lyT2).otro(lyT3).relleno() self.gbTutor = Controles.GB(self, _("Activate the tutor's help"), ly) self.gbTutor.setCheckable(True) self.gbTutor.setStyleSheet(gbStyle) lb = Controles.LB(self, _("It is showed") + ":").ponFuente(font) self.cbThoughtOp = Controles.CB(self, liThinks, -1).ponFuente(font) lbArrows = Controles.LB2P(self, _("Arrows to show")).ponFuente(font) self.sbArrows = Controles.SB(self, 7, 0, 999).tamMaximo(50).ponFuente(font) ly = Colocacion.H().control(lb).control(self.cbThoughtOp).relleno() ly.control(lbArrows).control(self.sbArrows).relleno() gbThoughtOp = Controles.GB(self, _("Opponent's thought information"), ly) gbThoughtOp.setStyleSheet(gbStyle) ly = Colocacion.V().espacio(16).control(self.gbTutor).control(gbThoughtOp) ly.espacio(16).control(self.chbSummary).control(self.chbTakeback).margen(6) nueva_tab(ly, _("Help configuration")) # ################################################################################################################################## # TAB Tiempo # ################################################################################################################################## lyG = nuevoG() self.lbMinutos = Controles.LB(self, _("Total minutes") + ":").ponFuente(font) self.edMinutos = Controles.ED(self).tipoFloat(10.0).ponFuente(font).anchoFijo(50) self.edSegundos, self.lbSegundos = QTUtil2.spinBoxLB( self, 6, -999, 999, maxTam=54, etiqueta=_("Seconds added per move"), fuente=font ) self.edMinExtra, self.lbMinExtra = QTUtil2.spinBoxLB( self, 0, -999, 999, maxTam=70, etiqueta=_("Extra minutes for the player"), fuente=font ) self.edZeitnot, self.lbZeitnot = QTUtil2.spinBoxLB( self, 0, -999, 999, maxTam=54, etiqueta=_("Zeitnot: alarm sounds when remaining seconds"), fuente=font ) lyH = Colocacion.H() lyH.control(self.lbMinutos).control(self.edMinutos).espacio(30) lyH.control(self.lbSegundos).control(self.edSegundos).relleno() lyH2 = Colocacion.H() lyH2.control(self.lbMinExtra).control(self.edMinExtra).relleno() lyH3 = Colocacion.H() lyH3.control(self.lbZeitnot).control(self.edZeitnot).relleno() ly = Colocacion.V().otro(lyH).otro(lyH2).otro(lyH3) self.chbTiempo = _label(lyG, _("Activate the time control"), ly, siCheck=True) nueva_tab(lyG, _("Time")) # ################################################################################################################################## # TAB Initial moves # ################################################################################################################################## lyG = nuevoG() # Posicion self.btPosicion = ( Controles.PB(self, " " * 5 + _("Change") + " " * 5, self.posicionEditar).ponPlano(False).ponFuente(font) ) self.fen = "" self.btPosicionQuitar = Controles.PB(self, "", self.posicionQuitar).ponIcono(Iconos.Motor_No()).ponFuente(font) self.btPosicionPegar = ( Controles.PB(self, "", self.posicionPegar).ponIcono(Iconos.Pegar16()).ponToolTip(_("Paste FEN position")) ).ponFuente(font) hbox = ( Colocacion.H() .relleno() .control(self.btPosicionQuitar) .control(self.btPosicion) .control(self.btPosicionPegar) .relleno() ) _label(lyG, _("Start position"), hbox) # Aperturas self.btApertura = ( Controles.PB(self, " " * 5 + _("Undetermined") + " " * 5, self.editarApertura) .ponPlano(False) .ponFuente(font) ) self.bloqueApertura = None self.btAperturasFavoritas = Controles.PB(self, "", self.aperturasFavoritas).ponIcono(Iconos.Favoritos()) self.btAperturasQuitar = Controles.PB(self, "", self.aperturasQuitar).ponIcono(Iconos.Motor_No()) hbox = ( Colocacion.H() .relleno() .control(self.btAperturasQuitar) .control(self.btApertura) .control(self.btAperturasFavoritas) .relleno() ) _label(lyG, _("Opening"), hbox) # Libros fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.restore_pickle(fvar) self.listaLibros.comprueba() li_books = [(x.name, x) for x in self.listaLibros.lista] libInicial = li_books[0][1] if li_books else None li_resp_book = [ (_("Selected by the player"), "su"), (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp"), ] ## Rival self.cbBooksR = QTUtil2.comboBoxLB(self, li_books, libInicial).ponFuente(font) self.btNuevoBookR = Controles.PB(self, "", self.nuevoBook, plano=True).ponIcono(Iconos.Mas(), tamIcon=16) self.cbBooksRR = QTUtil2.comboBoxLB(self, li_resp_book, "mp").ponFuente(font) self.lbDepthBookR = Controles.LB2P(self, _("Max depth")).ponFuente(font) self.edDepthBookR = Controles.ED(self).ponFuente(font).tipoInt(0).anchoFijo(30) hbox = ( Colocacion.H() .control(self.cbBooksR) .control(self.btNuevoBookR) .relleno() .control(self.cbBooksRR) .relleno() .control(self.lbDepthBookR) .control(self.edDepthBookR) ) self.chbBookR = _label(lyG, "%s: %s" % (_("Activate book"), _("Opponent")), hbox, siCheck=True) ## Player self.cbBooksP = QTUtil2.comboBoxLB(self, li_books, libInicial).ponFuente(font) self.btNuevoBookP = Controles.PB(self, "", self.nuevoBook, plano=True).ponIcono(Iconos.Mas(), tamIcon=16) self.lbDepthBookP = Controles.LB2P(self, _("Max depth")).ponFuente(font) self.edDepthBookP = Controles.ED(self).ponFuente(font).tipoInt(0).anchoFijo(30) hbox = ( Colocacion.H() .control(self.cbBooksP) .control(self.btNuevoBookP) .relleno() .control(self.lbDepthBookP) .control(self.edDepthBookP) ) self.chbBookP = _label( lyG, "%s: %s" % (_("Activate book"), self.configuracion.nom_player()), hbox, siCheck=True ) nueva_tab(lyG, _("Initial moves")) # ################################################################################################################################## # TAB avanzada # ################################################################################################################################## lyG = nuevoG() liAjustes = self.personalidades.listaAjustes(True) self.cbAjustarRival = ( Controles.CB(self, liAjustes, ADJUST_BETTER).capturaCambiado(self.ajustesCambiado).ponFuente(font) ) lbAjustarRival = Controles.LB2P(self, _("Set strength")).ponFuente(font) self.btAjustarRival = ( Controles.PB(self, _("Personality"), self.cambiaPersonalidades, plano=True) .ponIcono(Iconos.Mas(), tamIcon=16) .ponFuente(font) ) # ## Resign lbResign = Controles.LB2P(self, _("Resign/draw by engine")).ponFuente(font) liResign = ( (_("Very early"), -100), (_("Early"), -300), (_("Average"), -500), (_("Late"), -800), (_("Very late"), -1000), (_("Never"), -9999999), ) self.cbResign = Controles.CB(self, liResign, -800).ponFuente(font) self.lb_path_engine = Controles.LB(self, "").ponWrap() o_columns = Columnas.ListaColumnas() o_columns.nueva("OPTION", _("UCI option"), 240, centered=True) o_columns.nueva("VALUE", _("Value"), 200, centered=True, edicion=Delegados.MultiEditor(self)) self.grid_uci = Grid.Grid(self, o_columns, siEditable=True) self.grid_uci.ponFuente(font) self.register_grid(self.grid_uci) lyH2 = ( Colocacion.H().control(lbAjustarRival).control(self.cbAjustarRival).control(self.btAjustarRival).relleno() ) lyH3 = Colocacion.H().control(lbResign).control(self.cbResign).relleno() ly = Colocacion.V().otro(lyH2).otro(lyH3).espacio(16).control(self.lb_path_engine).control(self.grid_uci) _label(lyG, _("Opponent"), ly) nueva_tab(lyG, _("Advanced")) layout = Colocacion.V().control(tb).control(tab).relleno().margen(3) self.setLayout(layout) self.liAperturasFavoritas = [] self.btAperturasFavoritas.hide() dic = Util.restore_pickle(self.configuracion.ficheroEntMaquina) if not dic: dic = {} self.restore_dic(dic) self.ajustesCambiado() # self.ayudasCambiado() self.ponRival() self.restore_video()
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.show_board = dicVideo.get("SHOW_BOARD", True) self.position = Position.Position() self.game = None 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.configuration = cpu.configuration Code.todasPiezas = Piezas.TodasPiezas() config_board = cpu.configuration.config_board( "kib" + cpu.kibitzer.huella, 24) self.board = Board.Board(self, config_board) self.board.crea() self.board.set_dispatcher(self.mensajero) Delegados.generaPM(self.board.piezas) self.book = Books.Book("P", cpu.kibitzer.name, cpu.kibitzer.path_exe, True) self.book.polyglot() self.with_figurines = cpu.configuration.x_pgn_withfigurines o_columns = Columnas.ListaColumnas() delegado = Delegados.EtiquetaPOS( True, siLineas=False) if self.with_figurines 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_Close(), self.terminar), (_("Continue"), Iconos.Kibitzer_Play(), self.play), (_("Pause"), Iconos.Kibitzer_Pause(), self.pause), (_("Takeback"), Iconos.pmKibitzer_Back(), self.takeback), (_("Manual position"), Iconos.Kibitzer_Voyager(), self.set_position), (_("Show/hide board"), Iconos.Kibitzer_Board(), 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, with_text=False, icon_size=24) self.tb.setAccionVisible(self.play, False) ly1 = Colocacion.H().control(self.board).control(self.grid_moves) layout = Colocacion.V().control( self.tb).espacio(-8).otro(ly1).margen(3) self.setLayout(layout) self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.cpu.compruebaInput) self.timer.start(500) if not self.show_board: self.board.hide() self.restore_video(dicVideo) self.ponFlags()
def __init__(self, procesador): self.configuration = procesador.configuration self.procesador = procesador self.db_histo = UtilSQL.DictSQL(self.configuration.ficheroGMhisto) self.opening_block = None self.li_preferred_openings = [] w_parent = procesador.main_window titulo = _("Play like a Grandmaster") icono = Iconos.GranMaestro() extparam = "gm" QTVarios.WDialogo.__init__(self, w_parent, titulo, icono, extparam) flb = Controles.TipoLetra(puntos=procesador.configuration.x_menu_points) # Toolbar li_acciones = [ (_("Accept"), Iconos.Aceptar(), self.aceptar), None, (_("Cancel"), Iconos.Cancelar(), self.cancelar), None, (_("One game"), Iconos.Uno(), self.unJuego), None, (_("Import"), Iconos.ImportarGM(), self.importar), ] tb = Controles.TBrutina(self, li_acciones) # Grandes maestros self.li_gm = GM.lista_gm() gb_style = Common.gb_style() li = [(x[0], x[1]) for x in self.li_gm] li.insert(0, ("-", None)) self.cb_gm = QTUtil2.comboBoxLB(self, li, li[0][1] if len(self.li_gm) == 0 else li[1][1]) self.cb_gm.capture_changes(self.check_gm) hbox = Colocacion.H().relleno().control(self.cb_gm).relleno() gbGM = Controles.GB(self, _("Choose a Grandmaster"), hbox).ponFuente(flb) gbGM.setStyleSheet(gb_style) # Personales self.li_personal = GM.lista_gm_personal(self.procesador.configuration.personal_training_folder) if self.li_personal: li = [(x[0], x[1]) for x in self.li_personal] li.insert(0, ("-", None)) self.cbPersonal = QTUtil2.comboBoxLB(self, li, li[0][1]) self.cbPersonal.capture_changes(self.check_personal) btBorrar = Controles.PB(self, "", self.borrarPersonal).ponIcono(Iconos.Borrar(), icon_size=24) hbox = Colocacion.H().relleno().control(self.cbPersonal).control(btBorrar).relleno() gb_personal = Controles.GB(self, _("Personal games"), hbox).ponFuente(flb) gb_personal.setStyleSheet(gb_style) # Color self.rb_white = Controles.RB(self, _("White"), rutina=self.check_color) self.rb_white.setFont(flb) self.rb_white.activa(True) self.rb_black = Controles.RB(self, _("Black"), rutina=self.check_color) self.rb_black.setFont(flb) self.rb_black.activa(False) # Contrario self.chContrario = Controles.CHB(self, _("Choose the opponent's move, when there are multiple possible answers"), False) # Juez liDepths = [("--", 0)] for x in range(1, 31): liDepths.append((str(x), x)) self.liMotores = self.configuration.comboMotoresMultiPV10() self.cbJmotor, self.lbJmotor = QTUtil2.comboBoxLB(self, self.liMotores, self.configuration.tutor_inicial, _("Engine")) self.edJtiempo = Controles.ED(self).tipoFloat().ponFloat(1.0).anchoFijo(50) self.lbJtiempo = Controles.LB2P(self, _("Time in seconds")) self.cbJdepth = Controles.CB(self, liDepths, 0).capture_changes(self.change_depth) self.lbJdepth = Controles.LB2P(self, _("Depth")) self.lbJshow = Controles.LB2P(self, _("Show rating")) self.chbEvals = Controles.CHB(self, _("Show all evaluations"), False) li_options = [(_("All moves"), None), (_("Moves are different"), True), (_("Never"), False)] self.cbJshow = Controles.CB(self, li_options, True) self.lbJmultiPV = Controles.LB2P(self, _("Number of moves evaluated by engine(MultiPV)")) li = [(_("Default"), "PD"), (_("Maximum"), "MX")] for x in (1, 3, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200): li.append((str(x), str(x))) self.cbJmultiPV = Controles.CB(self, li, "PD") self.li_adjudicator_controls = ( self.cbJmotor, self.lbJmotor, self.edJtiempo, self.lbJtiempo, self.lbJdepth, self.cbJdepth, self.lbJshow, self.cbJshow, self.lbJmultiPV, self.cbJmultiPV, self.chbEvals, ) for control in self.li_adjudicator_controls: control.setFont(flb) # Inicial self.edJugInicial, lbInicial = QTUtil2.spinBoxLB(self, 1, 1, 99, etiqueta=_("Initial move"), maxTam=40) # Libros fvar = self.configuration.file_books self.list_books = Books.ListBooks() self.list_books.restore_pickle(fvar) # # Comprobamos que todos esten accesibles self.list_books.check() li = [(x.name, x) for x in self.list_books.lista] li.insert(0, ("--", None)) self.cbBooks, lbBooks = QTUtil2.comboBoxLB(self, li, None, _("Bypass moves in the book")) # Openings self.btOpening = Controles.PB(self, " " * 5 + _("Undetermined") + " " * 5, self.aperturasEditar).ponPlano(False) self.btOpeningsFavoritas = Controles.PB(self, "", self.preferred_openings).ponIcono(Iconos.Favoritos()) self.btOpeningsQuitar = Controles.PB(self, "", self.aperturasQuitar).ponIcono(Iconos.Motor_No()) hbox = Colocacion.H().control(self.btOpeningsQuitar).control(self.btOpening).control(self.btOpeningsFavoritas).relleno() gbOpening = Controles.GB(self, _("Opening"), hbox) # gbBasic # # Color hbox = Colocacion.H().relleno().control(self.rb_white).espacio(10).control(self.rb_black).relleno() gbColor = Controles.GB(self, _("Play with"), hbox).ponFuente(flb) gbColor.setStyleSheet(gb_style) # Tiempo ly1 = Colocacion.H().control(self.lbJmotor).control(self.cbJmotor).relleno().control(self.lbJshow).control(self.cbJshow) ly2 = Colocacion.H().control(self.lbJtiempo).control(self.edJtiempo) ly2.control(self.lbJdepth).control(self.cbJdepth).relleno().control(self.chbEvals) ly3 = Colocacion.H().control(self.lbJmultiPV).control(self.cbJmultiPV).relleno() ly = Colocacion.V().otro(ly1).otro(ly2).otro(ly3) self.gbJ = Controles.GB(self, _("Adjudicator"), ly).to_connect(self.change_adjudicator) self.gbJ.setStyleSheet(gb_style) # Opciones vlayout = Colocacion.V().control(gbColor) vlayout.espacio(5).control(self.gbJ) vlayout.margen(20) gbBasic = Controles.GB(self, "", vlayout) gbBasic.setFlat(True) # Opciones avanzadas lyInicial = Colocacion.H().control(lbInicial).control(self.edJugInicial).relleno().control(lbBooks).control(self.cbBooks).relleno() vlayout = Colocacion.V().otro(lyInicial).control(gbOpening) vlayout.espacio(5).control(self.chContrario).margen(20).relleno() gbAdvanced = Controles.GB(self, "", vlayout) gbAdvanced.setFlat(True) # Historico self.liHisto = [] o_columns = Columnas.ListaColumnas() o_columns.nueva("FECHA", _("Date"), 100, centered=True) o_columns.nueva("PACIERTOS", _("Hints"), 90, centered=True) o_columns.nueva("PUNTOS", _("Points accumulated"), 140, centered=True) o_columns.nueva("ENGINE", _("Adjudicator"), 100, centered=True) o_columns.nueva("RESUMEN", _("Game played"), 280) self.grid = grid = Grid.Grid(self, o_columns, siSelecFilas=True, background=None) self.grid.coloresAlternados() self.register_grid(grid) # Tabs self.tab = Controles.Tab().set_position("S") self.tab.nuevaTab(gbBasic, _("Basic")) self.tab.nuevaTab(gbAdvanced, _("Advanced")) self.tab.nuevaTab(self.grid, _("Track record")) self.tab.setFont(flb) # Cabecera lyCab = Colocacion.H().control(gbGM) if self.li_personal: lyCab.control(gb_personal) layout = Colocacion.V().control(tb).otro(lyCab).control(self.tab).margen(6) self.setLayout(layout) self.restore_dic() self.change_adjudicator() self.check_gm() self.check_personal() self.check_histo() self.aperturaMuestra() self.btOpeningsFavoritas.hide() self.restore_video(anchoDefecto=750)
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 reinicio(self, dbop): self.dbop = dbop self.dbop.open_cache_engines() self.game_type = GT_OPENING_LINES self.level = self.dbop.getconfig("ENG_LEVEL", 0) self.numengine = self.dbop.getconfig("ENG_ENGINE", 0) self.trainingEngines = self.dbop.trainingEngines() self.auto_analysis = self.trainingEngines.get("AUTO_ANALYSIS", True) self.ask_movesdifferent = self.trainingEngines.get( "ASK_MOVESDIFFERENT", False) liTimes = self.trainingEngines.get("TIMES") if not liTimes: liTimes = [500, 1000, 2000, 4000, 8000] liBooks = self.trainingEngines.get("BOOKS") if not liBooks: liBooks = ["", "", "", "", ""] liBooks_sel = self.trainingEngines.get("BOOKS_SEL") if not liBooks_sel: liBooks_sel = ["", "", "", "", ""] liEngines = self.trainingEngines["ENGINES"] num_engines_base = len(liEngines) liEnginesExt = [ key for key in self.trainingEngines.get("EXT_ENGINES", []) if not (key in liEngines) ] num_engines = num_engines_base + len(liEnginesExt) if self.numengine >= num_engines: self.level += 1 self.numengine = 0 self.dbop.setconfig("ENG_LEVEL", self.level) self.dbop.setconfig("ENG_ENGINE", 0) num_levels = len(liTimes) if self.level >= num_levels: if QTUtil2.pregunta( self.main_window, "%s.\n%s" % (_("Training finished"), _("Do you want to reinit?"))): self.dbop.setconfig("ENG_LEVEL", 0) self.dbop.setconfig("ENG_ENGINE", 0) self.reinicio(dbop) return self.time = liTimes[self.level] nombook = liBooks[self.level] if nombook: list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) self.book = list_books.buscaLibro(nombook) if self.book: self.book.polyglot() self.book.mode = liBooks_sel[self.level] if not self.book.mode: self.book.mode = "mp" else: self.book = None if self.numengine < num_engines_base: self.keyengine = liEngines[self.numengine] else: self.keyengine = liEnginesExt[self.numengine - num_engines_base - 1] self.plies_mandatory = self.trainingEngines["MANDATORY"] self.plies_control = self.trainingEngines["CONTROL"] self.plies_pendientes = self.plies_control self.lost_points = self.trainingEngines["LOST_POINTS"] self.is_human_side_white = self.trainingEngines["COLOR"] == "WHITE" self.is_engine_side_white = not self.is_human_side_white self.siAprobado = False rival = self.configuration.buscaRival(self.keyengine) self.xrival = self.procesador.creaManagerMotor(rival, self.time, None) self.xrival.is_white = self.is_engine_side_white self.xanalyzer.cambiaOpciones( max(self.xtutor.motorTiempoJugada, self.time + 5.0), 0) juez = self.configuration.buscaRival( self.trainingEngines["ENGINE_CONTROL"]) self.xjuez = self.procesador.creaManagerMotor( juez, int(self.trainingEngines["ENGINE_TIME"] * 1000), None) self.xjuez.anulaMultiPV() self.li_info = [ "<b>%s</b>: %d/%d - %s" % (_("Engine"), self.numengine + 1, num_engines, self.xrival.name), '<b>%s</b>: %d/%d - %0.1f"' % (_("Level"), self.level + 1, num_levels, self.time / 1000.0), ] self.dicFENm2 = self.trainingEngines["DICFENM2"] self.siAyuda = False self.board.dbvisual_set_show_allways(False) self.hints = 9999 # Para que analice sin problemas self.game = Game.Game() self.main_window.pon_toolbar((TB_CLOSE, TB_RESIGN, TB_REINIT)) self.main_window.activaJuego(True, False, siAyudas=False) self.set_dispatcher(self.player_has_moved) self.set_position(self.game.last_position) self.show_side_indicator(True) self.remove_hints() self.put_pieces_bottom(self.is_human_side_white) self.pgnRefresh(True) self.ponCapInfoPorDefecto() self.state = ST_PLAYING self.check_boards_setposition() self.errores = 0 self.ini_time = time.time() self.muestraInformacion() self.play_next_move()
def __init__(self, procesador): w_parent = procesador.main_window self.configuration = procesador.configuration self.procesador = procesador titulo = _("Training with a book") icono = Iconos.Libros() QTVarios.WDialogo.__init__(self, w_parent, titulo, icono, "bookstrain") self.setMinimumWidth(450) flb = Controles.TipoLetra(puntos=10) # Variables antiguas dic_data = self.restore() # Toolbar liAcciones = [(_("Accept"), Iconos.Aceptar(), self.aceptar), None, (_("Cancel"), Iconos.Cancelar(), self.cancelar), None] tb = Controles.TBrutina(self, liAcciones) # Side self.rb_white = Controles.RB(self, _("White")) self.rb_white.setChecked(dic_data.get(self.ISWHITE, True)) self.rb_black = Controles.RB(self, _("Black")) self.rb_black.setChecked(not dic_data.get(self.ISWHITE, True)) hbox = Colocacion.H().relleno().control( self.rb_white).espacio(10).control(self.rb_black).relleno() gb_side = Controles.GB(self, _("Play with"), hbox).ponFuente(flb) # Books fvar = self.configuration.file_books self.list_books = Books.ListBooks() self.list_books.restore_pickle(fvar) self.list_books.check() li = [(x.name, x) for x in self.list_books.lista] # Player book_player = li[0][1] if li else None nom_book_player = dic_data.get(self.BOOK_PLAYER) if nom_book_player: for nom, book in li: if nom == nom_book_player: book_player = book break self.cb_player = Controles.CB(self, li, book_player) btNuevo = Controles.PB(self, "", self.nuevo, plano=False).ponIcono(Iconos.Nuevo(), icon_size=16) btBorrar = Controles.PB(self, "", self.borrar, plano=False).ponIcono(Iconos.Borrar(), icon_size=16) self.chb_highest = Controles.CHB( self, _("Always the highest percentage"), dic_data.get(self.ALWAYS_HIGHEST, False)) lybook = Colocacion.H().relleno().control( self.cb_player).control(btNuevo).control(btBorrar).relleno() ly_select = Colocacion.H().relleno().control( self.chb_highest).relleno() ly = Colocacion.V().otro(lybook).espacio(10).otro(ly_select) gb_player = Controles.GB(self, _("Player's book"), ly).ponFuente(flb) # Rival book_rival = book_player nom_book_rival = dic_data.get(self.BOOK_RIVAL) if nom_book_rival: for nom, book in li: if nom == nom_book_rival: book_rival = book break self.cb_rival = Controles.CB(self, li, book_rival) li = ( (_("Selected by the player"), "su"), (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp"), ) self.cb_resp_rival = Controles.CB(self, li, dic_data.get(self.RESP_RIVAL, "au")) ly = Colocacion.V().controlc(self.cb_rival).espacio(10).controlc( self.cb_resp_rival) gb_rival = Controles.GB(self, _("Rival book"), ly).ponFuente(flb) self.chb_showmenu = Controles.CHB( self, _("Display a menu of alternatives if move is invalid"), dic_data.get(self.SHOW_MENU, True)) vlayout = Colocacion.V() vlayout.control(gb_side).espacio(5) vlayout.control(gb_player).espacio(5) vlayout.control(gb_rival).espacio(5) vlayout.control(self.chb_showmenu).espacio(5) vlayout.margen(20) layout = Colocacion.V().control(tb).otro(vlayout).margen(3) self.setLayout(layout) self.restore_video()
def __init__(self, wParent, nombre_torneo): torneo = self.torneo = Tournament.Tournament(nombre_torneo) titulo = nombre_torneo icono = Iconos.Torneos() extparam = "untorneo_v1" QTVarios.WDialogo.__init__(self, wParent, titulo, icono, extparam) self.configuracion = Code.configuracion # Datos self.liEnActual = [] self.xjugar = None self.liResult = None self.last_change = Util.today() self.li_results = [] # Toolbar tb = Controles.TBrutina(self, tamIcon=24) tb.new(_("Close"), Iconos.MainMenu(), self.terminar) tb.new(_("Launch a worker"), Iconos.Lanzamiento(), self.gm_launch) # Tabs self.tab = tab = Controles.Tab() # Tab-configuracion -------------------------------------------------- w = QtWidgets.QWidget() # Adjudicator lb_resign = Controles.LB( self, "%s (%s): " % (_("Minimum centipawns to assign winner"), _("0=disable"))) self.ed_resign = Controles.ED(self).tipoInt( torneo.resign()).anchoFijo(30) bt_resign = Controles.PB(self, "", rutina=self.borra_resign).ponIcono( Iconos.Reciclar()) # Draw-plys lbDrawMinPly = Controles.LB( self, "%s (%s): " % (_("Minimum moves to assign draw"), _("0=disable"))) self.sbDrawMinPly = Controles.SB(self, torneo.drawMinPly(), 20, 1000) # Draw-puntos lb_draw_range = Controles.LB( self, _("Maximum centipawns to assign draw") + ": ") self.ed_draw_range = Controles.ED(self).tipoInt( torneo.drawRange()).anchoFijo(30) bt_draw_range = Controles.PB( self, "", rutina=self.borra_draw_range).ponIcono(Iconos.Reciclar()) # adjudicator self.liMotores = self.configuracion.comboMotoresMultiPV10() self.cbJmotor, self.lbJmotor = QTUtil2.comboBoxLB( self, self.liMotores, torneo.adjudicator(), _("Engine")) self.edJtiempo = Controles.ED(self).tipoFloat().ponFloat( 1.0).anchoFijo(50).ponFloat(torneo.adjudicator_time()) self.lbJtiempo = Controles.LB2P(self, _("Time in seconds")) layout = Colocacion.G() layout.controld(self.lbJmotor, 3, 0).control(self.cbJmotor, 3, 1) layout.controld(self.lbJtiempo, 4, 0).control(self.edJtiempo, 4, 1) self.gbJ = Controles.GB(self, _("Adjudicator"), layout) self.gbJ.setCheckable(True) self.gbJ.setChecked(torneo.adjudicator_active()) lbBook = Controles.LB(self, _("Opening book") + ": ") fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.restore_pickle(fvar) # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.name, x.path) for x in self.listaLibros.lista] li.insert(0, ("* " + _("None"), "-")) self.cbBooks = Controles.CB(self, li, torneo.book()) btNuevoBook = Controles.PB(self, "", self.nuevoBook, plano=False).ponIcono(Iconos.Nuevo(), tamIcon=16) lyBook = Colocacion.H().control( self.cbBooks).control(btNuevoBook).relleno() lbBookDepth = Controles.LB(self, _("Max depth of book (0=Maximum)") + ": ") self.sbBookDepth = Controles.SB(self, torneo.bookDepth(), 0, 200) # Posicion inicial lbFEN = Controles.LB(self, _("Initial position") + ": ") self.fen = torneo.fen() self.btPosicion = Controles.PB(self, " " * 5 + _("Change") + " " * 5, self.posicionEditar).ponPlano(False) self.btPosicionQuitar = Controles.PB( self, "", self.posicionQuitar).ponIcono(Iconos.Motor_No()) self.btPosicionPegar = (Controles.PB(self, "", self.posicionPegar).ponIcono( Iconos.Pegar16()).ponToolTip( _("Paste FEN position"))) lyFEN = (Colocacion.H().control(self.btPosicionQuitar).control( self.btPosicion).control(self.btPosicionPegar).relleno()) # Norman Pollock lbNorman = Controles.LB( self, '%s(<a href="https://komodochess.com/pub/40H-pgn-utilities">?</a>): ' % _("Initial position from Norman Pollock openings database"), ) self.chbNorman = Controles.CHB(self, " ", self.torneo.norman()) # Layout layout = Colocacion.G() ly_res = Colocacion.H().control( self.ed_resign).control(bt_resign).relleno() ly_dra = Colocacion.H().control( self.ed_draw_range).control(bt_draw_range).relleno() layout.controld(lb_resign, 0, 0).otro(ly_res, 0, 1) layout.controld(lbDrawMinPly, 1, 0).control(self.sbDrawMinPly, 1, 1) layout.controld(lb_draw_range, 2, 0).otro(ly_dra, 2, 1) layout.controld(lbBook, 3, 0).otro(lyBook, 3, 1) layout.controld(lbBookDepth, 4, 0).control(self.sbBookDepth, 4, 1) layout.controld(lbFEN, 5, 0).otro(lyFEN, 5, 1) layout.controld(lbNorman, 6, 0).control(self.chbNorman, 6, 1) layoutV = Colocacion.V().relleno().otro(layout).control( self.gbJ).relleno() layoutH = Colocacion.H().relleno().otro(layoutV).relleno() # Creamos w.setLayout(layoutH) tab.nuevaTab(w, _("Configuration")) # Tab-engines -------------------------------------------------- self.splitterEngines = QtWidgets.QSplitter(self) self.register_splitter(self.splitterEngines, "engines") # TB li_acciones = [ (_("New"), Iconos.TutorialesCrear(), self.enNuevo), None, (_("Modify"), Iconos.Modificar(), self.enModificar), None, (_("Remove"), Iconos.Borrar(), self.enBorrar), None, (_("Copy"), Iconos.Copiar(), self.enCopiar), None, (_("Import"), Iconos.MasDoc(), self.enImportar), None, ] tbEnA = Controles.TBrutina(self, li_acciones, tamIcon=16, style=QtCore.Qt.ToolButtonTextBesideIcon) # Grid engine o_columns = Columnas.ListaColumnas() o_columns.nueva("NUM", _("N."), 50, centered=True) o_columns.nueva("ALIAS", _("Alias"), 209) self.gridEnginesAlias = Grid.Grid(self, o_columns, siSelecFilas=True, siSeleccionMultiple=True, xid=GRID_ALIAS) self.register_grid(self.gridEnginesAlias) w = QtWidgets.QWidget() ly = Colocacion.V().control(self.gridEnginesAlias).margen(0) w.setLayout(ly) self.splitterEngines.addWidget(w) o_columns = Columnas.ListaColumnas() o_columns.nueva("CAMPO", _("Label"), 200, siDerecha=True) o_columns.nueva("VALOR", _("Value"), 286) self.gridEnginesValores = Grid.Grid(self, o_columns, siSelecFilas=False, xid=GRID_VALUES) self.register_grid(self.gridEnginesValores) w = QtWidgets.QWidget() ly = Colocacion.V().control(self.gridEnginesValores).margen(0) w.setLayout(ly) self.splitterEngines.addWidget(w) self.splitterEngines.setSizes([250, 520]) # por defecto w = QtWidgets.QWidget() ly = Colocacion.V().control(tbEnA).control(self.splitterEngines) w.setLayout(ly) tab.nuevaTab(w, _("Engines")) # Creamos # Tab-games queued-------------------------------------------------- w = QtWidgets.QWidget() # TB li_acciones = [ (_("New"), Iconos.TutorialesCrear(), self.gm_crear_queued), None, (_("Remove"), Iconos.Borrar(), self.gm_borrar_queued), None, ] tbEnG = Controles.TBrutina(self, li_acciones, tamIcon=16, style=QtCore.Qt.ToolButtonTextBesideIcon) o_columns = Columnas.ListaColumnas() o_columns.nueva("NUM", _("N."), 50, centered=True) o_columns.nueva("WHITE", _("White"), 190, centered=True) o_columns.nueva("BLACK", _("Black"), 190, centered=True) o_columns.nueva("TIME", _("Time"), 170, centered=True) # o_columns.nueva("STATE", _("State"), 190, centered=True) self.gridGamesQueued = Grid.Grid(self, o_columns, siSelecFilas=True, siSeleccionMultiple=True, xid=GRID_GAMES_QUEUED) self.register_grid(self.gridGamesQueued) # Layout layout = Colocacion.V().control(tbEnG).control(self.gridGamesQueued) # Creamos w.setLayout(layout) tab.nuevaTab(w, _("Games queued")) # Tab-games terminados-------------------------------------------------- w = QtWidgets.QWidget() # TB li_acciones = [ (_("Remove"), Iconos.Borrar(), self.gm_borrar_finished), None, (_("Show"), Iconos.PGN(), self.gm_show_finished), None, (_("Save") + "(%s)" % _("PGN"), Iconos.GrabarComo(), self.gm_save_pgn), None, ] tbEnGt = Controles.TBrutina(self, li_acciones, tamIcon=16, style=QtCore.Qt.ToolButtonTextBesideIcon) o_columns = Columnas.ListaColumnas() o_columns.nueva("NUM", _("N."), 50, centered=True) o_columns.nueva("WHITE", _("White"), 190, centered=True) o_columns.nueva("BLACK", _("Black"), 190, centered=True) o_columns.nueva("TIME", _("Time"), 170, centered=True) o_columns.nueva("RESULT", _("Result"), 190, centered=True) self.gridGamesFinished = Grid.Grid(self, o_columns, siSelecFilas=True, siSeleccionMultiple=True, xid=GRID_GAMES_FINISHED) self.register_grid(self.gridGamesFinished) # Layout layout = Colocacion.V().control(tbEnGt).control(self.gridGamesFinished) # Creamos w.setLayout(layout) tab.nuevaTab(w, _("Games finished")) # Tab-resultado -------------------------------------------------- w = QtWidgets.QWidget() # Grid wh = _("W") bl = _("B") o_columns = Columnas.ListaColumnas() o_columns.nueva("NUM", _("N."), 35, centered=True) o_columns.nueva("ENGINE", _("Engine"), 120, centered=True) o_columns.nueva("SCORE", _("Score") + "%", 50, centered=True) o_columns.nueva("WIN", _("Wins"), 50, centered=True) o_columns.nueva("DRAW", _("Draws"), 50, centered=True) o_columns.nueva("LOST", _("Losses"), 50, centered=True) o_columns.nueva("WIN-WHITE", "%s %s" % (wh, _("Wins")), 60, centered=True) o_columns.nueva("DRAW-WHITE", "%s %s" % (wh, _("Draws")), 60, centered=True) o_columns.nueva("LOST-WHITE", "%s %s" % (wh, _("Losses")), 60, centered=True) o_columns.nueva("WIN-BLACK", "%s %s" % (bl, _("Wins")), 60, centered=True) o_columns.nueva("DRAW-BLACK", "%s %s" % (bl, _("Draws")), 60, centered=True) o_columns.nueva("LOST-BLACK", "%s %s" % (bl, _("Losses")), 60, centered=True) o_columns.nueva("GAMES", _("Games"), 50, centered=True) self.gridResults = Grid.Grid(self, o_columns, siSelecFilas=True, xid=GRID_RESULTS) self.register_grid(self.gridResults) self.qtColor = { "WHITE": QTUtil.qtColorRGB(255, 250, 227), "BLACK": QTUtil.qtColorRGB(221, 255, 221), "SCORE": QTUtil.qtColorRGB(170, 170, 170), } # Layout layout = Colocacion.V().control(self.gridResults) # Creamos w.setLayout(layout) tab.nuevaTab(w, _("Results")) # Layout # tab.setposition("W") layout = Colocacion.V().control(tb).espacio(-3).control(tab).margen(2) self.setLayout(layout) self.restore_video(siTam=True, anchoDefecto=800, altoDefecto=430) self.gridEnginesAlias.gotop() self.ed_resign.setFocus() self.muestraPosicion() QtCore.QTimer.singleShot(5000, self.comprueba_cambios) self.rotulos_tabs()
def base_inicio(self, engine_rival, minutos, seconds, human_side=None): self.game_type = GT_MICELO self.engine_rival = engine_rival self.minutos = minutos self.seconds = seconds self.is_competitive = True self.resultado = None self.human_is_playing = False self.state = ST_PLAYING self.showed_result = False # Problema doble asignacion de ptos Thomas if human_side is None: is_white = self.determinaColor(engine_rival) else: is_white = human_side self.human_side = 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.set_activate_tutor(False) self.ayudas_iniciales = self.hints = 0 self.vtime = {} self.maxSegundos = minutos * 60 self.secs_move = seconds self.vtime[True] = Util.Timer(self.maxSegundos) self.vtime[False] = Util.Timer(self.maxSegundos) self.vtime = { WHITE: Util.Timer(self.maxSegundos), BLACK: Util.Timer(self.maxSegundos) } cbook = self.engine_rival.book if self.engine_rival.book else Code.tbook self.book = Books.Book("P", cbook, cbook, True) self.book.polyglot() elo = self.engine_rival.elo self.maxMoveBook = (elo // 200) if 0 <= elo <= 1700 else 9999 eloengine = self.engine_rival.elo eloplayer = self.configuration.miceloActivo() self.whiteElo = eloplayer if is_white else eloengine self.blackElo = eloplayer if not is_white else eloengine self.xrival = self.procesador.creaManagerMotor( self.engine_rival, None, None, siMultiPV=self.engine_rival.multiPV > 0) self.xrival.check_engine() self.pte_tool_resigndraw = False if self.human_side: self.pte_tool_resigndraw = True self.maxPlyRendirse = 1 else: self.maxPlyRendirse = 0 self.pon_toolbar() self.main_window.activaJuego(True, True, siAyudas=False) self.set_dispatcher(self.player_has_moved) self.set_position(self.game.last_position) self.put_pieces_bottom(is_white) self.remove_hints(True, siQuitarAtras=True) self.show_side_indicator(True) nbsp = " " * 3 txt = "%s:%+d%s%s:%+d%s%s:%+d" % ( _("Win"), self.engine_rival.pgana, nbsp, _("Draw"), self.engine_rival.ptablas, nbsp, _("Loss"), self.engine_rival.ppierde, ) self.set_label1("<center>%s</center>" % txt) self.set_label2("") self.pgnRefresh(True) self.ponCapInfoPorDefecto() tpBL = self.vtime[True].etiqueta() tpNG = self.vtime[False].etiqueta() self.rival = self.engine_rival.alias + " (%d)" % self.engine_rival.elo player = self.configuration.x_player + " (%d)" % self.configuration.miceloActivo( ) white_name, black_name = self.configuration.nom_player( ), self.engine_rival.alias white_elo, black_elo = self.configuration.miceloActivo( ), self.engine_rival.elo if self.is_engine_side_white: white_name, black_name = black_name, white_name white_elo, black_elo = black_elo, white_elo self.game.set_tag("Event", _("Tourney-Elo")) self.game.set_tag("White", white_name) self.game.set_tag("Black", black_name) self.game.set_tag("WhiteElo", str(white_elo)) self.game.set_tag("BlackElo", str(black_elo)) time_control = "%d" % int(self.maxSegundos) if self.secs_move: time_control += "+%d" % self.secs_move self.game.set_tag("TimeControl", time_control) white_player = white_name + " (%d)" % white_elo black_player = black_name + " (%d)" % black_elo self.main_window.ponDatosReloj(white_player, tpBL, black_player, tpNG) self.refresh() self.check_boards_setposition() self.game.tag_timestart()