Exemplo n.º 1
0
 def mueve_rival(self, from_sq, to_sq, promotion):
     siBien, mens, move = Move.dameJugada(self.game,
                                          self.game.last_position, from_sq,
                                          to_sq, promotion)
     self.add_move(move, False)
     self.move_the_pieces(move.liMovs, True)
     self.error = ""
Exemplo n.º 2
0
    def leerLIPV(self, lipv):
        position = self.last_position
        pv = []
        for mov in lipv:
            if (len(mov) >= 4 and mov[0] in "abcdefgh" and mov[1] in "12345678"
                    and mov[2] in "abcdefgh" and mov[3] in "12345678"):
                pv.append(mov)
            else:
                break

        siB = self.is_white

        for mov in pv:
            from_sq = mov[:2]
            to_sq = mov[2:4]
            if len(mov) == 5:
                promotion = mov[4]
                if siB:
                    promotion = promotion.upper()
            else:
                promotion = None
            siBien, mens, move = Move.dameJugada(self, position, from_sq,
                                                 to_sq, promotion)
            if siBien:
                self.li_moves.append(move)
                position = move.position
            siB = not siB
        return self
Exemplo n.º 3
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        if self.timer:
            self.ms += int((time.time() - self.timer) * 1000)
        self.moves += 1
        self.timer = None

        movimiento = from_sq + to_sq

        # Peon coronando
        if not promotion and self.game.last_position.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(self.game.last_position.is_white)
            if promotion is None:
                self.sigueHumano()
                return False
        if promotion:
            movimiento += promotion

        ok, self.error, move = Move.dameJugada(self.game, self.game.last_position, from_sq, to_sq, promotion)
        if ok:
            self.game.add_move(move)
            self.tablero.setposition(move.position)
            self.sigueMaquina()
            return True
        else:
            return False
Exemplo n.º 4
0
    def juegaRival(self):
        if self.is_opening:
            pv = self.liPVopening[self.posOpening]
            self.posOpening += 1
            if self.posOpening == len(self.liPVopening):
                self.is_opening = False
        else:
            fen = self.game.last_position.fen()
            pv = None
            if self.book:
                pv = self.book.eligeJugadaTipo(fen, "au")
                if not pv:
                    self.book = None
            if not pv:
                if len(self.game.last_position) <= 4:
                    t4 = LibChess.T4(self.configuracion)
                    pv = t4.best_move(fen)
                    t4.close()
                if not pv:
                    pv = self.engine.play(fen)

        siBien, mens, move = Move.dameJugada(self.game,
                                             self.game.last_position, pv[:2],
                                             pv[2:4], pv[4:])
        self.add_move(move, False)
        self.move_the_pieces(move.liMovs, True)
        self.siguiente_jugada()
Exemplo n.º 5
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        move = self.checkmueve_humano(from_sq, to_sq, promotion)
        if not move:
            return False

        movimiento = move.movimiento()
        self.add_time()

        siAnalisis = False

        is_selected = False

        if self.opening:
            fenBase = self.fenUltimo()
            if self.opening.check_human(fenBase, from_sq, to_sq):
                is_selected = True
            else:
                self.opening = None

        self.analizaFinal()  # tiene que acabar siempre
        if not is_selected:
            rmUser, n = self.mrmTutor.buscaRM(movimiento)
            if not rmUser:
                rmUser = self.xtutor.valora(self.game.last_position, from_sq,
                                            to_sq, move.promotion)
                if not rmUser:
                    self.sigueHumanoAnalisis()
                    return False
                self.mrmTutor.agregaRM(rmUser)
            siAnalisis = True
            pointsBest, pointsUser = self.mrmTutor.difPointsBest(movimiento)
            if (pointsBest - pointsUser) > 0:
                if not move.is_mate:
                    tutor = Tutor.Tutor(self, self, move, from_sq, to_sq,
                                        False)
                    if tutor.elegir(True):
                        self.reponPieza(from_sq)
                        from_sq = tutor.from_sq
                        to_sq = tutor.to_sq
                        promotion = tutor.promotion
                        siBien, mens, jgTutor = Move.dameJugada(
                            self.game, self.game.last_position, from_sq, to_sq,
                            promotion)
                        if siBien:
                            move = jgTutor
                            self.add_hint()
                    del tutor

        self.move_the_pieces(move.liMovs)

        if siAnalisis:
            rm, nPos = self.mrmTutor.buscaRM(move.movimiento())
            if rm:
                move.analysis = self.mrmTutor, nPos

        self.add_move(move, True)
        self.error = ""
        self.siguiente_jugada()
        return True
