def play_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 = self.dbop.get_cache_engines(self.keyengine, self.time, fenm2) if self.book: move = self.book.eligeJugadaTipo(self.game.last_position.fen(), self.book.mode) if not move: 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:] ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: self.add_move(move, False) self.move_the_pieces(move.liMovs, True) self.error = "" return True else: self.error = mens return False
def player_has_moved(self, from_sq, to_sq, promotion=""): move = self.check_human_move(from_sq, to_sq, promotion) if not move: return False movimiento = move.movimiento() self.analizaFinal() siMirarTutor = self.is_tutor_enabled if self.in_the_opening: if self.opening.check_human(self.last_fen(), from_sq, to_sq): siMirarTutor = False if siMirarTutor: if not self.is_analyzed_by_tutor: self.mrmTutor = self.analizaTutor() if self.mrmTutor is None: self.sigueHumano() return False if not self.tutor_book.si_esta(self.last_fen(), movimiento): if self.mrmTutor.mejorMovQue(movimiento): self.refresh() if not move.is_mate: tutor = Tutor.Tutor(self, self, move, from_sq, to_sq, False) if self.in_the_opening: liApPosibles = self.listaOpeningsStd.list_possible_openings( self.game) else: liApPosibles = None if tutor.elegir(self.hints > 0, liApPosibles=liApPosibles): if self.hints > 0: # doble entrada a tutor. self.set_piece_again(from_sq) self.hints -= 1 from_sq = tutor.from_sq to_sq = tutor.to_sq promotion = tutor.promotion ok, mens, jgTutor = Move.get_game_move( self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: move = jgTutor elif self.configuration.x_save_tutor_variations: tutor.ponVariations(move, 1 + len(self.game) / 2) del tutor self.move_the_pieces(move.liMovs) self.add_move(move, True) self.play_next_move() return True
def juegaRival(self): if not self.is_finished(): self.thinking(True) rm = self.xrival.juega(nAjustado=self.xrival.nAjustarFuerza) if rm.from_sq: ok, self.error, move = Move.get_game_move( 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.thinking(False)
def player_has_moved(self, from_sq, to_sq, promotion=""): move = self.check_human_move(from_sq, to_sq, promotion) if not move: return False self.analizaFinal(move.is_mate) # tiene que acabar siempre a1h8 = move.movimiento() ok = False if self.is_playing_gameobj(): move_obj = self.game_obj.move(self.pos_obj) is_main, is_var = move_obj.test_a1h8(a1h8) if is_main: ok = True self.pos_obj += 1 elif is_var: li_movs = [(move_obj.from_sq, move_obj.to_sq, True)] for a1h8_m in move.variations.list_movimientos(): li_movs.append((a1h8_m[:2], a1h8[2:4], False)) self.board.ponFlechasTmp(li_movs) if not ok: self.sigueHumano() return False if not ok: is_mate = move.is_mate self.analizaFinal(is_mate) # tiene que acabar siempre if self.is_tutor_enabled: if not self.is_analyzed_by_tutor: self.analizaTutor(True) if self.mrmTutor.mejorMovQue(a1h8): if not move.is_mate: tutor = Tutor.Tutor(self, move, from_sq, to_sq, False) if tutor.elegir(True): self.set_piece_again(from_sq) from_sq = tutor.from_sq to_sq = tutor.to_sq promotion = tutor.promotion si_bien, mens, move_tutor = Move.get_game_move(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.play_next_move() return True
def play_rival(self, from_sq, to_sq, promotion): ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: self.add_move(move, False) self.move_the_pieces(move.liMovs, True) self.error = "" return True else: self.error = mens return False
def play_next_move(self): if self.test_is_finished(): return False self.current_side = is_white = self.game.is_white() self.board.set_side_indicator(is_white) move_found = False analysis = 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.board.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 analysis = mrm, 0 ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) if not move: return False if analysis: move.analysis = analysis move.del_nags() self.add_move(move) self.move_the_pieces(move.liMovs) return True
def player_has_moved(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.board.peonCoronando(cpActual.is_white) ok, mens, move = Move.get_game_move(self.game, cpActual, from_sq, to_sq, promotion) if ok: game = Game.Game() game.assign_other_game(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.player_has_moved(game)
def play_rival(self, engine_response): from_sq = engine_response.from_sq to_sq = engine_response.to_sq promotion = engine_response.promotion ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: self.error = "" self.add_move(move, False) self.move_the_pieces(move.liMovs, True) return True else: self.error = mens return False
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 ok, error, move = Move.get_game_move(self.game, self.game.last_position, self.premove[0], self.premove[1], promotion) if ok: self.player_has_moved(from_sq, to_sq, promotion) return self.premove = None self.pon_toolbar() self.analizaInicio() self.activate_side(is_white)
def player_has_moved(self, from_sq, to_sq, promotion=""): self.board.disable_all() # Peon coronando if not promotion and self.position.siPeonCoronando(from_sq, to_sq): promotion = self.board.peonCoronando(self.position.is_white) ok, mens, move = Move.get_game_move(None, self.position, from_sq, to_sq, promotion) if ok: self.board.set_position(move.position) self.board.put_arrow_sc(from_sq, to_sq) self.hechaJugada(move) else: self.ponJuego() return False return True
def ayuda(self): if self.human_is_playing: self.paraHumano() else: return self.board.set_position(self.game.last_position) main = self.list_moves[0][4] saux = False paux = 0 for n, jug in enumerate(self.list_moves): opacity = p = jug[4] simain = p == main if not simain: if not saux: paux = p saux = True opacity = 1.0 if p == paux else max(p, 0.25) self.board.creaFlechaMulti(jug[0] + jug[1], siMain=simain, opacity=opacity) resp = WindowBooks.eligeJugadaBooks(self.main_window, self.list_moves, self.human_side, siSelectSiempre=False) self.board.remove_arrows() if resp is None: self.sumar_aciertos = False self.sigueHumano() return xfrom, xto, promotion = resp ok, mens, jg = Move.get_game_move(self.game, self.game.last_position, xfrom, xto, promotion) self.movimientos += 1 self.set_label3("<b>%s</b>" % self.txt_matches()) self.move_the_pieces(jg.liMovs) self.masJugada(jg, True) self.error = "" self.sumar_aciertos = True self.siguienteJugada()
def player_has_moved(self, from_sq, to_sq, promotion=""): # Peon coronando if not promotion and self.position_before.siPeonCoronando(from_sq, to_sq): promotion = self.w.board.peonCoronando(not self.move.position.is_white) if promotion is None: return False si_bien, mens, new_move = Move.get_game_move(None, self.position_before, from_sq, to_sq, promotion) if si_bien: self.move_the_pieces(new_move.liMovs) self.w.board.put_arrow_sc(new_move.from_sq, new_move.to_sq) self.analyse_move(new_move) return True else: return False
def player_has_moved(self, from_sq, to_sq, promotion=""): if not promotion and self.game.last_position.siPeonCoronando( from_sq, to_sq): promotion = self.board.peonCoronando( self.game.last_position.is_white) ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: self.game.add_move(move) self.board.set_position(move.position) self.board.put_arrow_sc(move.from_sq, move.to_sq) self.play_next_move() return True else: return False
def player_has_moved(self, from_sq, to_sq, promotion=""): self.board.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.board.peonCoronando(position.is_white) if promotion: movimiento += promotion ok, mens, move = Move.get_game_move(self.game, position, from_sq, to_sq, promotion) if ok: self.nuevaJugada(move) else: self.actualizaPosicion()
def play_rival(self, book_response): xfrom = book_response.from_sq xto = book_response.to_sq promotion = book_response.promotion ok, mens, jg = Move.get_game_move(self.game, self.game.last_position, xfrom, xto, promotion) if ok: self.ponVariantes(jg) self.masJugada(jg, False) self.move_the_pieces(jg.liMovs, True) self.error = "" return True else: self.error = mens return False
def player_has_moved(self, from_sq, to_sq, promotion=""): self.paraHumano() movimiento = from_sq + to_sq # Peon coronando if not promotion and self.position.siPeonCoronando(from_sq, to_sq): promotion = self.board.peonCoronando(self.position.is_white) if promotion: movimiento += promotion game = Game.Game(ini_posicion=self.position) ok, mens, self.move = Move.get_game_move(game, self.position, from_sq, to_sq, promotion) if ok: self.board.set_position(self.move.position) self.board.put_arrow_sc(from_sq, to_sq) self.calculaTiempoPuntos() else: self.sigueHumano()
def get_moves_txt(self, position_before, is_gm): li = [] d_repeticiones = {} for gmPartida in self.li_gm_games: move = gmPartida.move(self.ply) if move: if not (move in d_repeticiones): d_repeticiones[move] = [len(li), 1] from_sq, to_sq, promotion = move[:2], move[2:4], move[4:] ok, mens, move = Move.get_game_move( gmPartida, position_before, from_sq, to_sq, promotion) li.append([ from_sq, to_sq, promotion, gmPartida.basic_label(is_gm), move.pgn_translated() ]) else: d_repeticiones[move][1] += 1 pos = d_repeticiones[move][0] li[pos][3] = _("%d games") % d_repeticiones[move][1] return li
def player_has_moved(self, from_sq, to_sq, promotion=""): self.human_is_playing = True # necesario para el check move = self.check_human_move(from_sq, to_sq, promotion) if not move: return False self.game.add_move(move) self.game.check() if self.siAyuda: self.board.remove_arrows() 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.play_game(self.game) from_sq = rm.from_sq to_sq = rm.to_sq promotion = rm.promotion ok, mens, move = Move.get_game_move(self.game, self.game.last_position, from_sq, to_sq, promotion) self.game.add_move(move) self.put_arrow_sc(move.from_sq, move.to_sq) self.move_the_pieces(move.liMovs, False) if self.is_finished(): self.repiteMate(True, True) return self.activate_side( self.human_side ) # Caso en que hay promotion, sino no se activa la dama
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.thinking(True) self.rm_rival = self.xrival.juega() self.thinking(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 ok, mens, move = Move.get_game_move(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.play_next_move()
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:] ok, mens, move = Move.get_game_move(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.board.borraPieza(movim[1]) elif movim[0] == "m": self.board.muevePieza(movim[1], movim[2]) elif movim[0] == "c": self.board.cambiaPieza(movim[1], movim[2]) self.timer = time.time() self.sigueHumano()
def juegaRival(self): self.thinking(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.last_fen()) if not siEncontrada: self.opening = None if siEncontrada: self.rm_rival = EngineResponse.EngineResponse( "Opening", 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.thinking(False) ok, self.error, move = Move.get_game_move(self.game, self.game.last_position, self.rm_rival.from_sq, self.rm_rival.to_sq, self.rm_rival.promotion) if ok: self.add_move(move, False) self.move_the_pieces(move.liMovs, True) return True else: return False
def play_rival(self, rm_rival): self.reloj_stop(False) self.thinking(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.valoraRMrival(): self.muestra_resultado() return True ok, self.error, move = Move.get_game_move(self.game, self.game.last_position, rm_rival.from_sq, rm_rival.to_sq, rm_rival.promotion) self.rm_rival = rm_rival if ok: fen_ultimo = self.last_fen() 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.play_next_move() return True else: return False
def player_has_moved(self, from_sq, to_sq, promotion=""): if not self.human_is_playing: return self.check_premove(from_sq, to_sq) move = self.check_human_move(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.last_fen() if self.bookR and self.bookMandatory: listaJugadas = self.bookR.get_list_moves(fen_base) if listaJugadas: li = [] for apdesde, aphasta, appromotion, nada, nada1 in listaJugadas: mx = apdesde + aphasta + appromotion if mx.strip().lower() == movimiento: is_selected = True break li.append((apdesde, aphasta, False)) if not is_selected: self.board.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.board.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.configuration.x_tutor_difpoints difporc = self.configuration.x_tutor_difporc if self.mrmTutor.mejorRMQue(rmUser, difpts, difporc): if not move.is_mate: si_tutor = True 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() resp = rmTutor.abrTextoBase() if not resp: resp = _("Mate") menu.opcion( "tutor", "&1. %s (%s)" % (_("Show tutor"), resp), 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.cursorFueraBoard() resp = menu.lanza() if resp == "try": self.sigueHumanoAnalisis() return False elif resp == "user": si_tutor = False elif resp != "tutor": self.sigueHumanoAnalisis() return False if si_tutor: tutor = Tutor.Tutor(self, move, from_sq, to_sq, False) if self.aperturaStd: liApPosibles = self.listaOpeningsStd.list_possible_openings( self.game) else: liApPosibles = None if tutor.elegir(self.hints > 0, liApPosibles=liApPosibles): if self.hints > 0: # doble entrada a tutor. self.set_piece_again(from_sq) self.hints -= 1 self.tutor_con_flechas = self.nArrowsTt > 0 and self.hints > 0 from_sq = tutor.from_sq to_sq = tutor.to_sq promotion = tutor.promotion ok, mens, jgTutor = Move.get_game_move( self.game, self.game.last_position, from_sq, to_sq, promotion) if ok: move = jgTutor self.setSummary("SELECTTUTOR", True) if self.configuration.x_save_tutor_variations: tutor.ponVariations(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.play_next_move() return True
def player_has_moved(self, from_sq, to_sq, promotion=""): move = self.check_human_move(from_sq, to_sq, promotion) if not move: return False movUsu = move.movimiento().lower() self.dbwashing.add_time(self.timekeeper.stop()) jgObj = self.gameObj.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 book para aceptarla fen = self.last_fen() 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 = WindowJuicio.MensajeF(self.main_window, comment) w.mostrar() self.set_position(move.position_before) # Creamos un move sin analysis ok, self.error, move = Move.get_game_move(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.gameObj.num_moves(): self.end_game() else: self.error = "" self.play_next_move() return True
def player_has_moved(self, from_sq, to_sq, promotion=""): jgUsu = self.check_human_move(from_sq, to_sq, promotion) if not jgUsu: return False movimiento = jgUsu.movimiento() position = self.game.last_position isValid = self.motorGM.is_valid_move(movimiento) analysis = None if not isValid: self.board.set_position(position) self.board.activate_side(self.human_side) li_moves = self.motorGM.get_moves_txt(position, True) desdeGM, hastaGM, promotionGM = WindowGM.select_move( self, li_moves, True) siAnalizaJuez = self.with_adjudicator if siAnalizaJuez: if self.book: fen = self.last_fen() siH = self.book.check_human(fen, from_sq, to_sq) is_gm = self.book.check_human(fen, desdeGM, hastaGM) if is_gm and siH: siAnalizaJuez = False else: self.book = False else: siAnalizaJuez = self.with_adjudicator 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, promotionGM = from_sq, to_sq, promotion ok, mens, jgGM = Move.get_game_move(self.game, position, desdeGM, hastaGM, promotionGM) movGM = jgGM.pgn_translated() movUsu = jgUsu.pgn_translated() if siAnalizaJuez: um = QTUtil2.analizando(self.main_window) mrm = self.analizaMinimo(self.vtime * 100) import time t = time.time() 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, promotionGM) pos_gm = mrm.agregaRM(rmGM) self.analizaInicio() um.final() analysis = mrm, pos_gm dpts = rmUsu.centipawns_abs() - rmGM.centipawns_abs() if self.mostrar is None or ((self.mostrar is True) and not isValid): w = WindowJuicio.WJuicio(self, self.xtutor, self.nombreGM, position, mrm, rmGM, rmUsu, analysis, is_competitive=not self.show_evals) w.exec_() rm, pos_gm = w.analysis[0].buscaRM(jgGM.movimiento()) analysis = w.analysis[0], pos_gm dpts = w.difPuntos() self.puntos += dpts comentario0 = "<b>%s</b> : %s = %s<br>" % ( self.configuration.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>" % (_("Centipawns 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 = analysis self.add_move(jgGM, True) self.error = "" self.play_next_move() return True
def play_human(self, xfrom, xto, promotion=None): jg = self.check_human_move(xfrom, xto, promotion) if not jg: return False found = False actpeso = 0 for jdesde, jhasta, jpromotion, jpgn, peso in self.list_moves: if xfrom == jdesde and xto == jhasta and jg.promotion == jpromotion: found = True actpeso = peso break if found and self.player_highest: # si el jugador busca elegir el maximo maxpeso = 0.0 for jdesde, jhasta, jpromotion, jpgn, peso in self.list_moves: if peso > maxpeso: maxpeso = peso if actpeso < maxpeso: found = False if not found: self.board.set_position(self.game.last_position) main = self.list_moves[0][4] saux = False paux = 0 for n, jug in enumerate(self.list_moves): opacity = p = jug[4] simain = p == main if not simain: if not saux: paux = p saux = True opacity = 1.0 if p == paux else max(p, 0.25) self.board.creaFlechaMulti(jug[0] + jug[1], siMain=simain, opacity=opacity) if self.show_menu: resp = WindowBooks.eligeJugadaBooks(self.main_window, self.list_moves, self.human_side, siSelectSiempre=False) self.board.remove_arrows() else: resp = None if resp is None: self.sumar_aciertos = False self.sigueHumano() return False xfrom, xto, promotion = resp ok, mens, jg = Move.get_game_move(self.game, self.game.last_position, xfrom, xto, promotion) else: if self.sumar_aciertos: self.aciertos += actpeso self.movimientos += 1 self.set_label3("<b>%s</b>" % self.txt_matches()) self.move_the_pieces(jg.liMovs) self.masJugada(jg, True) self.error = "" self.sumar_aciertos = True self.siguienteJugada() return True