def start(self, dbwashing, washing, engine):
        self.dbwashing = dbwashing
        self.washing = washing
        self.engine = engine

        self.dbwashing.add_game()

        self.game_type = GT_WASHING_REPLAY

        self.human_is_playing = False

        self.is_tutor_enabled = False
        self.main_window.set_activate_tutor(False)
        self.ayudas_iniciales = 0

        self.main_window.activaJuego(True, False, siAyudas=False)
        self.main_window.remove_hints(True, True)
        self.set_dispatcher(self.player_has_moved)
        self.show_side_indicator(True)

        self.gameObj = self.dbwashing.restoreGame(self.engine)
        self.numJugadasObj = self.gameObj.num_moves()
        self.posJugadaObj = 0

        li_options = [TB_CLOSE]
        self.main_window.pon_toolbar(li_options)

        self.errores = 0

        self.book = Opening.OpeningPol(999, elo=engine.elo)

        is_white = self.engine.color
        self.human_side = is_white
        self.is_engine_side_white = not is_white
        self.set_position(self.game.last_position)
        self.put_pieces_bottom(is_white)

        self.set_label1(
            "%s: %s\n%s: %s" %
            (_("Rival"), self.engine.name, _("Task"), self.engine.lbState()))

        self.pgnRefresh(True)

        self.game.pending_opening = True
        self.game.set_tag("Event", _("The Washing Machine"))

        player = self.configuration.nom_player()
        other = self.engine.name
        w, b = (player, other) if self.human_side else (other, player)
        self.game.set_tag("White", w)
        self.game.set_tag("Black", b)
        QTUtil.refresh_gui()

        self.check_boards_setposition()

        self.state = ST_PLAYING

        self.play_next_move()
    def start(self, recno, is_white):

        db = WindowPlayGame.DBPlayGame(self.configuration.file_play_game())
        reg = db.leeRegistro(recno)
        gameObj = Game.Game()
        gameObj.restore(reg["GAME"])
        nombreObj = gameObj.get_tag("WHITE" if is_white else "BLACK")
        label = db.label(recno)
        db.close()

        self.recno = recno
        self.resultado = None
        self.human_is_playing = False
        self.analysis = None
        self.comment = None
        self.siAnalizando = False
        self.human_side = is_white
        self.is_engine_side_white = not is_white
        self.numJugadasObj = gameObj.num_moves()
        self.gameObj = gameObj
        self.posJugadaObj = 0
        self.nombreObj = nombreObj

        self.siSave = False
        self.minTiempo = 5000

        self.xanalyzer.maximizaMultiPV()

        self.puntosMax = 0
        self.puntos = 0
        self.vtime = 0.0

        self.book = Opening.OpeningPol(999)

        self.main_window.pon_toolbar(
            (TB_CANCEL, TB_REINIT, TB_CONFIG, TB_UTILITIES))

        self.main_window.activaJuego(True, False, siAyudas=False)
        self.remove_hints(True, True)

        self.set_dispatcher(self.player_has_moved)
        self.set_position(self.game.last_position)
        self.put_pieces_bottom(self.human_side)
        self.show_side_indicator(True)
        self.set_label1(label)
        self.set_label2("")

        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()
        self.check_boards_setposition()

        self.state = ST_PLAYING
        self.play_next_move()
 def takeback(self):
     if len(self.game):
         self.analizaTerminar()
         self.game.anulaUltimoMovimiento(self.human_side)
         self.game.assign_opening()
         self.goto_end()
         self.opening = Opening.OpeningPol(30, self.engine.elo)
         self.is_analyzed_by_tutor = False
         self.add_hint()
         self.add_time()
         self.refresh()
         self.play_next_move()