Exemplo n.º 6
0
    def mueve_rival(self):
        si_obligatorio = len(self.game) <= self.plies_mandatory
        si_pensar = True
        fenm2 = self.game.last_position.fenm2()
        moves = self.dicFENm2.get(fenm2, set())
        if si_obligatorio:
            nmoves = len(moves)
            if nmoves == 0:
                si_obligatorio = False
            else:
                move = self.dbop.get_cache_engines(self.keyengine, self.time,
                                                   fenm2)
                if move is None:
                    if self.book:
                        move_book = self.book.eligeJugadaTipo(
                            self.game.last_position.fen(), "au")
                        if move_book in list(moves):
                            move = move_book
                    if move is None:
                        move = random.choice(list(moves))
                    self.dbop.set_cache_engines(self.keyengine, self.time,
                                                fenm2, move)
                from_sq, to_sq, promotion = move[:2], move[2:4], move[4:]
                si_pensar = False

        if si_pensar:
            move = None
            if self.book:
                move = self.book.eligeJugadaTipo(self.game.last_position.fen(),
                                                 self.book.mode)
            if move is None:
                move = self.dbop.get_cache_engines(self.keyengine, self.time,
                                                   fenm2)
            if move is None:
                rm_rival = self.xrival.juegaPartida(self.game)
                move = rm_rival.movimiento()
                self.dbop.set_cache_engines(self.keyengine, self.time, fenm2,
                                            move)
            from_sq, to_sq, promotion = move[:2], move[2:4], move[4:]
            if si_obligatorio:
                if not (move in moves):
                    move = list(moves)[0]
                    from_sq, to_sq, promotion = move[:2], move[2:4], move[4:]

        siBien, mens, move = Move.dameJugada(self.game,
                                             self.game.last_position, from_sq,
                                             to_sq, promotion)
        if siBien:
            self.add_move(move, False)
            self.move_the_pieces(move.liMovs, True)

            self.error = ""

            return True
        else:
            self.error = mens
            return False
Exemplo n.º 7
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        move = self.checkmueve_humano(from_sq, to_sq, promotion)
        if not move:
            return False

        a1h8 = move.movimiento()
        ok = False
        if self.is_playing_gameobj():
            move = self.game_obj.move(self.pos_obj)
            is_main, is_var = move.test_a1h8(a1h8)
            if is_main:
                ok = True
                self.pos_obj += 1
            elif is_var:
                li_movs = [(move.from_sq, move.to_sq, True)]
                for a1h8_m in move.variations.list_movimientos():
                    li_movs.append((a1h8_m[:2], a1h8[2:4], False))
                self.tablero.ponFlechasTmp(li_movs)
            else:
                if a1h8[:2] != move.from_sq:
                    self.tablero.markPosition(move.from_sq)
            if not ok:
                self.sigueHumano()
                return False

        if not ok:
            if self.is_tutor_enabled:
                if not self.is_analyzed_by_tutor:
                    self.analizaTutor()
                if self.mrmTutor.mejorMovQue(a1h8):
                    if not move.is_mate:
                        tutor = Tutor.Tutor(self, self, move, from_sq, to_sq,
                                            False)

                        if tutor.elegir(True):
                            self.reponPieza(from_sq)
                            from_sq = tutor.from_sq
                            to_sq = tutor.to_sq
                            promotion = tutor.promotion
                            si_bien, mens, move_tutor = Move.dameJugada(
                                self.game, self.game.last_position, from_sq,
                                to_sq, promotion)
                            if si_bien:
                                move = move_tutor

                        del tutor
            self.mrmTutor = None

        self.move_the_pieces(move.liMovs)
        self.add_move(move, True)

        if self.game_obj and self.pos_obj >= len(self.game_obj):
            self.lineaTerminadaOpciones()

        self.siguiente_jugada()
        return True
Exemplo n.º 8
0
 def juegaRival(self):
     if not self.is_finished():
         self.pensando(True)
         rm = self.xrival.juega(nAjustado=self.xrival.nAjustarFuerza)
         if rm.from_sq:
             siBien, self.error, move = Move.dameJugada(
                 self.game, self.game.last_position, rm.from_sq, rm.to_sq, rm.promotion
             )
             self.add_move(move)
             self.move_the_pieces(move.liMovs)
         self.pensando(False)
