def importarPolyglot(self, partida): listaLibros = Books.ListaLibros() listaLibros.recuperaVar(self.configuracion.ficheroBooks) listaLibros.comprueba() liGen = [FormLayout.separador] li = [(book.nombre, book) for book in listaLibros.lista] config = FormLayout.Combobox(_("Book that plays white side"), li) liGen.append((config, listaLibros.lista[0])) liGen.append(FormLayout.separador) config = FormLayout.Combobox(_("Book that plays black side"), li) liGen.append((config, listaLibros.lista[0])) 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 else: return bookW.polyglot() bookB.polyglot() titulo = bookW.nombre if bookW==bookB else "%s/%s" % (bookW.nombre, bookB.nombre) dicData = self.configuracion.leeVariables("OPENINGLINES") dicData = self.importarLeeParam(titulo, dicData) if dicData: depth, siWhite, minMoves = dicData["DEPTH"], dicData["SIWHITE"], dicData["MINMOVES"] self.dbop.importarPolyglot(self, partida, bookW, bookB, titulo, depth, siWhite, minMoves) self.glines.refresh() self.glines.gotop()
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, wParent): QtGui.QDialog.__init__(self, wParent) self.wParent = wParent self.fichero = "" 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.configuracion = VarGen.configuracion fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.recuperaVar(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 liAcciones = [(_("Accept"), Iconos.Aceptar(), "aceptar"), None, (_("Cancel"), Iconos.Cancelar(), "cancelar"), None] tb = Controles.TB(self, liAcciones) # Layout layout = Colocacion.V().control(tb).otro(ly).margen(3) self.setLayout(layout)
def importarPolyglot(self, partida): listaLibros = Books.ListaLibros() listaLibros.recuperaVar(self.configuracion.ficheroBooks) listaLibros.comprueba() dicData = self.dbop.getconfig("IMPORT_POLYGLOT") bookW = listaLibros.lista[0] bookB = listaLibros.lista[0] if dicData: book = listaLibros.buscaLibro(dicData["BOOKW"]) if book: bookW = book book = listaLibros.buscaLibro(dicData["BOOKB"]) if book: bookB = book liGen = [FormLayout.separador] li = [(bookx.nombre, bookx) for bookx in listaLibros.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.nombre, "BOOKB": bookB.nombre} self.dbop.setconfig("IMPORT_POLYGLOT", dicData) else: return bookW.polyglot() bookB.polyglot() titulo = bookW.nombre if bookW == bookB else "%s/%s" % (bookW.nombre, bookB.nombre) dicData = self.importarLeeParam(titulo) if dicData: depth, siWhite, onlyone, minMoves = dicData["DEPTH"], dicData[ "SIWHITE"], dicData["ONLYONE"], dicData["MINMOVES"] self.dbop.importarPolyglot(self, partida, bookW, bookB, titulo, depth, siWhite, onlyone, minMoves) self.glines.refresh() self.glines.gotop()
def __init__(self, gestor, siEnVivo): titulo = _("Consult a book") icono = Iconos.Libros() extparam = "treebook" super().__init__(parent=gestor.pantalla, titulo=titulo, icono=icono, extparam=extparam) # Se lee la lista de libros1 self.listaLibros = Books.ListaLibros() self.fvar = gestor.configuracion.ficheroBooks self.listaLibros.recuperaVar(self.fvar) # Comprobamos que todos esten accesibles self.listaLibros.comprueba() self.book = self.listaLibros.porDefecto() # fens fenActivo = gestor.fenActivoConInicio() # Posicion en el tablero fenUltimo = gestor.fenUltimo() self.siEnviar = siEnVivo and (fenActivo == fenUltimo) self.listaMoves = ListaMoves(None, self.book, fenActivo) self.infoMove = InfoMove(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() anchoTablero = self.infoMove.tablero.width() self.resize(600 - 278 + anchoTablero, anchoTablero + 30) self.splitter.setSizes([296 - 278 + anchoTablero, 290]) for col, ancho in enumerate((100, 59, 87, 0, 38)): self.wmoves.tree.setColumnWidth(col, ancho) self.ponTitulo(self.book)
def __init__(self, wParent, torneo): titulo = _("Competition") icono = Iconos.Torneos() extparam = "untorneo" QTVarios.WDialogo.__init__(self, wParent, titulo, icono, extparam) self.configuracion = VarGen.configuracion # Datos self.torneo = torneo self.liEnActual = [] self.xjugar = None self.liResult = None # Toolbar liAcciones = ( (_("Save") + "+" + _("Quit"), Iconos.MainMenu(), "terminar"), None, (_("Cancel"), Iconos.Cancelar(), "cancelar"), None, (_("Play"), Iconos.Empezar(), "gmJugar"), None, ) tb = Controles.TB(self, liAcciones) # Tabs self.tab = tab = Controles.Tab() # Tab-configuracion -------------------------------------------------- w = QtGui.QWidget() # # Nombre lbNombre = Controles.LB(self, _("Name") + ": ") self.edNombre = Controles.ED(w, torneo.nombre()) # # Resign lbResign = Controles.LB(self, _("Minimum points to assign winner") + ": ") self.sbResign = Controles.SB(self, torneo.resign(), 60, 10000) # Draw-plys lbDrawMinPly = Controles.LB(self, _("Minimum moves to assign draw") + ": ") self.sbDrawMinPly = Controles.SB(self, torneo.drawMinPly(), 20, 9999) # Draw-puntos lbDrawRange = Controles.LB(self, _("Maximum points to assign draw") + ": ") self.sbDrawRange = Controles.SB(self, torneo.drawRange(), 0, 50) lbBook = Controles.LB(self, _("Opening book") + ": ") fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.recuperaVar(fvar) # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.nombre, x.path) for x in self.listaLibros.lista] li.insert(0, ("* " + _("Default"), "")) 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() # 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="http://www.hoflink.com/~npollock/40H.html">?</a>): ' % _("Initial position from Norman Pollock openings database")) self.chbNorman = Controles.CHB(self, " ", self.torneo.norman()) # Layout layout = Colocacion.G() layout.controld(lbNombre, 0, 0).control(self.edNombre, 0, 1) layout.controld(lbResign, 1, 0).control(self.sbResign, 1, 1) layout.controld(lbDrawMinPly, 2, 0).control(self.sbDrawMinPly, 2, 1) layout.controld(lbDrawRange, 3, 0).control(self.sbDrawRange, 3, 1) layout.controld(lbBook, 4, 0).otro(lyBook, 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).relleno() layoutH = Colocacion.H().relleno().otro(layoutV).relleno() # Creamos w.setLayout(layoutH) tab.nuevaTab(w, _("Configuration")) # Tab-engines -------------------------------------------------- self.splitterEngines = QtGui.QSplitter(self) self.registrarSplitter(self.splitterEngines, "engines") # TB liAcciones = [ (_("New"), Iconos.TutorialesCrear(), "enNuevo"), None, (_("Modify"), Iconos.Modificar(), "enModificar"), None, (_("Remove"), Iconos.Borrar(), "enBorrar"), None, (_("Copy"), Iconos.Copiar(), "enCopiar"), None, (_("Import"), Iconos.MasDoc(), "enImportar"), None, ] tbEnA = Controles.TB(self, liAcciones, tamIcon=24) # Grid engine oColumnas = Columnas.ListaColumnas() oColumnas.nueva("ALIAS", _("Alias"), 209) self.gridEnginesAlias = Grid.Grid(self, oColumnas, siSelecFilas=True, xid="EA", siSeleccionMultiple=True) self.registrarGrid(self.gridEnginesAlias) w = QtGui.QWidget() ly = Colocacion.V().control(self.gridEnginesAlias).margen(0) w.setLayout(ly) self.splitterEngines.addWidget(w) oColumnas = Columnas.ListaColumnas() oColumnas.nueva("CAMPO", _("Label"), 200, siDerecha=True) oColumnas.nueva("VALOR", _("Value"), 286) self.gridEnginesValores = Grid.Grid(self, oColumnas, siSelecFilas=False, xid="EV") self.registrarGrid(self.gridEnginesValores) w = QtGui.QWidget() ly = Colocacion.V().control(self.gridEnginesValores).margen(0) w.setLayout(ly) self.splitterEngines.addWidget(w) self.splitterEngines.setSizes([250, 520]) # por defecto w = QtGui.QWidget() ly = Colocacion.V().control(tbEnA).control(self.splitterEngines) w.setLayout(ly) tab.nuevaTab(w, _("Engines")) # Creamos # Tab-games -------------------------------------------------- w = QtGui.QWidget() # TB liAcciones = [ (_("New"), Iconos.TutorialesCrear(), "gmCrear"), None, (_("Remove"), Iconos.Borrar(), "gmBorrar"), None, (_("Show"), Iconos.PGN(), "gmMostrar"), None, (_("Save") + "(%s)" % _("PGN"), Iconos.GrabarComo(), "gmGuardar"), None, ] tbEnG = Controles.TB(self, liAcciones, tamIcon=24) # Grid engine oColumnas = Columnas.ListaColumnas() oColumnas.nueva("WHITE", _("White"), 190, siCentrado=True) oColumnas.nueva("BLACK", _("Black"), 190, siCentrado=True) oColumnas.nueva("RESULT", _("Result"), 190, siCentrado=True) oColumnas.nueva("TIEMPO", _("Time"), 170, siCentrado=True) self.gridGames = Grid.Grid(self, oColumnas, siSelecFilas=True, xid="G", siSeleccionMultiple=True) self.registrarGrid(self.gridGames) # Layout layout = Colocacion.V().control(tbEnG).control(self.gridGames) # Creamos w.setLayout(layout) tab.nuevaTab(w, _("Games")) # Tab-resultado -------------------------------------------------- w = QtGui.QWidget() # Grid oColumnas = Columnas.ListaColumnas() oColumnas.nueva("NUMERO", _("N."), 35, siCentrado=True) oColumnas.nueva("MOTOR", _("Engine"), 190, siCentrado=True) oColumnas.nueva("GANADOS", _("Wins"), 120, siCentrado=True) oColumnas.nueva("PERDIDOS", _("Lost"), 120, siCentrado=True) oColumnas.nueva("TABLAS", _("Draw"), 120, siCentrado=True) oColumnas.nueva("PUNTOS", _("Points"), 120, siCentrado=True) self.gridResult = Grid.Grid(self, oColumnas, siSelecFilas=True, xid="R") self.registrarGrid(self.gridResult) # Layout layout = Colocacion.V().control(self.gridResult) # Creamos w.setLayout(layout) tab.nuevaTab(w, _("Result")) # Layout layout = Colocacion.V().control(tb).control(tab).margen(8) self.setLayout(layout) self.recuperarVideo(siTam=True, anchoDefecto=800, altoDefecto=430) self.gridEnginesAlias.gotop() self.edNombre.setFocus() self.muestraPosicion()
def __init__(self, procesador, titulo): QTVarios.WDialogo.__init__(self, procesador.pantalla, titulo, Iconos.Libre(), "entMaquina") self.configuracion = procesador.configuracion self.procesador = procesador self.personalidades = Personalidades.Personalidades( self, self.configuracion) self.motores = Motores.Motores(self.configuracion) # Toolbar liAcciones = [ (_("Accept"), Iconos.Aceptar(), self.aceptar), None, (_("Cancel"), Iconos.Cancelar(), self.cancelar), None, (_("Configurations"), Iconos.Configurar(), self.configuraciones), None, ] tb = Controles.TBrutina(self, liAcciones) # Tab tab = Controles.Tab() def nuevoG(): lyG = Colocacion.G() lyG.filaActual = 0 return lyG 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; margin-top: 5ex; /* leave space at the top for the title */ } QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top center; /* position at the top center */ padding: 0 3px; } """ def _label(lyG, txt, ly, rutinaCHB=None, siCheck=False): gb = Controles.GB(self, txt, ly) if rutinaCHB: gb.conectar(rutinaCHB) elif siCheck: gb.setCheckable(True) gb.setChecked(False) gb.setStyleSheet(gbStyle) lyG.controlc(gb, lyG.filaActual, 0) lyG.filaActual += 1 return gb # TAB General lyG = nuevoG() # Blancas o negras self.rbBlancas = Controles.RB(self, "").activa() self.rbBlancas.setIcon( QTVarios.fsvg2ico("Pieces/Chessicons/wp.svg", 64)) self.rbNegras = Controles.RB(self, "") self.rbNegras.setIcon(QTVarios.fsvg2ico("Pieces/Chessicons/bp.svg", 64)) self.rbRandom = Controles.RB(self, _("Random")) hbox = Colocacion.H().relleno().control( self.rbBlancas).espacio(30).control( self.rbNegras).espacio(30).control(self.rbRandom).relleno() _label(lyG, _("Select color"), hbox) # Motores liDepths = [("--", 0)] for x in range(1, 31): liDepths.append((str(x), x)) # # Rival self.rival = self.configuracion.rivalInicial self.rivalTipo = Motores.INTERNO self.btRival = Controles.PB(self, "", self.cambiaRival, plano=False) self.edRtiempo = Controles.ED(self).tipoFloat().anchoMaximo(50) self.cbRdepth = Controles.CB(self, liDepths, 0).capturaCambiado(self.cambiadoDepth) lbTiempoSegundosR = Controles.LB2P(self, _("Time")) lbNivel = Controles.LB2P(self, _("Depth")) # # Ajustar rival liAjustes = self.personalidades.listaAjustes(True) self.cbAjustarRival = Controles.CB(self, liAjustes, kAjustarMejor).capturaCambiado( self.ajustesCambiado) lbAjustarRival = Controles.LB2P(self, _("Set strength")) btAjustarRival = Controles.PB(self, _("Personality"), self.cambiaPersonalidades, plano=True).ponIcono(Iconos.Mas(), tamIcon=16) # Resign lbResign = Controles.LB2P(self, _("Resign/draw by engine")) liResign = ((_("Very early"), -100), (_("Early"), -300), (_("Average"), -500), (_("Late"), -800), (_("Very late"), -1000), (_("Never"), -9999999)) self.cbResign = Controles.CB(self, liResign, -800) lyH1 = Colocacion.H().control(self.btRival).espacio(20) lyH1.control(lbTiempoSegundosR).control(self.edRtiempo) lyH1.control(lbNivel).control(self.cbRdepth).relleno() lyH2 = Colocacion.H().control(lbAjustarRival).control( self.cbAjustarRival).control(btAjustarRival).relleno() lyH3 = Colocacion.H().control(lbResign).control( self.cbResign).relleno() ly = Colocacion.V().otro(lyH1).otro(lyH2).otro(lyH3) _label(lyG, _("Opponent"), ly) gb = Controles.GB(self, "", lyG) tab.nuevaTab(gb, _("Basic configuration")) # TAB Ayudas lbAyudas = Controles.LB2P(self, _("Available hints")) self.sbAyudas = Controles.SB(self, 7, 0, 999).tamMaximo(50) self.cbAtras = Controles.CHB(self, _("Takeback"), True) self.cbChance = Controles.CHB(self, _("Second chance"), True) btTutorChange = Controles.PB(self, _("Tutor change"), self.tutorChange, plano=False).ponIcono(Iconos.Tutor(), tamIcon=16) 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)) lb = Controles.LB(self, _("It is showed") + ":") self.cbThoughtTt = Controles.CB(self, liThinks, -1) self.cbContinueTt = Controles.CHB( self, _("The tutor thinks while you think"), True) lbBoxHeight = Controles.LB2P(self, _("Box height")) self.sbBoxHeight = Controles.SB(self, 7, 0, 999).tamMaximo(50) ly1 = Colocacion.H().control(lb).control(self.cbThoughtTt).relleno() ly2 = Colocacion.H().control(lbBoxHeight).control( self.sbBoxHeight).relleno() ly = Colocacion.V().otro(ly1).control( self.cbContinueTt).espacio(16).otro(ly2).relleno() gbThoughtTt = Controles.GB(self, _("Thought of the tutor"), ly) gbThoughtTt.setStyleSheet(gbStyle) lb = Controles.LB(self, _("It is showed") + ":") self.cbThoughtOp = Controles.CB(self, liThinks, -1) lbArrows = Controles.LB2P(self, _("Arrows to show")) self.sbArrows = Controles.SB(self, 7, 0, 999).tamMaximo(50) ly1 = Colocacion.H().control(lb).control(self.cbThoughtOp).relleno() ly2 = Colocacion.H().control(lbArrows).control(self.sbArrows).relleno() ly = Colocacion.V().otro(ly1).otro(ly2).relleno() gbThoughtOp = Controles.GB(self, _("Thought of the opponent"), ly) gbThoughtOp.setStyleSheet(gbStyle) self.chbSummary = Controles.CHB( self, _("Save a summary when the game is finished in the main comment"), False) lyH1 = Colocacion.H().relleno() lyH1.control(lbAyudas).control(self.sbAyudas).relleno() lyH1.control(self.cbAtras).relleno() lyH1.control(self.cbChance).relleno() lyH1.control(btTutorChange).relleno() # lyV1 = Colocacion.V().control(gbThoughtOp) lyH3 = Colocacion.H().relleno() lyH3.control(gbThoughtOp).relleno() lyH3.control(gbThoughtTt).relleno() ly = Colocacion.V().otro(lyH1).otro(lyH3).control( self.chbSummary).margen(16) gb = Controles.GB(self, "", ly) tab.nuevaTab(gb, _("Help configuration")) # TAB Tiempo lyG = nuevoG() self.edMinutos, self.lbMinutos = QTUtil2.spinBoxLB( self, 15, 0, 999, maxTam=50, etiqueta=_("Total minutes")) self.edSegundos, self.lbSegundos = QTUtil2.spinBoxLB( self, 6, -999, 999, maxTam=54, etiqueta=_("Seconds added per move")) self.edMinExtra, self.lbMinExtra = QTUtil2.spinBoxLB( self, 0, -999, 999, maxTam=70, etiqueta=_("Extra minutes for the player")) self.edZeitnot, self.lbZeitnot = QTUtil2.spinBoxLB( self, 0, -999, 999, maxTam=54, etiqueta=_("Zeitnot: alarm sounds when remaining seconds")) lyH1 = Colocacion.H() lyH1.control(self.lbMinutos).control(self.edMinutos).espacio(30) lyH1.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(lyH1).otro(lyH2).otro(lyH3) self.chbTiempo = _label(lyG, _("Time"), ly, siCheck=True) gb = Controles.GB(self, "", lyG) tab.nuevaTab(gb, _("Time")) # TAB Initial moves lyG = nuevoG() # Posicion self.btPosicion = Controles.PB(self, " " * 5 + _("Change") + " " * 5, self.posicionEditar).ponPlano(False) self.fen = "" 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")) 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) 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.recuperaVar(fvar) # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.nombre, x) for x in self.listaLibros.lista] libInicial = li[0][1] if li else None self.cbBooks = QTUtil2.comboBoxLB(self, li, libInicial) self.btNuevoBook = Controles.PB(self, "", self.nuevoBook, plano=True).ponIcono(Iconos.Mas(), tamIcon=16) self.chbBookMandatory = Controles.CHB(self, _("Mandatory"), False) # Respuesta rival li = ( (_("Selected by the player"), "su"), (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp"), ) self.cbBooksRR = QTUtil2.comboBoxLB(self, li, "mp") self.lbBooksRR = Controles.LB2P(self, _("Opponent's move")) hbox = Colocacion.H().relleno().control(self.cbBooks).control( self.btNuevoBook).control(self.chbBookMandatory).relleno() hboxRR = Colocacion.H().relleno().control(self.lbBooksRR).control( self.cbBooksRR).relleno() hboxV = Colocacion.V().otro(hbox).otro(hboxRR) self.chbBook = _label(lyG, _("Book"), hboxV, siCheck=True) ly = Colocacion.V().otro(lyG).relleno() gb = Controles.GB(self, "", ly) tab.nuevaTab(gb, _("Initial moves")) layout = Colocacion.V().control(tb).control(tab).relleno().margen(3) self.setLayout(layout) self.liAperturasFavoritas = [] self.btAperturasFavoritas.hide() dic = Util.recuperaDIC(self.configuracion.ficheroEntMaquina) if not dic: dic = {} self.muestraDic(dic) self.ajustesCambiado() # self.ayudasCambiado() self.ponRival() self.recuperarVideo()
def reinicio(self, dbop): self.dbop = dbop self.dbop.open_cache_engines() self.tipoJuego = kJugOpeningLines 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 = ["", "", "", "", ""] liEngines = self.trainingEngines["ENGINES"] num_engines_base = len(liEngines) liEnginesExt = self.trainingEngines.get("EXT_ENGINES", []) 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.pantalla, "%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: listaLibros = Books.ListaLibros() listaLibros.recuperaVar(self.configuracion.ficheroBooks) self.book = listaLibros.buscaLibro(nombook) if self.book: self.book.polyglot() 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.siJugamosConBlancas = self.trainingEngines["COLOR"] == "WHITE" self.siRivalConBlancas = not self.siJugamosConBlancas self.siAprobado = False rival = self.configuracion.buscaRivalExt(self.keyengine) self.xrival = self.procesador.creaGestorMotor(rival, self.time, None) self.xrival.siBlancas = self.siRivalConBlancas juez = self.configuracion.buscaRival( self.trainingEngines["ENGINE_CONTROL"]) self.xjuez = self.procesador.creaGestorMotor( 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.nombre), "<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.tablero.dbVisual_setShowAllways(False) self.ayudas = 9999 # Para que analice sin problemas self.partida = Partida.Partida() self.pantalla.ponToolBar((k_mainmenu, k_abandonar, k_reiniciar)) self.pantalla.activaJuego(True, False, siAyudas=False) self.ponMensajero(self.mueveHumano) self.ponPosicion(self.partida.ultPosicion) self.mostrarIndicador(True) self.quitaAyudas() self.ponPiezasAbajo(self.siJugamosConBlancas) self.pgnRefresh(True) self.ponCapInfoPorDefecto() self.estado = kJugando self.ponPosicionDGT() self.errores = 0 self.ini_time = time.time() self.muestraInformacion() self.siguienteJugada()
def paramAnalisisMasivo(parent, configuracion, siVariosSeleccionados): alm = leeDicParametros(configuracion) # Datos liGen = [SEPARADOR] # # Tutor li = configuracion.ayudaCambioTutor() li[0] = alm.motor liGen.append((_("Engine") + ":", li)) liGen.append(SEPARADOR) # # Time config = FormLayout.Editbox(_("Duration of engine analysis (secs)"), 40, tipo=float) liGen.append((config, alm.tiempo / 1000.0)) # Depth liDepths = [("--", 0)] for x in range(1, 31): liDepths.append((str(x), x)) config = FormLayout.Combobox(_("Depth"), liDepths) liGen.append((config, alm.depth)) # Time+Depth liGen.append(("%s+%s:" % (_("Time"), _("Depth")), alm.timedepth)) # MultiPV liGen.append(SEPARADOR) 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))) config = FormLayout.Combobox( _("Number of moves evaluated by engine(MultiPV)"), li) liGen.append((config, alm.multiPV)) liGen.append(SEPARADOR) liJ = [(_("White"), "BLANCAS"), (_("Black"), "NEGRAS"), (_("White & Black"), "AMBOS")] config = FormLayout.Combobox(_("Analyze only color"), liJ) liGen.append((config, "AMBOS")) liGen.append( ("<div align=\"right\">" + _("Only player moves") + ":<br>%s</div>" % _("(You can add multiple aliases separated by ; and wildcard * )"), "")) fvar = configuracion.ficheroBooks listaLibros = Books.ListaLibros() listaLibros.recuperaVar(fvar) # Comprobamos que todos esten accesibles listaLibros.comprueba() defecto = listaLibros.lista[0] li = [("--", None)] for libro in listaLibros.lista: if libro.nombre == alm.libro: defecto = libro li.append((libro.nombre, libro)) config = FormLayout.Combobox( _("Do not scan the opening moves based on book"), li) liGen.append((config, defecto)) liGen.append((_("Start from the end of the game") + ":", alm.desdeelfinal)) liGen.append(SEPARADOR) liGen.append((_("Only selected games") + ":", siVariosSeleccionados)) liBlunders, liBrilliancies = formBlundersBrilliancies(alm, configuracion) lista = [] lista.append((liGen, _("General options"), "")) lista.append((liBlunders, _("Wrong moves"), "")) lista.append((liBrilliancies, _("Brilliancies"), "")) reg = Util.Almacen() reg.form = None def dispatchR(valor): if reg.form is None: if isinstance(valor, FormLayout.FormTabWidget): reg.form = valor reg.wtime = valor.getWidget(0, 1) reg.wdepth = valor.getWidget(0, 2) reg.wdt = valor.getWidget(0, 3) elif isinstance(valor, FormLayout.FormWidget): reg.form = valor reg.wtime = valor.getWidget(1) reg.wdepth = valor.getWidget(2) reg.wdt = valor.getWidget(3) else: sender = reg.form.sender() if not reg.wdt.isChecked(): if sender == reg.wtime: if reg.wtime.textoFloat() > 0: reg.wdepth.setCurrentIndex(0) elif sender == reg.wdepth: if reg.wdepth.currentIndex() > 0: reg.wtime.ponFloat(0.0) elif sender == reg.wdt: if reg.wtime.textoFloat() > 0: reg.wdepth.setCurrentIndex(0) elif reg.wdepth.currentIndex() > 0: reg.wtime.ponFloat(0.0) QTUtil.refreshGUI() resultado = FormLayout.fedit(lista, title=_("Mass analysis"), parent=parent, anchoMinimo=460, icon=Iconos.Opciones(), dispatch=dispatchR) if resultado: accion, liResp = resultado liGen, liBlunders, liBrilliancies = liResp alm.motor = liGen[0] alm.tiempo = int(liGen[1] * 1000) alm.depth = liGen[2] alm.timedepth = liGen[3] alm.multiPV = liGen[4] color = liGen[5] alm.blancas = color != "NEGRAS" alm.negras = color != "BLANCAS" cjug = liGen[6].strip() alm.liJugadores = cjug.upper().split(";") if cjug else None alm.libroAperturas = liGen[7] alm.libro = alm.libroAperturas.nombre alm.desdeelfinal = liGen[8] alm.siVariosSeleccionados = liGen[9] alm.kblunders = liBlunders[0] alm.tacticblunders = liBlunders[1] alm.pgnblunders = liBlunders[2] alm.oriblunders = liBlunders[3] alm.bmtblunders = liBlunders[4] alm.dpbrilliancies = liBrilliancies[0] alm.ptbrilliancies = liBrilliancies[1] alm.fnsbrilliancies = liBrilliancies[2] alm.pgnbrilliancies = liBrilliancies[3] alm.oribrilliancies = liBrilliancies[4] alm.bmtbrilliancies = liBrilliancies[5] dic = {} for x in dir(alm): if not x.startswith("__"): dic[x.upper()] = getattr(alm, x) Util.guardaVar(configuracion.ficheroAnalisis, dic) if not (alm.tacticblunders or alm.pgnblunders or alm.bmtblunders or alm.fnsbrilliancies or alm.pgnbrilliancies or alm.bmtbrilliancies): QTUtil2.mensError(parent, _("No file was specified where to save results")) return return alm else: return None
def paramAnalisis(parent, configuracion, siModoAmpliado, siTodosMotores=False): alm = leeDicParametros(configuracion) # Datos liGen = [SEPARADOR] # # Tutor if siTodosMotores: li = configuracion.ayudaCambioCompleto(alm.motor) else: li = configuracion.ayudaCambioTutor() li[0] = alm.motor liGen.append((_("Engine") + ":", li)) # # Time liGen.append(SEPARADOR) config = FormLayout.Editbox(_("Duration of engine analysis (secs)"), 40, tipo=float) liGen.append((config, alm.tiempo / 1000.0)) # Depth liDepths = [("--", 0)] for x in range(1, 51): liDepths.append((str(x), x)) config = FormLayout.Combobox(_("Depth"), liDepths) liGen.append((config, alm.depth)) # Time+Depth liGen.append(("%s+%s:" % (_("Time"), _("Depth")), alm.timedepth)) # MultiPV liGen.append(SEPARADOR) 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))) config = FormLayout.Combobox( _("Number of moves evaluated by engine(MultiPV)"), li) liGen.append((config, alm.multiPV)) # Priority liGen.append(SEPARADOR) li = [(_("Normal"), EngineThread.PRIORITY_NORMAL), (_("Low"), EngineThread.PRIORITY_LOW), (_("Very low"), EngineThread.PRIORITY_VERYLOW), (_("High"), EngineThread.PRIORITY_HIGH), (_("Very high"), EngineThread.PRIORITY_VERYHIGH)] config = FormLayout.Combobox(_("Process priority"), li) liGen.append((config, alm.priority)) # Completo if siModoAmpliado: liGen.append(SEPARADOR) liJ = [(_("White"), "BLANCAS"), (_("Black"), "NEGRAS"), (_("White & Black"), "AMBOS")] config = FormLayout.Combobox(_("Analyze only color"), liJ) liGen.append((config, "AMBOS")) config = FormLayout.Editbox("<div align=\"right\">" + _("Moves") + "<br>" + _("By example:") + " -5,8-12,14,19-", rx="[0-9,\-,\,]*") liGen.append((config, "")) fvar = configuracion.ficheroBooks listaLibros = Books.ListaLibros() listaLibros.recuperaVar(fvar) # Comprobamos que todos esten accesibles listaLibros.comprueba() li = [("--", None)] defecto = listaLibros.lista[0] if alm.libro else None for libro in listaLibros.lista: if alm.libro == libro.nombre: defecto = libro li.append((libro.nombre, libro)) config = FormLayout.Combobox( _("Do not scan the opening moves based on book"), li) liGen.append((config, defecto)) liGen.append(SEPARADOR) liGen.append( (_("To redo any existing prior analyses (if they exist)") + ":", alm.siBorrarPrevio)) liGen.append( (_("Start from the end of the game") + ":", alm.desdeelfinal)) liGen.append(SEPARADOR) liGen.append((_("Show graphics") + ":", alm.showGraphs)) liVar = [SEPARADOR] liVar.append((_("Add analysis to variants") + ":", alm.masvariantes)) liVar.append(SEPARADOR) liVar.append((FormLayout.Spinbox(_("Minimum points lost"), 0, 1000, 60), alm.limitemasvariantes)) liVar.append(SEPARADOR) liVar.append((_("Only add better variant") + ":", alm.mejorvariante)) liVar.append(SEPARADOR) liVar.append((_("Include info about engine") + ":", alm.infovariante)) liVar.append(SEPARADOR) liVar.append( ("%s %s/%s/%s:" % (_("Format"), _("Points"), _("Depth"), _("Time")), alm.siPDT)) liVar.append(SEPARADOR) liVar.append( (_("Only one move of each variant") + ":", alm.unmovevariante)) liBlunders, liBrilliancies = formBlundersBrilliancies( alm, configuracion) liST = [SEPARADOR] liST.append((_("Activate") + ":", alm.stability)) liST.append(SEPARADOR) liST.append( (FormLayout.Spinbox(_("Last depths to control same best move"), 2, 10, 40), alm.st_depths)) liST.append(SEPARADOR) liST.append( (FormLayout.Spinbox(_("Maximum difference among last evaluations"), 0, 99999, 60), alm.st_centipawns)) liST.append(SEPARADOR) liST.append((FormLayout.Spinbox(_("Additional time limit"), 0, 99999, 60), alm.st_timelimit)) lista = [] lista.append((liGen, _("General options"), "")) lista.append((liVar, _("Variants"), "")) lista.append((liBlunders, _("Wrong moves"), "")) lista.append((liBrilliancies, _("Brilliancies"), "")) lista.append((liST, _("Stability control"), "")) else: lista = liGen reg = Util.Almacen() reg.form = None def dispatchR(valor): if reg.form is None: if isinstance(valor, FormLayout.FormTabWidget): reg.form = valor reg.wtime = valor.getWidget(0, 1) reg.wdepth = valor.getWidget(0, 2) reg.wdt = valor.getWidget(0, 3) elif isinstance(valor, FormLayout.FormWidget): reg.form = valor reg.wtime = valor.getWidget(1) reg.wdepth = valor.getWidget(2) reg.wdt = valor.getWidget(3) else: sender = reg.form.sender() if not reg.wdt.isChecked(): if sender == reg.wtime: if reg.wtime.textoFloat() > 0: reg.wdepth.setCurrentIndex(0) elif sender == reg.wdepth: if reg.wdepth.currentIndex() > 0: reg.wtime.ponFloat(0.0) elif sender == reg.wdt: if reg.wtime.textoFloat() > 0: reg.wdepth.setCurrentIndex(0) elif reg.wdepth.currentIndex() > 0: reg.wtime.ponFloat(0.0) QTUtil.refreshGUI() resultado = FormLayout.fedit(lista, title=_("Analysis Configuration"), parent=parent, anchoMinimo=460, icon=Iconos.Opciones(), dispatch=dispatchR) if resultado: accion, liResp = resultado if siModoAmpliado: liGen, liVar, liBlunders, liBrilliancies, liST = liResp else: liGen = liResp alm.motor = liGen[0] alm.tiempo = int(liGen[1] * 1000) alm.depth = liGen[2] alm.timedepth = liGen[3] alm.multiPV = liGen[4] alm.priority = liGen[5] if siModoAmpliado: color = liGen[6] alm.blancas = color != "NEGRAS" alm.negras = color != "BLANCAS" alm.jugadas = liGen[7] alm.libroAperturas = liGen[8] alm.libro = alm.libroAperturas.nombre if alm.libroAperturas else None alm.siBorrarPrevio = liGen[9] alm.desdeelfinal = liGen[10] alm.showGraphs = liGen[11] (alm.masvariantes, alm.limitemasvariantes, alm.mejorvariante, alm.infovariante, alm.siPDT, alm.unmovevariante) = liVar (alm.kblunders, alm.tacticblunders, alm.pgnblunders, alm.oriblunders, alm.bmtblunders) = liBlunders (alm.dpbrilliancies, alm.ptbrilliancies, alm.fnsbrilliancies, alm.pgnbrilliancies, alm.oribrilliancies, alm.bmtbrilliancies) = liBrilliancies (alm.stability, alm.st_depths, alm.st_centipawns, alm.st_timelimit) = liST dic = {} for x in dir(alm): if not x.startswith("__"): dic[x.upper()] = getattr(alm, x) Util.guardaVar(configuracion.ficheroAnalisis, dic) return alm else: return None
def __init__(self, wParent, listaMotores, motorExterno, siTorneo=False): super(WMotor, self).__init__(wParent) self.setWindowTitle(motorExterno.idName) self.setWindowIcon(Iconos.Motor()) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowMaximizeButtonHint) scrollArea = genOpcionesME(self, motorExterno) self.motorExterno = motorExterno self.liMotores = listaMotores if siTorneo else listaMotores.liMotores self.siTorneo = siTorneo # Toolbar tb = QTUtil2.tbAcceptCancel(self) lbAlias = Controles.LB(self, _("Alias") + ": ") self.edAlias = Controles.ED(self, motorExterno.alias).anchoMinimo(360) lbInfo = Controles.LB(self, _("Information") + ": ") self.emInfo = Controles.EM(self, motorExterno.idInfo, siHTML=False).anchoMinimo(360).altoFijo(60) lbElo = Controles.LB(self, "ELO" + ": ") self.sbElo = Controles.SB(self, motorExterno.elo, 0, 4000) if siTorneo: lbDepth = Controles.LB(self, _("Maximum depth") + ": ") self.sbDepth = Controles.SB(self, motorExterno.depth(), 0, 50) lbTime = Controles.LB(self, _("Maximum seconds to think") + ": ") self.sbTime = Controles.SB(self, motorExterno.time(), 0, 9999) lbBook = Controles.LB(self, _("Opening book") + ": ") fvar = VarGen.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.recuperaVar(fvar) # # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.nombre, x.path) for x in self.listaLibros.lista] li.insert(0, ("* " + _("Engine book"), "-")) li.insert(0, ("* " + _("Default"), "*")) self.cbBooks = Controles.CB(self, li, motorExterno.book()) btNuevoBook = Controles.PB(self, "", self.nuevoBook, plano=False).ponIcono(Iconos.Nuevo(), tamIcon=16) # # Respuesta rival li = ( (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp"), ) self.cbBooksRR = QTUtil2.comboBoxLB(self, li, motorExterno.bookRR()) lyBook = Colocacion.H().control(lbBook).control( self.cbBooks).control( self.cbBooksRR).control(btNuevoBook).relleno() lyDT = Colocacion.H().control(lbDepth).control( self.sbDepth).espacio(40).control(lbTime).control( self.sbTime).relleno() lyTorneo = Colocacion.V().otro(lyDT).otro(lyBook) # Layout ly = Colocacion.G() ly.controld(lbAlias, 0, 0).control(self.edAlias, 0, 1) ly.controld(lbInfo, 1, 0).control(self.emInfo, 1, 1) ly.controld(lbElo, 2, 0).control(self.sbElo, 2, 1) if siTorneo: ly.otro(lyTorneo, 3, 0, 1, 2) layout = Colocacion.V().control(tb).espacio(30).otro(ly).control( scrollArea) self.setLayout(layout) self.edAlias.setFocus()
def trainNewEngines(self): training = self.dbop.trainingEngines() color = "WHITE" basepv = self.dbop.basePV mandatory = basepv.count(" ") + 1 if len(basepv) > 0 else 0 control = 10 lost_points = 20 engine_control = self.configuracion.tutor.clave engine_time = 5.0 num_engines = 20 key_engine = "alaric" ext_engines = [] auto_analysis = True ask_movesdifferent = False times = [500, 1000, 2000, 4000, 8000] books = ["", "", "", "", ""] if training is not None: color = training["COLOR"] mandatory = training.get("MANDATORY", mandatory) control = training.get("CONTROL", control) lost_points = training.get("LOST_POINTS", lost_points) engine_control = training.get("ENGINE_CONTROL", engine_control) engine_time = training.get("ENGINE_TIME", engine_time) num_engines = training.get("NUM_ENGINES", num_engines) key_engine = training.get("KEY_ENGINE", key_engine) ext_engines = training.get("EXT_ENGINES", ext_engines) auto_analysis = training.get("AUTO_ANALYSIS", auto_analysis) ask_movesdifferent = training.get("ASK_MOVESDIFFERENT", ask_movesdifferent) times = training.get("TIMES", times) books = training.get("BOOKS", books) separador = FormLayout.separador liGen = [separador] liJ = [(_("White"), "WHITE"), (_("Black"), "BLACK")] config = FormLayout.Combobox(_("Play with"), liJ) liGen.append((config, color)) liGen.append((_("Mandatory moves") + ":", mandatory)) liGen.append(separador) liGen.append((_("Moves until the control") + ":", control)) liGen.append(separador) liGen.append( (_("Maximum number of lost centipawns to pass control") + ":", lost_points)) liGen.append(separador) dicRivales = self.configuracion.dicRivales dicRivales = EnginesBunch.filtra(dicRivales) config = FormLayout.Spinbox(_("Number of engines"), 0, len(dicRivales), 50) liGen.append((config, num_engines)) likeys = [(dicRivales[x].nombre, x) for x in dicRivales] likeys.sort(key=lambda x: x[1]) config = FormLayout.Combobox(_("Bunch of engines"), likeys) liGen.append((config, key_engine)) liGen.append(separador) config = FormLayout.Combobox(_("Engine that does the control"), self.configuracion.comboMotoresCompleto()) liGen.append((config, engine_control)) liGen.append( (_("Duration of analysis (secs)") + ":", float(engine_time))) liGen.append(separador) liGen.append((_("Automatic analysis") + ":", auto_analysis)) liGen.append(separador) liGen.append( (_("Ask when the moves are different from the line") + ":", ask_movesdifferent)) liMotoresExternos = self.configuracion.listaMotoresExternos( ordenados=False) if liMotoresExternos: liExt = [separador] for cm in liMotoresExternos: liExt.append((cm.nombre, cm.alias in ext_engines)) else: liExt = None liLevels = [separador] listaLibros = Books.ListaLibros() listaLibros.recuperaVar(self.configuracion.ficheroBooks) listaLibros.comprueba() libooks = [(bookx.nombre, bookx) for bookx in listaLibros.lista] libooks.insert(0, ("--", None)) for level in range(5): n = level + 1 title = "%s %d" % (_("Level"), n) liLevels.append((None, title)) tm = times[level] / 1000.0 if len(times) > level else 0.0 liLevels.append((_("Time engines think in seconds") + ":", tm)) bk = books[level] if len(books) > level else "" book = listaLibros.buscaLibro(bk) if bk else None config = FormLayout.Combobox(_("Book"), libooks) liLevels.append((config, book)) lista = [] lista.append((liGen, _("Basic data"), "")) if liExt: lista.append((liExt, _("External engines"), "")) lista.append((liLevels, _("Levels"), "")) resultado = FormLayout.fedit(lista, title=_("With engines"), parent=self, anchoMinimo=360, icon=Iconos.Study()) if resultado is None: return accion, liResp = resultado selMotoresExt = [] if liMotoresExternos: liGen, liExt, liLevels = liResp for x in range(len(liMotoresExternos)): if liExt[x]: selMotoresExt.append(liMotoresExternos[x].alias) else: liGen, liLevels = liResp reg = {} (reg["COLOR"], reg["MANDATORY"], reg["CONTROL"], reg["LOST_POINTS"], reg["NUM_ENGINES"], reg["KEY_ENGINE"], reg["ENGINE_CONTROL"], reg["ENGINE_TIME"], reg["AUTO_ANALYSIS"], reg["ASK_MOVESDIFFERENT"]) = liGen reg["EXT_ENGINES"] = selMotoresExt if (len(selMotoresExt) + reg["NUM_ENGINES"]) == 0: reg["NUM_ENGINES"] = 1 times = [] books = [] for x in range(5): tm = int(liLevels[x * 2] * 1000) bk = liLevels[x * 2 + 1] if tm: times.append(tm) books.append(bk.nombre if bk else "") if len(times) == 0: times.append(500) books.append(None) reg["TIMES"] = times reg["BOOKS"] = books self.dbop.createTrainingEngines(reg, self.procesador) QTUtil2.mensaje(self, _("Created"))
def __init__(self, procesador): wParent = procesador.pantalla self.configuracion = procesador.configuracion self.procesador = procesador self.siCambios = False QtGui.QDialog.__init__(self, wParent) self.setWindowTitle(_("Training with a book")) self.setWindowIcon(Iconos.Libros()) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinimizeButtonHint) self.setMinimumWidth(450) flb = Controles.TipoLetra(puntos=10) # Variables antiguas dic = self.recuperaDIC() if dic is None: dic = {} dic_siBlancas = dic.get("SIBLANCAS", True) dic_nomLibro = dic.get("NOMLIBRO", "") dic_RR = dic.get("RR", "au") dic_RJ = dic.get("RJ", False) # Toolbar liAcciones = [(_("Accept"), Iconos.Aceptar(), "aceptar"), None, (_("Cancel"), Iconos.Cancelar(), "cancelar"), None, ] tb = Controles.TB(self, liAcciones) # Color self.rbBlancas = QtGui.QRadioButton(_("White")) self.rbBlancas.setChecked(dic_siBlancas) self.rbNegras = QtGui.QRadioButton(_("Black")) self.rbNegras.setChecked(not dic_siBlancas) hbox = Colocacion.H().relleno().control(self.rbBlancas).espacio(10).control(self.rbNegras).relleno() gbColor = Controles.GB(self, _("Play with"), hbox).ponFuente(flb) # Libros fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.recuperaVar(fvar) # # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.nombre, x) for x in self.listaLibros.lista] libInicial = None if dic_nomLibro: for nom, libro in li: if nom == dic_nomLibro: libInicial = libro break if libInicial is None: libInicial = li[0][1] if li else None self.cb = QTUtil2.comboBoxLB(self, li, libInicial) btNuevo = Controles.PB(self, "", self.nuevo, plano=False).ponIcono(Iconos.Nuevo(), tamIcon=16) btBorrar = Controles.PB(self, "", self.borrar, plano=False).ponIcono(Iconos.Borrar(), tamIcon=16) hbox = Colocacion.H().relleno().control(self.cb).control(btNuevo).control(btBorrar).relleno() gbLibro = Controles.GB(self, _("Book"), hbox).ponFuente(flb) # Respuesta rival li = ( (_("Selected by the player"), "su"), (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp"), ) self.cbRR = QTUtil2.comboBoxLB(self, li, dic_RR) hbox = Colocacion.H().relleno().control(self.cbRR).relleno() gbRR = Controles.GB(self, _("Opponent's move"), hbox).ponFuente(flb) # Respuesta jugador self.chRJ = Controles.CHB(self, _("Always the highest percentage"), dic_RJ) hbox = Colocacion.H().relleno().control(self.chRJ).relleno() gbRJ = Controles.GB(self, _("Player's move"), hbox).ponFuente(flb) vlayout = Colocacion.V() vlayout.control(gbColor).espacio(5) vlayout.control(gbLibro).espacio(5) vlayout.control(gbRR).espacio(5) vlayout.control(gbRJ) vlayout.margen(20) layout = Colocacion.V().control(tb).otro(vlayout).margen(3) self.setLayout(layout)
def __init__(self, procesador): self.configuracion = procesador.configuracion self.procesador = procesador self.dbHisto = Util.DicSQL(self.configuracion.ficheroGMhisto) self.bloqueApertura = None self.liAperturasFavoritas = [] wParent = procesador.pantalla titulo = _("Play like a grandmaster") icono = Iconos.GranMaestro() extparam = "gm" QTVarios.WDialogo.__init__(self, wParent, titulo, icono, extparam) flb = Controles.TipoLetra(puntos=10) # Toolbar liAcciones = [(_("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, liAcciones) # Grandes maestros self.liGM = GM.listaGM() li = [(x[0], x[1]) for x in self.liGM] li.insert(0, ("-", None)) self.cbGM = QTUtil2.comboBoxLB(self, li, li[0][1] if len(self.liGM) == 0 else li[1][1]) self.cbGM.capturaCambiado(self.compruebaGM) hbox = Colocacion.H().relleno().control(self.cbGM).relleno() gbGM = Controles.GB(self, _("Choose a grandmaster"), hbox).ponFuente(flb) # Personales self.liPersonal = GM.listaGMpersonal(self.procesador.configuracion.dirPersonalTraining) if self.liPersonal: li = [(x[0], x[1]) for x in self.liPersonal] li.insert(0, ("-", None)) self.cbPersonal = QTUtil2.comboBoxLB(self, li, li[0][1]) self.cbPersonal.capturaCambiado(self.compruebaP) btBorrar = Controles.PB(self, "", self.borrarPersonal, plano=False).ponIcono(Iconos.Borrar(), tamIcon=16) hbox = Colocacion.H().relleno().control(self.cbPersonal).control(btBorrar).relleno() gbPersonal = Controles.GB(self, _("Personal games"), hbox).ponFuente(flb) # Color self.rbBlancas = Controles.RB(self, _("White"), rutina=self.compruebaColor) self.rbBlancas.activa(True) self.rbNegras = Controles.RB(self, _("Black"), rutina=self.compruebaColor) self.rbNegras.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.configuracion.comboMotoresMultiPV10() self.cbJmotor, self.lbJmotor = QTUtil2.comboBoxLB(self, self.liMotores, self.configuracion.tutorInicial, _("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).capturaCambiado(self.cambiadoDepth) self.lbJdepth = Controles.LB2P(self, _("Depth")) self.lbJshow = Controles.LB2P(self, _("Show rating")) self.chbEvals = Controles.CHB(self, _("Show all evaluations"), False) liOptions = [(_("All moves"), None), (_("Moves are different"), True), (_("Never"), False)] self.cbJshow = Controles.CB(self, liOptions, 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") # Inicial self.edJugInicial, lbInicial = QTUtil2.spinBoxLB(self, 1, 1, 99, etiqueta=_("Initial move"), maxTam=40) # Libros fvar = self.configuracion.ficheroBooks self.listaLibros = Books.ListaLibros() self.listaLibros.recuperaVar(fvar) # # Comprobamos que todos esten accesibles self.listaLibros.comprueba() li = [(x.nombre, x) for x in self.listaLibros.lista] li.insert(0, ("--", None)) self.cbBooks, lbBooks = QTUtil2.comboBoxLB(self, li, None, _("Bypass moves in the book")) # Aperturas self.btApertura = Controles.PB(self, " " * 5 + _("Undetermined") + " " * 5, self.aperturasEditar).ponPlano( False) self.btAperturasFavoritas = Controles.PB(self, "", self.aperturasFavoritas).ponIcono(Iconos.Favoritos()) self.btAperturasQuitar = Controles.PB(self, "", self.aperturasQuitar).ponIcono(Iconos.Motor_No()) hbox = Colocacion.H().control(self.btAperturasQuitar).control(self.btApertura).control( self.btAperturasFavoritas).relleno() gbOpening = Controles.GB(self, _("Opening"), hbox) # gbBasic # # Color hbox = Colocacion.H().relleno().control(self.rbBlancas).espacio(10).control(self.rbNegras).relleno() gbColor = Controles.GB(self, _("Play with"), hbox).ponFuente(flb) # Tiempo ly1 = Colocacion.H().control(self.lbJmotor).control(self.cbJmotor).control(self.lbJshow).control( self.cbJshow).relleno() ly2 = Colocacion.H().control(self.lbJtiempo).control(self.edJtiempo) ly2.control(self.lbJdepth).control(self.cbJdepth).espacio(15).control(self.chbEvals).relleno() 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).conectar(self.cambiaJuez) # 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().relleno().otro(lyInicial).control(gbOpening) vlayout.espacio(5).control(self.chContrario).margen(20).relleno() gbAdvanced = Controles.GB(self, "", vlayout) gbAdvanced.setFlat(True) # Historico self.liHisto = [] oColumnas = Columnas.ListaColumnas() oColumnas.nueva("FECHA", _("Date"), 80, siCentrado=True) oColumnas.nueva("PACIERTOS", _("Hints"), 90, siCentrado=True) oColumnas.nueva("PUNTOS", _("Points accumulated"), 120, siCentrado=True) oColumnas.nueva("ENGINE", _("Adjudicator"), 100, siCentrado=True) oColumnas.nueva("RESUMEN", _("Game played"), 150) self.grid = grid = Grid.Grid(self, oColumnas, siSelecFilas=True, background=None) self.grid.coloresAlternados() self.registrarGrid(grid) # Tabs self.tab = Controles.Tab().ponPosicion("S") self.tab.nuevaTab(gbBasic, _("Basic")) self.tab.nuevaTab(gbAdvanced, _("Advanced")) self.tab.nuevaTab(self.grid, _("Track record")) # Cabecera lyCab = Colocacion.H().control(gbGM) if self.liPersonal: lyCab.control(gbPersonal) layout = Colocacion.V().control(tb).otro(lyCab).control(self.tab).margen(3) self.setLayout(layout) self.recuperaDic() self.cambiaJuez() self.compruebaGM() self.compruebaP() self.compruebaHisto() self.aperturaMuestra() self.btAperturasFavoritas.hide() self.recuperarVideo(anchoDefecto=450)