Пример #4
0
    def base_inicio(self, id_game):
        self.resultado = None
        self.human_is_playing = False
        self.state = ST_PLAYING
        self.analysis = None
        self.comment = None
        self.siAnalizando = False

        self.is_competitive = True

        self.read_id(id_game)
        self.id_game = id_game

        self.eloObj = int(
            self.game.get_tag("WhiteElo" if self.human_side else "BlackElo"))
        self.eloUsu = self._activo()

        self.pwin = Util.fideELO(self.eloUsu, self.eloObj, +1)
        self.pdraw = Util.fideELO(self.eloUsu, self.eloObj, 0)
        self.plost = Util.fideELO(self.eloUsu, self.eloObj, -1)

        self.puntos = 0

        self.is_tutor_enabled = False
        self.main_window.set_activate_tutor(self.is_tutor_enabled)

        self.hints = 0
        self.ayudas_iniciales = 0

        self.xtutor.maximizaMultiPV()

        self.book = Opening.OpeningPol(999)

        self.pon_toolbar()

        self.main_window.activaJuego(True, False, siAyudas=False)
        self.set_dispatcher(self.player_has_moved)
        self.set_position(self.game.last_position)
        self.put_pieces_bottom(self.human_side)
        self.remove_hints(True, siQuitarAtras=True)
        self.show_side_indicator(True)
        label = "%s: <b>%d</b> | %s: <b>%d</b>" % (self._titulo, self.eloUsu,
                                                   _("Elo rival"), self.eloObj)
        label += " | %+d %+d %+d" % (self.pwin, self.pdraw, self.plost)
        self.set_label1(label)

        self.set_label2("")
        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()

        self.check_boards_setposition()
Пример #5
0
    def start(self, recno):

        self.expedition = Everest.Expedition(self.configuration, recno)
        self.expedition.run()

        self.dic_analysis = {}

        self.is_competitive = True
        self.resultado = None
        self.human_is_playing = False
        self.analysis = None
        self.comment = None
        self.siAnalizando = False
        self.human_side = self.expedition.is_white
        self.is_engine_side_white = not self.expedition.is_white
        self.gameObj = self.expedition.game
        self.game.set_tags(self.gameObj.li_tags)
        self.numJugadasObj = self.gameObj.num_moves()
        self.posJugadaObj = 0
        self.nombreObj = self.expedition.name

        self.xanalyzer.maximize_multipv()

        self.puntos = 0
        self.vtime = 0.0

        self.book = Opening.OpeningPol(999)

        self.main_window.pon_toolbar((TB_CANCEL, TB_REINIT, TB_CONFIG))

        self.main_window.activaJuego(True, False, siAyudas=False)
        self.remove_hints(True, True)

        self.set_dispatcher(self.player_has_moved)
        self.set_position(self.game.last_position)
        self.put_pieces_bottom(self.human_side)
        self.show_side_indicator(True)
        self.set_label1(self.expedition.label())
        self.set_label2("")

        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()
        self.check_boards_setposition()

        self.state = ST_PLAYING
        self.play_next_move()
Пример #6
0
    def reiniciar(self):
        self.game.set_position()
        self.posJugadaObj = 0
        self.puntos = 0
        self.ponPuntos()
        self.vtime = 0.0
        self.book = Opening.OpeningPol(999)
        self.state = ST_PLAYING
        self.board.set_position(self.game.first_position)
        self.pgnRefresh(True)
        self.check_boards_setposition()
        self.analizaFinal()
        self.terminaNoContinuo()

        self.set_label1(self.expedition.label())
        self.ponPuntos()
        self.play_next_move()
    def reiniciar(self, siPregunta):
        if siPregunta:
            if not QTUtil2.pregunta(self.main_window, _("Restart the game?")):
                return

        self.game.set_position()
        self.posJugadaObj = 0
        self.puntos = 0
        self.puntosMax = 0
        self.ponPuntos()
        self.vtime = 0.0
        self.book = Opening.OpeningPol(999)
        self.state = ST_PLAYING
        self.board.set_position(self.game.first_position)
        self.pgnRefresh(True)
        self.check_boards_setposition()
        self.analizaFinal()

        self.play_next_move()