Exemplo n.º 9
0
    def siguiente_jugada(self):
        if self.test_is_finished():
            return False

        self.current_side = is_white = self.game.is_white()

        self.tablero.ponIndicador(is_white)

        move_found = False
        analisis = None
        bk = self.book[is_white]
        if bk:
            move_found, from_sq, to_sq, promotion = self.eligeJugadaBook(
                bk, self.bookRR[is_white])
            if not move_found:
                self.book[is_white] = None

        if not move_found:
            xrival = self.xengine[is_white]
            tiempoBlancas = self.vtime[True].tiempoPendiente
            tiempoNegras = self.vtime[False].tiempoPendiente
            segundosJugada = xrival.motorTiempoJugada
            self.reloj_start(is_white)
            mrm = xrival.juegaTiempoTorneo(self.game, tiempoBlancas,
                                           tiempoNegras, segundosJugada)
            if self.state == ST_PAUSE:
                self.reloj_pause(is_white)
                self.tablero.borraMovibles()
                return True
            self.reloj_stop(is_white)
            if mrm is None:
                return False
            rm = mrm.mejorMov()
            from_sq = rm.from_sq
            to_sq = rm.to_sq
            promotion = rm.promotion
            analisis = mrm, 0

        siBien, mens, move = Move.dameJugada(self.game,
                                             self.game.last_position, from_sq,
                                             to_sq, promotion)
        if not move:
            return False
        if analisis:
            move.analysis = analisis
            move.del_nags()
        self.add_move(move)
        self.move_the_pieces(move.liMovs)

        return True
Exemplo n.º 10
0
    def mueve_rival(self, move):
        from_sq = move[:2]
        to_sq = move[2:4]
        promotion = move[4:]

        siBien, mens, move = Move.dameJugada(self.game, self.game.last_position, from_sq, to_sq, promotion)
        if siBien:
            self.error = ""

            self.add_move(move, False)
            self.move_the_pieces(move.liMovs, True)

            return True
        else:
            self.error = mens
            return False
Exemplo n.º 11
0
    def mueveRival(self, respMotor):
        from_sq = respMotor.from_sq
        to_sq = respMotor.to_sq

        promotion = respMotor.promotion

        siBien, mens, move = Move.dameJugada(self.game, self.game.last_position, from_sq, to_sq, promotion)
        if siBien:
            self.masJugada(move, False)
            self.move_the_pieces(move.liMovs, True)

            self.error = ""

            return True
        else:
            self.error = mens
            return False
Exemplo n.º 12
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        if not promotion and self.game.last_position.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(self.game.last_position.is_white)
            if promotion is None:
                return False

        siBien, mens, move = Move.dameJugada(self.game, self.game.last_position, from_sq, to_sq, promotion)

        if siBien:
            self.game.add_move(move)
            self.tablero.setposition(move.position)
            self.tablero.ponFlechaSC(move.from_sq, move.to_sq)

            self.siguiente_jugada()
            return True
        else:
            return False
Exemplo n.º 13
0
    def mueve_humano(self, from_sq, to_sq, promotion=""):
        cpActual = self.game.move(
            self.pos_move
        ).position if self.pos_move >= 0 else self.game.first_position
        if cpActual.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(cpActual.is_white)
            if promotion is None:
                return

        siBien, mens, move = Move.dameJugada(self.game, cpActual, from_sq,
                                             to_sq, promotion)

        if siBien:
            game = Game.Game()
            game.leeOtra(self.game)

            if self.pos_move < len(self.game) - 1:
                game.li_moves = game.li_moves[:self.pos_move + 1]
            game.add_move(move)
            self.panelOpening.mueve_humano(game)
Exemplo n.º 14
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        self.tablero.disable_all()

        # Peon coronando
        if not promotion and self.position.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(self.position.is_white)
            if promotion is None:
                self.ponJuego()
                return False

        siBien, mens, move = Move.dameJugada(None, self.position, from_sq,
                                             to_sq, promotion)
        if siBien:
            self.tablero.setposition(move.position)
            self.tablero.ponFlechaSC(from_sq, to_sq)
            self.hechaJugada(move)
        else:
            self.ponJuego()
            return False
        return True
