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 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)
Exemple #3
0
 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
Exemple #4
0
 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)
Exemple #5
0
    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()
Exemple #6
0
    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")
Exemple #7
0
 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)
Exemple #8
0
 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()
Exemple #10
0
 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)
Exemple #11
0
    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 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()
Exemple #13
0
    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)
Exemple #14
0
    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.configuration.buscaRival(self.torneo.adjudicator())
            self.xadjudicator = EngineManager.EngineManager(self, conf_engine)
            self.xadjudicator.options(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].set_text(rival[side].key)

        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].options(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.Book("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.board.disable_all()
        self.board.set_position(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.play_next_move():
            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()
Exemple #15
0
    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()
Exemple #16
0
    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()
Exemple #17
0
    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 = "&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()