Пример #8
0
    def calc_elosFORM(self, configuration):
        for move in self.li_moves:
            move.is_book = False
        if self.siFenInicial():
            ap = Opening.OpeningPol(999)
            for move in self.li_moves:
                move.is_book = ap.check_human(move.position_before.fen(),
                                              move.from_sq, move.to_sq)
                if not move.is_book:
                    break

        elos = {}
        for is_white in (True, False):
            elos[is_white] = self.calc_elo_colorFORM(configuration.perfomance,
                                                     is_white)

        elos[None] = {}
        for std in (OPENING, MIDDLEGAME, ENDGAME, ALLGAME):
            elos[None][std] = int((elos[True][std] + elos[False][std]) / 2.0)

        return elos
Пример #9
0
    def base_inicio(self, datos_motor):
        self.game_type = GT_ELO

        self.is_competitive = True

        self.resultado = None
        self.human_is_playing = False
        self.state = ST_PLAYING

        is_white = self.determina_side(datos_motor)

        self.human_side = is_white
        self.is_engine_side_white = not is_white

        self.lirm_engine = []
        self.next_test_resign = 5
        self.resign_limit = -1000

        self.is_tutor_enabled = False
        self.main_window.set_activate_tutor(self.is_tutor_enabled)

        self.hints = 0
        self.ayudas_iniciales = self.hints

        self.in_the_opening = True

        self.datosMotor = datos_motor
        self.opening = Opening.OpeningPol(100, elo=self.datosMotor.elo)

        eloengine = self.datosMotor.elo
        eloplayer = self.configuration.eloActivo()
        self.whiteElo = eloplayer if is_white else eloengine
        self.blackElo = eloplayer if not is_white else eloengine

        self.siRivalInterno = self.datosMotor.siInterno
        if self.siRivalInterno:
            rival = self.configuration.buscaRival("irina")
            depth = 2 if self.datosMotor.key in ("Rat", "Snake") else 1
            self.xrival = self.procesador.creaManagerMotor(rival, None, depth)
            self.xrival.set_option("Personality", self.datosMotor.key)

        else:
            rival = self.configuration.buscaRival(self.datosMotor.key)
            self.xrival = self.procesador.creaManagerMotor(rival, None, self.datosMotor.depth)

        self.pte_tool_resigndraw = True

        self.pon_toolbar()

        self.main_window.activaJuego(True, False, 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)
        label = "%s: <b>%s</b>" % (_("Opponent"), self.datosMotor.label())
        self.set_label1(label)

        nbsp = "&nbsp;" * 3

        txt = "%s:%+d%s%s:%+d%s%s:%+d" % (
            _("Win"),
            self.datosMotor.pgana,
            nbsp,
            _("Draw"),
            self.datosMotor.ptablas,
            nbsp,
            _("Loss"),
            self.datosMotor.ppierde,
        )

        self.set_label2("<center>%s</center>" % txt)
        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()

        self.check_boards_setposition()

        self.game.add_tag("Event", _("Lucas-Elo"))

        player = self.configuration.nom_player()
        other = self.datosMotor.name
        w, b = (player, other) if self.human_side else (other, player)
        self.game.add_tag("White", w)
        self.game.add_tag("Black", b)