Exemplo n.º 15
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        self.human_is_playing = True  # necesario para el check
        move = self.checkmueve_humano(from_sq, to_sq, promotion)
        if not move:
            return False

        self.game.add_move(move)
        self.game.comprueba()
        if self.siAyuda:
            self.tablero.quitaFlechas()
        self.move_the_pieces(move.liMovs, False)
        if self.game.is_finished():
            if move.is_mate:
                self.siguienteMate()
            else:
                self.repiteMate(True, True)
            return

        self.numMov += 1
        if self.numMov == self.mate:
            self.repiteMate(True, True)
            return

        # Juega rival con depth 3
        rm = self.xrival.juega()
        from_sq = rm.from_sq
        to_sq = rm.to_sq
        promotion = rm.promotion

        siBien, mens, move = Move.dameJugada(self.game,
                                             self.game.last_position, from_sq,
                                             to_sq, promotion)
        self.game.add_move(move)
        self.ponFlechaSC(move.from_sq, move.to_sq)
        self.move_the_pieces(move.liMovs, False)
        if self.is_finished():
            self.repiteMate(True, True)
            return
        self.activaColor(
            self.is_human_side_white
        )  # Caso en que hay promotion, sino no se activa la dama
Exemplo n.º 16
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        self.paraHumano()

        movimiento = from_sq + to_sq

        # Peon coronando
        if not promotion and self.position.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(self.position.is_white)
            if promotion is None:
                self.sigueHumano()
                return False
        if promotion:
            movimiento += promotion

        siBien, mens, self.move = Move.dameJugada(self.game, self.position, from_sq, to_sq, promotion)
        if siBien:
            self.tablero.setposition(self.move.position)
            self.tablero.ponFlechaSC(from_sq, to_sq)
            self.calculaTiempoPuntos()
        else:
            self.sigueHumano()
Exemplo n.º 17
0
 def dameJugadasTXT(self, position_before, siGM):
     li = []
     dRepeticiones = {}
     for gmPartida in self.liGMPartidas:
         move = gmPartida.move(self.ply)
         if move:
             if not (move in dRepeticiones):
                 dRepeticiones[move] = [len(li), 1]
                 from_sq, to_sq, promotion = move[:2], move[2:4], move[4:]
                 siBien, mens, move = Move.dameJugada(
                     gmPartida, position_before, from_sq, to_sq, promotion)
                 li.append([
                     from_sq, to_sq, promotion,
                     gmPartida.rotuloBasico(siGM),
                     move.pgn_translated()
                 ])
             else:
                 dRepeticiones[move][1] += 1
                 pos = dRepeticiones[move][0]
                 li[pos][3] = _("%d games") % dRepeticiones[move][1]
     return li
Exemplo n.º 18
0
    def juegaHumano(self, is_white):
        self.reloj_start(True)
        self.timekeeper.start()
        self.human_is_playing = True
        if self.premove:
            from_sq, to_sq = self.premove
            promotion = "q" if self.game.last_position.siPeonCoronando(
                from_sq, to_sq) else None
            siBien, error, move = Move.dameJugada(self.game,
                                                  self.game.last_position,
                                                  self.premove[0],
                                                  self.premove[1], promotion)
            if siBien:
                self.mueve_humano(from_sq, to_sq, promotion)
                return
            self.premove = None

        self.pon_toolbar()
        self.analizaInicio()

        self.activaColor(is_white)
Exemplo n.º 19
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):

        # Peon coronando
        if not promotion and self.position_before.siPeonCoronando(
                from_sq, to_sq):
            promotion = self.w.tablero.peonCoronando(
                not self.move.position.is_white)
            if promotion is None:
                return False

        si_bien, mens, new_move = Move.dameJugada(None, self.position_before,
                                                  from_sq, to_sq, promotion)

        if si_bien:

            self.move_the_pieces(new_move.liMovs)
            self.w.tablero.ponFlechaSC(new_move.from_sq, new_move.to_sq)
            self.analyse_move(new_move)
            return True
        else:
            return False
