コード例 #1
0
ファイル: WindowGM.py プロジェクト: gamaBHC/lucaschessR
 def importar(self):
     if importar_gm(self):
         liC = GM.lista_gm()
         self.cb_gm.clear()
         for tp in liC:
             self.cb_gm.addItem(tp[0], tp[1])
         self.cb_gm.setCurrentIndex(0)
コード例 #2
0
    def grabaDic(self):
        rk = Util.Record()
        rk.gm = self.cb_gm.valor()
        if rk.gm is None:
            rk.modo = "personal"
            rk.gm = self.cbPersonal.valor()
            if rk.gm is None:
                return False
        else:
            rk.modo = "estandar"
        rk.gameElegida = None
        rk.is_white = self.rb_white.isChecked()
        rk.with_adjudicator = self.gbJ.isChecked()
        rk.show_evals = self.chbEvals.valor()
        rk.engine = self.cbJmotor.valor()
        rk.vtime = int(self.edJtiempo.textoFloat() * 10)
        rk.mostrar = self.cbJshow.valor()
        rk.depth = self.cbJdepth.valor()
        rk.multiPV = self.cbJmultiPV.valor()
        rk.select_rival_move = self.ch_select_rival_move.isChecked()
        rk.jugInicial = self.edJugInicial.valor()
        if rk.with_adjudicator and rk.vtime <= 0 and rk.depth == 0:
            rk.with_adjudicator = False
        rk.bypass_book = self.cbBooks.valor()
        rk.opening = self.opening_block

        default = Code.path_resource("GM")

        carpeta = default if rk.modo == "estandar" else self.configuration.personal_training_folder
        self.ogm = GM.GM(carpeta, rk.gm)
        self.ogm.filter_side(rk.is_white)
        if not len(self.ogm):
            QTUtil2.message_error(
                self, _("There are no games to play with this color"))
            return False

        self.ogm.isErasable = rk.modo == "personal"  # para saber si se puede borrar
        self.record = rk
        dic = {}

        for atr in dir(self.record):
            if not atr.startswith("_"):
                dic[atr.upper()] = getattr(self.record, atr)
        dic["APERTURASFAVORITAS"] = self.li_preferred_openings

        Util.save_pickle(self.configuration.file_gms(), dic)

        return True
コード例 #3
0
ファイル: WindowGM.py プロジェクト: gamaBHC/lucaschessR
    def borrarPersonal(self):
        tgm = self.cbPersonal.valor()
        if tgm is None:
            return
        if not QTUtil2.pregunta(self, _X(_("Delete %1?"), tgm)):
            return

        base = os.path.join(self.configuration.personal_training_folder, "%s.gm" % tgm)
        for x in "wbi":
            Util.remove_file(base + x)

        self.li_personal = GM.lista_gm_personal(self.configuration.personal_training_folder)

        li = [(x[0], x[1]) for x in self.li_personal]
        li.insert(0, ("-", None))
        self.cbPersonal.rehacer(li, li[0][1])

        self.check_personal()
コード例 #4
0
    def __init__(self, wgm, ogm):
        self.ogm = ogm
        self.liRegs = ogm.gen_toselect()
        self.si_reverse = False
        self.claveSort = None

        dgm = GM.dic_gm()
        name = dgm.get(ogm.gm, ogm.gm)
        titulo = "%s - %s" % (_("One game"), name)
        icono = Iconos.Uno()
        extparam = "gm1g"
        QTVarios.WDialogo.__init__(self, wgm, titulo, icono, extparam)

        o_columns = Columnas.ListaColumnas()
        o_columns.nueva("NOMBRE", _("Opponent"), 180)
        o_columns.nueva("FECHA", _("Date"), 90, centered=True)
        o_columns.nueva("EVENT", _("Event"), 140, centered=True)
        o_columns.nueva("ECO", _("ECO"), 40, centered=True)
        o_columns.nueva("RESULT", _("Result"), 64, centered=True)
        self.grid = Grid.Grid(self,
                              o_columns,
                              siSelecFilas=True,
                              siSeleccionMultiple=True)
        nAnchoPgn = self.grid.anchoColumnas() + 20
        self.grid.setMinimumWidth(nAnchoPgn)
        self.grid.coloresAlternados()

        self.register_grid(self.grid)

        li_acciones = [(_("Accept"), Iconos.Aceptar(), self.aceptar), None,
                       (_("Cancel"), Iconos.Cancelar(), self.cancelar), None]
        if ogm.isErasable:
            li_acciones.append((_("Remove"), Iconos.Borrar(), self.remove))
            li_acciones.append(None)

        tb = Controles.TBrutina(self, li_acciones)

        layout = Colocacion.V().control(tb).control(self.grid).margen(3)
        self.setLayout(layout)

        self.restore_video(anchoDefecto=400)
        self.gameElegida = None
コード例 #5
0
ファイル: WindowGM.py プロジェクト: gamaBHC/lucaschessR
    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)
コード例 #6
0
    def base_inicio(self, record):
        self.game_type = GT_AGAINST_GM

        self.hints = 9999  # Para que analice sin problemas

        self.puntos = 0

        self.record = record

        self.gm = record.gm
        self.is_white = record.is_white
        self.modo = record.modo
        self.with_adjudicator = record.with_adjudicator
        self.show_evals = record.show_evals
        self.engine = record.engine
        self.vtime = record.vtime
        self.depth = record.depth
        self.multiPV = record.multiPV
        self.mostrar = record.mostrar
        self.select_rival_move = record.select_rival_move
        self.jugInicial = record.jugInicial
        self.gameElegida = record.gameElegida
        self.bypass_book = record.bypass_book
        self.opening = record.opening
        self.on_bypass_book = True if self.bypass_book else False
        if self.on_bypass_book:
            self.bypass_book.polyglot()
        self.on_opening = True if self.opening else False

        self.siAnalizando = False

        if self.with_adjudicator:
            self.puntos = 0
            tutor = self.configuration.buscaRival(self.engine)
            t_t = self.vtime * 100
            self.xtutor = self.procesador.creaManagerMotor(
                tutor, t_t, self.depth)
            self.xtutor.set_multipv(self.multiPV)
            self.analysis = None
            self.continueTt = not Code.configuration.x_engine_notbackground

        self.book = Opening.OpeningPol(999)

        self.thinking(True)

        default = Code.path_resource("GM")
        carpeta = default if self.modo == "estandar" else self.configuration.personal_training_folder
        self.motorGM = GM.GM(carpeta, self.gm)
        self.motorGM.filter_side(self.is_white)
        if self.gameElegida is not None:
            self.motorGM.set_game_selected(self.gameElegida)

        self.human_side = self.is_white
        self.is_engine_side_white = not self.is_white
        self.thinking(False)

        self.main_window.pon_toolbar(
            (TB_CLOSE, TB_REINIT, TB_ADJOURN, TB_CONFIG, TB_UTILITIES))
        self.main_window.activaJuego(True, 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_white)
        dic = GM.dic_gm()
        self.nombreGM = dic[
            self.gm.lower()] if self.modo == "estandar" else self.gm
        rot = _("Grandmaster")
        rotulo1 = rot + ": <b>%s</b>" if self.modo == "estandar" else "<b>%s</b>"
        self.set_label1(rotulo1 % self.nombreGM)

        self.rival_name = ""
        self.textoPuntuacion = ""
        self.ponRotuloSecundario()
        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()

        self.state = ST_PLAYING

        self.check_boards_setposition()

        self.play_next_move()