Пример #10
0
    def base_inicio(self, categorias, categoria, nivel, is_white, puntos):
        self.game_type = GT_COMPETITION_WITH_TUTOR

        self.liReiniciar = categoria, nivel, is_white

        self.dbm = CompetitionWithTutor.DBManagerCWT()

        self.resultado = None
        self.human_is_playing = False
        self.state = ST_PLAYING

        self.is_competitive = True

        self.plays_instead_of_me_option = True

        self.human_side = is_white
        self.is_engine_side_white = not is_white

        self.rm_rival = None

        self.categorias = categorias
        self.categoria = categoria
        self.nivelJugado = nivel
        self.puntos = puntos

        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.tutor_book = Books.BookGame(Code.tbook)

        self.hints = categoria.hints
        self.ayudas_iniciales = self.hints  # Se guarda para guardar el PGN

        self.in_the_opening = True
        self.opening = Opening.OpeningPol(nivel)  # lee las aperturas

        self.rival_conf = self.dbm.get_current_rival()
        self.xrival = self.procesador.creaManagerMotor(self.rival_conf, None,
                                                       nivel)

        self.main_window.pon_toolbar(
            (TB_CANCEL, TB_RESIGN, TB_TAKEBACK, 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.put_pieces_bottom(is_white)
        self.ponAyudas(self.hints)
        self.show_side_indicator(True)
        label = "%s: %s\n%s %s %d" % (_("Opponent"), self.xrival.name,
                                      categoria.name(), _("Level"), nivel)
        if self.puntos:
            label += " (+%d %s)" % (self.puntos, _("points"))
        self.set_label1(label)
        self.xrotulo2()

        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()

        self.game.set_tag("Event", _("Competition with tutor"))

        player = self.configuration.nom_player()
        other = "%s (%s %d)" % (self.xrival.name, _("Level"), self.nivelJugado)
        w, b = (player, other) if self.human_side else (other, player)
        self.game.set_tag("White", w)
        self.game.set_tag("Black", b)

        self.is_analyzed_by_tutor = False

        self.check_boards_setposition()

        self.game.tag_timestart()
Пример #11
0
    def start(self, resistance, numEngine, key):

        self.game_type = GT_RESISTANCE

        self.resistance = resistance
        self.numEngine = numEngine
        self.key = key
        is_white = "WHITE" in key
        self.segundos, self.puntos, self.maxerror = resistance.actual()
        self.movimientos = 0
        self.puntosRival = 0

        self.human_is_playing = False
        self.state = ST_PLAYING

        self.human_side = is_white
        self.is_engine_side_white = not is_white

        self.siBoxing = True

        self.rm_rival = None

        self.in_the_opening = False
        self.opening = Opening.OpeningPol(5)  # lee las aperturas

        # debe hacerse antes que rival
        self.xarbitro = self.procesador.creaManagerMotor(
            self.configuration.tutor, self.segundos * 1000, None)
        self.xarbitro.anulaMultiPV()

        engine = resistance.dameClaveEngine(numEngine)
        rival = self.configuration.buscaRival(engine)
        self.xrival = self.procesador.creaManagerMotor(rival,
                                                       self.segundos * 1000,
                                                       None)

        self.main_window.pon_toolbar(
            (TB_RESIGN, TB_REINIT, TB_CONFIG, TB_UTILITIES))
        self.main_window.activaJuego(True, False, 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()
        self.set_activate_tutor(False)
        self.show_side_indicator(True)
        self.ponRotuloObjetivo()
        self.ponRotuloActual()
        self.pgnRefresh(True)
        self.ponCapInfoPorDefecto()
        self.check_boards_setposition()

        tp = self.resistance.tipo
        if tp:
            b = n = False
            if tp == "p2":
                if is_white:
                    b = True
                else:
                    n = True
            elif tp == "p1":
                if is_white:
                    n = True
                else:
                    b = True
            self.board.mostrarPiezas(b, n)

        self.play_next_move()
Пример #12
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()
    def start(self, dbwashing, washing, engine):
        self.dbwashing = dbwashing
        self.washing = washing

        self.engine = engine

        self.game_type = GT_WASHING_CREATE

        self.resultado = None
        self.human_is_playing = False
        self.state = ST_PLAYING

        is_white = self.engine.color
        self.human_side = is_white
        self.is_engine_side_white = not is_white
        self.is_competitive = True

        self.opening = Opening.OpeningPol(30, self.engine.elo)

        self.is_tutor_enabled = True
        self.siAnalizando = False
        # self.main_window.set_activate_tutor(self.is_tutor_enabled)

        rival = self.configuration.buscaRival(self.engine.key)

        self.xrival = self.procesador.creaManagerMotor(rival, None, None)
        self.xrival.is_white = self.is_engine_side_white
        self.rm_rival = None
        self.tmRival = 15.0 * 60.0 * engine.elo / 3000.0

        self.xtutor.maximizaMultiPV()
        self.is_analyzed_by_tutor = False

        self.main_window.activaJuego(True, False, False)
        self.remove_hints()
        li = [TB_CLOSE, TB_REINIT, TB_TAKEBACK]
        self.main_window.pon_toolbar(li)
        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.set_label1("%s: %s\n%s: %s\n %s: %s" %
                        (_("Rival"), self.engine.name, _("Task"),
                         self.engine.lbState(), _("Tutor"), self.xtutor.name))
        self.ponRotuloDatos()

        self.ponCapInfoPorDefecto()

        self.pgnRefresh(True)

        game = dbwashing.restoreGame(engine)
        if not (game is None):
            if not game.is_finished():
                self.game = game
                self.goto_end()
                self.main_window.base.pgnRefresh()
        else:
            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.check_boards_setposition()

        self.play_next_move()
Пример #14
0
    def base_inicio(self, dic_var):
        self.reinicio = dic_var

        self.cache = dic_var.get("cache", {})

        self.game_type = GT_AGAINST_CHILD_ENGINE

        self.human_is_playing = False
        self.plays_instead_of_me_option = True
        self.state = ST_PLAYING

        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

        w, b = self.configuration.nom_player(), _F(dic_var["RIVAL"])
        if not is_white:
            w, b = b, w
        self.game.set_tag("Event", _("Opponents for young players"))
        self.game.set_tag("White", w)
        self.game.set_tag("Black", b)

        self.with_takeback = True

        cmrival = self.configuration.buscaRival("irina", None)
        self.xrival = self.procesador.creaManagerMotor(cmrival, None, 2)
        self.rival_name = dic_var["RIVAL"]
        self.xrival.set_option("Personality", self.rival_name)
        if not dic_var["FASTMOVES"]:
            self.xrival.set_option("Max Time", "5")
            self.xrival.set_option("Min Time", "1")
        self.xrival.name = _F(self.rival_name)

        self.lirm_engine = []
        self.next_test_resign = 0
        self.resign_limit = -99999  # never

        self.aperturaObl = self.aperturaStd = None

        self.human_is_playing = False
        self.state = ST_PLAYING
        self.siAnalizando = False

        self.aperturaStd = Opening.OpeningPol(1)

        self.set_dispatcher(self.player_has_moved)
        self.main_window.set_notify(self.mueve_rival_base)

        self.thinking(True)

        self.main_window.set_activate_tutor(False)

        self.hints = 0
        self.ayudas_iniciales = 0

        self.xrival.is_white = self.is_engine_side_white

        self.siTiempo = dic_var["SITIEMPO"]
        if self.siTiempo:
            self.maxSegundos = dic_var["MINUTOS"] * 60.0
            self.segundosJugada = dic_var["SEGUNDOS"]
            self.secs_extra = dic_var.get("MINEXTRA", 0) * 60.0

            self.vtime = {
                WHITE: Util.Timer(self.maxSegundos),
                BLACK: Util.Timer(self.maxSegundos)
            }

            time_control = "%d" % int(self.maxSegundos)
            if self.segundosJugada:
                time_control += "+%d" % self.segundosJugada
            self.game.set_tag("TimeControl", time_control)

        self.thinking(False)

        li = [
            TB_CANCEL, TB_RESIGN, TB_TAKEBACK, TB_REINIT, TB_ADJOURN, TB_PAUSE,
            TB_CONFIG, TB_UTILITIES
        ]
        self.main_window.pon_toolbar(li)

        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)
        self.remove_hints(True, siQuitarAtras=False)
        self.put_pieces_bottom(is_white)

        imagen = getattr(Iconos, "pm%s" % self.rival_name)

        self.main_window.base.lbRotulo1.ponImagen(imagen())
        self.main_window.base.lbRotulo1.show()

        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
        if self.siTiempo:
            tpBL = self.vtime[True].etiqueta()
            tpNG = self.vtime[False].etiqueta()
            self.main_window.ponDatosReloj(bl, tpBL, ng, tpNG)
            self.refresh()
            self.main_window.start_clock(self.set_clock, 400)
        else:
            self.main_window.base.change_player_labels(bl, ng)

        self.main_window.set_notify(self.mueve_rival_base)

        self.check_boards_setposition()

        self.game.tag_timestart()