Exemplo n.º 20
0
    def piensa_rival(self):
        self.human_is_playing = False
        self.is_rival_thinking = True
        self.disable_all()

        if self.is_playing_gameobj():
            if self.game_obj and self.pos_obj == len(self.game_obj):
                self.is_rival_thinking = False
                self.lineaTerminadaOpciones()
                return
            move = self.game_obj.move(self.pos_obj)
            self.pos_obj += 1
            from_sq, to_sq, promotion = move.from_sq, move.to_sq, move.promotion

        else:
            self.pensando(True)
            self.rm_rival = self.xrival.juega()
            self.pensando(False)
            from_sq, to_sq, promotion = (self.rm_rival.from_sq,
                                         self.rm_rival.to_sq,
                                         self.rm_rival.promotion)

        self.is_rival_thinking = False
        siBien, mens, move = Move.dameJugada(self.game,
                                             self.game.last_position, from_sq,
                                             to_sq, promotion)
        self.is_analyzed_by_tutor = False
        is_obj = self.is_playing_gameobj()
        if self.is_tutor_enabled:
            if not is_obj:
                self.analizaTutor(
                )  # Que analice antes de activar humano, para que no tenga que esperar
                self.is_analyzed_by_tutor = True

        self.move_the_pieces(move.liMovs, True)
        self.add_move(move, False)

        if is_obj:
            self.lineaTerminadaOpciones()
        self.siguiente_jugada()
Exemplo n.º 21
0
 def sigueMaquina(self):
     ended, go_next = self.test_final()
     if ended:
         if go_next:
             self.play_next()
         return
     lista = self.t4.best_moves_game(self.game)
     if len(lista) == 0:
         return
     move = random.choice(lista)
     from_sq, to_sq, promotion = move[:2], move[2:4], move[4:]
     siBien, mens, move = Move.dameJugada(self.game, self.game.last_position, from_sq, to_sq, promotion)
     self.game.add_move(move)
     for movim in move.liMovs:
         if movim[0] == "b":
             self.tablero.borraPieza(movim[1])
         elif movim[0] == "m":
             self.tablero.muevePieza(movim[1], movim[2])
         elif movim[0] == "c":
             self.tablero.cambiaPieza(movim[1], movim[2])
     self.timer = time.time()
     self.sigueHumano()
Exemplo n.º 22
0
    def mueve_rival(self, rm_rival):
        self.reloj_stop(False)
        self.pensando(False)
        time_s = self.timekeeper.stop()
        self.setSummary("TIMERIVAL", time_s)

        if self.state in (ST_ENDGAME, ST_PAUSE):
            return self.state == ST_ENDGAME
        if self.nAjustarFuerza == ADJUST_SELECTED_BY_PLAYER:
            rm_rival = self.ajustaPlayer(rm_rival)

        self.lirm_engine.append(rm_rival)
        if not (self.resign_limit < -1500):  # then not ask for draw
            if not self.valoraRMrival():
                self.muestra_resultado()
                return True

        siBien, self.error, move = Move.dameJugada(self.game,
                                                   self.game.last_position,
                                                   rm_rival.from_sq,
                                                   rm_rival.to_sq,
                                                   rm_rival.promotion)
        self.rm_rival = rm_rival
        if siBien:
            fen_ultimo = self.fenUltimo()
            move.set_time_ms(int(time_s * 1000))
            self.add_move(move, False)
            self.move_the_pieces(move.liMovs, True)

            if self.siTiempo:
                move.cacheTime = self.vtime[self.is_engine_side_white].save()
            self.cache[fen_ultimo] = move
            self.siguiente_jugada()
            return True

        else:
            return False
Exemplo n.º 23
0
    def juegaRival(self):
        self.pensando(True)
        self.disable_all()

        from_sq = to_sq = promotion = ""
        siEncontrada = False

        if self.opening:
            siEncontrada, from_sq, to_sq, promotion = self.opening.run_engine(
                self.fenUltimo())
            if not siEncontrada:
                self.opening = None

        if siEncontrada:
            self.rm_rival = EngineResponse.EngineResponse(
                "Apertura", self.is_engine_side_white)
            self.rm_rival.from_sq = from_sq
            self.rm_rival.to_sq = to_sq
            self.rm_rival.promotion = promotion

        else:
            self.rm_rival = self.xrival.juegaTiempo(self.tmRival, self.tmRival,
                                                    0)

        self.pensando(False)

        siBien, self.error, move = Move.dameJugada(self.game,
                                                   self.game.last_position,
                                                   self.rm_rival.from_sq,
                                                   self.rm_rival.to_sq,
                                                   self.rm_rival.promotion)
        if siBien:
            self.add_move(move, False)
            self.move_the_pieces(move.liMovs, True)
            return True
        else:
            return False
Exemplo n.º 24
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        self.tablero.disable_all()

        movimiento = from_sq + to_sq

        position = self.game.move(
            self.posCurrent
        ).position if self.posCurrent >= 0 else self.game.last_position

        # Peon coronando
        if not promotion and position.siPeonCoronando(from_sq, to_sq):
            promotion = self.tablero.peonCoronando(position.is_white)
            if promotion is None:
                self.sigueHumano()
                return False
        if promotion:
            movimiento += promotion

        siBien, mens, move = Move.dameJugada(self.game, position, from_sq,
                                             to_sq, promotion)
        if siBien:
            self.nuevaJugada(move)
        else:
            self.actualizaPosicion()
Exemplo n.º 25
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        if not self.human_is_playing:
            return self.check_premove(from_sq, to_sq)
        move = self.checkmueve_humano(from_sq, to_sq, promotion,
                                      not self.is_tutor_enabled)
        if not move:
            return False

        movimiento = move.movimiento()

        siAnalisis = False

        is_selected = False

        fen_base = self.fenUltimo()

        if self.bookR and self.bookMandatory:
            listaJugadas = self.bookR.miraListaJugadas(fen_base)
            if listaJugadas:
                li = []
                for apdesde, aphasta, apcoronacion, nada, nada1 in listaJugadas:
                    mx = apdesde + aphasta + apcoronacion
                    if mx.strip().lower() == movimiento:
                        is_selected = True
                        break
                    li.append((apdesde, aphasta, False))
                if not is_selected:
                    self.tablero.ponFlechasTmp(li)
                    self.sigueHumano()
                    return False

        if not is_selected and self.aperturaObl:
            if self.aperturaObl.check_human(fen_base, from_sq, to_sq):
                is_selected = True
            else:
                apdesde, aphasta = self.aperturaObl.from_to_active(fen_base)
                if apdesde is None:
                    self.aperturaObl = None
                else:
                    self.tablero.ponFlechasTmp(((apdesde, aphasta, False), ))
                    self.sigueHumano()
                    return False

        if not is_selected and self.aperturaStd:
            if self.aperturaStd.check_human(fen_base, from_sq, to_sq):
                is_selected = True
            else:
                if not self.aperturaStd.is_active(fen_base):
                    self.aperturaStd = None

        is_mate = move.is_mate
        self.analizaFinal(is_mate)  # tiene que acabar siempre
        if not is_mate and not is_selected and self.is_tutor_enabled:
            if not self.tutor_book.si_esta(fen_base, movimiento):
                rmUser, n = self.mrmTutor.buscaRM(movimiento)
                if not rmUser:
                    self.main_window.pensando_tutor(True)
                    rmUser = self.xtutor.valora(self.game.last_position,
                                                from_sq, to_sq, move.promotion)
                    self.main_window.pensando_tutor(False)
                    if not rmUser:
                        self.sigueHumanoAnalisis()
                        return False
                    self.mrmTutor.agregaRM(rmUser)
                siAnalisis = True
                pointsBest, pointsUser = self.mrmTutor.difPointsBest(
                    movimiento)
                self.setSummary("POINTSBEST", pointsBest)
                self.setSummary("POINTSUSER", pointsUser)
                difpts = self.configuracion.x_tutor_difpoints
                difporc = self.configuracion.x_tutor_difporc
                if self.mrmTutor.mejorRMQue(rmUser, difpts, difporc):
                    if not move.is_mate:
                        if self.chance:
                            num = self.mrmTutor.numMejorMovQue(movimiento)
                            if num:
                                rmTutor = self.mrmTutor.rmBest()
                                menu = QTVarios.LCMenu(self.main_window)
                                menu.opcion("None",
                                            _("There are %d best moves") % num,
                                            Iconos.Motor())
                                menu.separador()
                                menu.opcion(
                                    "tutor",
                                    "&1. %s (%s)" %
                                    (_("Show tutor"), rmTutor.abrTextoBase()),
                                    Iconos.Tutor(),
                                )
                                menu.separador()
                                menu.opcion("try", "&2. %s" % _("Try again"),
                                            Iconos.Atras())
                                menu.separador()
                                menu.opcion(
                                    "user",
                                    "&3. %s (%s)" % (_("Select my move"),
                                                     rmUser.abrTextoBase()),
                                    Iconos.Player(),
                                )
                                self.main_window.cursorFueraTablero()
                                resp = menu.lanza()
                                if resp == "try":
                                    self.sigueHumanoAnalisis()
                                    return False
                                elif resp == "user":
                                    siTutor = False
                                elif resp != "tutor":
                                    self.sigueHumanoAnalisis()
                                    return False

                        tutor = Tutor.Tutor(self, self, move, from_sq, to_sq,
                                            False)

                        if self.aperturaStd:
                            liApPosibles = self.listaAperturasStd.list_possible_openings(
                                self.game)
                        else:
                            liApPosibles = None

                        if tutor.elegir(self.ayudas > 0,
                                        liApPosibles=liApPosibles):
                            if self.ayudas > 0:  # doble entrada a tutor.
                                self.reponPieza(from_sq)
                                self.ayudas -= 1
                                self.tutor_con_flechas = self.nArrowsTt > 0 and self.ayudas > 0
                                from_sq = tutor.from_sq
                                to_sq = tutor.to_sq
                                promotion = tutor.promotion
                                siBien, mens, jgTutor = Move.dameJugada(
                                    self.game, self.game.last_position,
                                    from_sq, to_sq, promotion)
                                if siBien:
                                    move = jgTutor
                                    self.setSummary("SELECTTUTOR", True)
                        if self.configuracion.x_save_tutor_variations:
                            tutor.ponVariantes(move, 1 + len(self.game) / 2)

                        del tutor

        self.setSummary("TIMEUSER", self.timekeeper.stop())
        self.reloj_stop(True)

        self.move_the_pieces(move.liMovs)

        if siAnalisis:
            rm, nPos = self.mrmTutor.buscaRM(move.movimiento())
            if rm:
                move.analysis = self.mrmTutor, nPos

        self.add_move(move, True)
        self.error = ""
        self.siguiente_jugada()
        return True
Exemplo n.º 26
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        move = self.checkmueve_humano(from_sq, to_sq, promotion)
        if not move:
            return False

        movUsu = move.movimiento().lower()
        self.dbwashing.add_time(self.timekeeper.stop())

        jgObj = self.partidaObj.move(self.posJugadaObj)
        movObj = jgObj.movimiento().lower()
        if movUsu != movObj:
            lic = []
            if jgObj.analysis:
                mrmObj, posObj = jgObj.analysis
                rmObj = mrmObj.li_rm[posObj]
                lic.append("%s: %s (%s)" %
                           (_("Played previously"), jgObj.pgn_translated(),
                            rmObj.abrTextoBase()))
                ptsObj = rmObj.centipawns_abs()
                rmUsu, posUsu = mrmObj.buscaRM(movUsu)
                if posUsu >= 0:
                    lic.append("%s: %s (%s)" %
                               (_("Played now"), move.pgn_translated(),
                                rmUsu.abrTextoBase()))
                    ptsUsu = rmUsu.centipawns_abs()
                    if ptsUsu < ptsObj - 10:
                        lic[-1] += ' <span style="color:red"><b>%s</b></span>' % _(
                            "Bad move")
                        self.errores += 1
                        self.dbwashing.add_hint()

                else:
                    lic.append("%s: %s (?) %s" %
                               (_("Played now"), move.pgn_translated(),
                                _("Bad move")))
                    self.errores += 1
                    self.dbwashing.add_hint()

            else:
                # Debe ser una move de libro para aceptarla
                fen = self.fenUltimo()
                siBookUsu = self.book.check_human(fen, from_sq, to_sq)
                bmove = _("book move")
                lic.append(
                    "%s: %s (%s)" %
                    (_("Played previously"), jgObj.pgn_translated(), bmove))
                if siBookUsu:
                    lic.append("%s: %s (%s)" %
                               (_("Played now"), move.pgn_translated(), bmove))
                else:
                    lic.append("%s: %s (?) %s" %
                               (_("Played now"), move.pgn_translated(),
                                _("Bad move")))
                    self.errores += 1
                    self.dbwashing.add_hint()

            comment = "<br>".join(lic)
            w = PantallaJuicio.MensajeF(self.main_window, comment)
            w.mostrar()
            self.setposition(move.position_before)

        # Creamos un move sin analisis
        siBien, self.error, move = Move.dameJugada(self.game,
                                                   self.game.last_position,
                                                   jgObj.from_sq, jgObj.to_sq,
                                                   jgObj.promotion)

        self.move_the_pieces(move.liMovs)
        self.add_move(move, True)
        self.posJugadaObj += 1
        if len(self.game) == self.partidaObj.num_moves():
            self.finPartida()

        else:
            self.error = ""
            self.siguiente_jugada()
        return True
Exemplo n.º 27
0
    def mueve_humano(self, from_sq, to_sq, promotion=None):
        jgUsu = self.checkmueve_humano(from_sq, to_sq, promotion)
        if not jgUsu:
            return False

        movimiento = jgUsu.movimiento()
        position = self.game.last_position
        isValid = self.motorGM.isValidMove(movimiento)
        analisis = None

        if not isValid:
            self.tablero.setposition(position)
            self.tablero.activaColor(self.is_human_side_white)
            li_moves = self.motorGM.dameJugadasTXT(position, True)
            desdeGM, hastaGM, coronacionGM = PantallaGM.eligeJugada(self, li_moves, True)
            siAnalizaJuez = self.siJuez
            if siAnalizaJuez:
                if self.book:
                    fen = self.fenUltimo()
                    siH = self.book.check_human(fen, from_sq, to_sq)
                    siGM = self.book.check_human(fen, desdeGM, hastaGM)
                    if siGM and siH:
                        siAnalizaJuez = False
                    else:
                        self.book = False
        else:
            siAnalizaJuez = (
                self.siJuez and self.mostrar is None
            )  # None es ver siempre False no ver nunca True ver si diferentes
            if len(movimiento) == 5:
                promotion = movimiento[4].lower()
            desdeGM, hastaGM, coronacionGM = from_sq, to_sq, promotion

        siBien, mens, jgGM = Move.dameJugada(self.game, position, desdeGM, hastaGM, coronacionGM)
        movGM = jgGM.pgn_translated()
        movUsu = jgUsu.pgn_translated()

        if siAnalizaJuez:
            um = QTUtil2.analizando(self.main_window)
            mrm = self.analizaMinimo(self.vtime * 100)

            rmUsu, nada = mrm.buscaRM(jgUsu.movimiento())
            if rmUsu is None:
                um = QTUtil2.analizando(self.main_window)
                self.analizaFinal()
                rmUsu = self.xtutor.valora(position, from_sq, to_sq, promotion)
                mrm.agregaRM(rmUsu)
                self.analizaInicio()
                um.final()

            rmGM, pos_gm = mrm.buscaRM(jgGM.movimiento())
            if rmGM is None:
                self.analizaFinal()
                rmGM = self.xtutor.valora(position, desdeGM, hastaGM, coronacionGM)
                pos_gm = mrm.agregaRM(rmGM)
                self.analizaInicio()

            um.final()

            analisis = mrm, pos_gm
            dpts = rmUsu.centipawns_abs() - rmGM.centipawns_abs()

            if self.mostrar is None or ((self.mostrar is True) and not isValid):
                w = PantallaJuicio.WJuicio(
                    self,
                    self.xtutor,
                    self.nombreGM,
                    position,
                    mrm,
                    rmGM,
                    rmUsu,
                    analisis,
                    siCompetitivo=not self.showevals,
                )
                w.exec_()

                rm, pos_gm = w.analysis[0].buscaRM(jgGM.movimiento())
                analisis = w.analysis[0], pos_gm

                dpts = w.difPuntos()

            self.puntos += dpts

            comentario0 = "<b>%s</b> : %s = %s<br>" % (self.configuracion.x_player, movUsu, rmUsu.texto())
            comentario0 += "<b>%s</b> : %s = %s<br>" % (self.nombreGM, movGM, rmGM.texto())
            comentario1 = "<br><b>%s</b> = %+d<br>" % (_("Difference"), dpts)
            comentario2 = "<b>%s</b> = %+d<br>" % (_("Points accumulated"), self.puntos)
            self.textoPuntuacion = comentario2
            self.ponRotuloSecundario()

            if not isValid:
                jgGM.comment = (
                    (comentario0 + comentario1 + comentario2)
                    .replace("<b>", "")
                    .replace("</b>", "")
                    .replace("<br>", "\n")
                )

        self.analizaFinal()

        self.move_the_pieces(jgGM.liMovs)

        jgGM.analysis = analisis
        self.add_move(jgGM, True)
        self.error = ""
        self.siguiente_jugada()
        return True