def compruebaInput(self): if not self.engine: return self.veces += 1 if self.veces == 3: self.veces = 0 if self.siPlay: mrm = self.engine.ac_estado() rm = mrm.rmBest() if rm and rm.depth > self.depth: if mrm.li_rm: cp = self.game.last_position self.liData = [] def tr(tp, mas=""): self.liData.append((tp[0], "%.01f%%" % tp[1], "%s%s" % (mas, tp[2]))) tp = AnalysisIndexes.tp_gamestage(cp, mrm) self.liData.append((tp[0], "%d" % tp[1], tp[2])) pts = mrm.li_rm[0].centipawns_abs() mas = "" if pts: w, b = _("White"), _("Black") siW = "w" in self.fen if pts > 0: mas = w if siW else b elif pts < 0: mas = b if siW else w mas += "-" tr(AnalysisIndexes.tp_winprobability(cp, mrm), mas) tr(AnalysisIndexes.tp_complexity(cp, mrm)) tr(AnalysisIndexes.tp_efficientmobility(cp, mrm)) tr(AnalysisIndexes.tp_narrowness(cp, mrm)) tr(AnalysisIndexes.tp_piecesactivity(cp, mrm)) tr(AnalysisIndexes.tp_exchangetendency(cp, mrm)) tp = AnalysisIndexes.tp_positionalpressure(cp, mrm) self.liData.append((tp[0], "%d" % int(tp[1]), "")) tr(AnalysisIndexes.tp_materialasymmetry(cp, mrm)) self.grid.refresh() self.grid.resizeRowsToContents() QTUtil.refresh_gui() self.cpu.compruebaInput()
def piecesactivity(self): return AnalysisIndexes.get_piecesactivity(self.move.position_before, self.mrm)
def efficientmobility(self): return AnalysisIndexes.get_efficientmobility(self.move.position_before, self.mrm)
def narrowness(self): return AnalysisIndexes.get_narrowness(self.move.position_before, self.mrm)
def winprobability(self): return AnalysisIndexes.get_winprobability(self.move.position_before, self.mrm)
def complexity(self): return AnalysisIndexes.get_complexity(self.move.position_before, self.mrm)
def xprocesa(self, game, tmp_bp): self.si_bmt_blunders = False self.si_bmt_brilliancies = False si_bp2 = hasattr( tmp_bp, "bp2" ) # Para diferenciar el analysis de una game que usa una progressbar unica del # analysis de muchas, que usa doble def gui_dispatch(xrm): return not tmp_bp.is_canceled() self.xmanager.set_gui_dispatch( gui_dispatch ) # Dispatch del engine, si esta puesto a 4 minutos por ejemplo que # compruebe si se ha indicado que se cancele. si_blunders = self.kblunders > 0 si_brilliancies = self.fnsbrilliancies or self.pgnbrilliancies or self.bmtbrilliancies if self.bmtblunders and self.bmt_listaBlunders is None: self.bmt_listaBlunders = BMT.BMTLista() if self.bmtbrilliancies and self.bmt_listaBrilliancies is None: self.bmt_listaBrilliancies = BMT.BMTLista() xlibro_aperturas = self.book is_white = self.white is_black = self.black if self.li_players: for x in ["BLACK", "WHITE"]: player = game.get_tag(x) if player: player = player.upper() si = False for uno in self.li_players: si_z = uno.endswith("*") si_a = uno.startswith("*") uno = uno.replace("*", "").strip().upper() if si_a: if player.endswith(uno): si = True if si_z: # form para poner si_a y si_z si = uno in player elif si_z: if player.startswith(uno): si = True elif uno == player: si = True if si: break if not si: if x == "BLACK": is_black = False else: is_white = False if not (is_white or is_black): return cl_game = Util.microsegundos_rnd() txt_game = game.save() si_poner_pgn_original_blunders = False si_poner_pgn_original_brilliancies = False n_jugadas = len(game) if self.li_selected: li_moves = self.li_selected else: li_moves = list(range(n_jugadas)) if xlibro_aperturas: li_borrar = [] for pos, njg in enumerate(li_moves): if tmp_bp.is_canceled(): self.xmanager.remove_gui_dispatch() return # # Si esta en el book move = game.move(njg) if xlibro_aperturas.get_list_moves(move.position_before.fen()): li_borrar.append(pos) continue else: break if li_borrar: li_borrar.reverse() for x in li_borrar: del li_moves[x] if self.from_last_move: li_moves.reverse() n_jugadas = len(li_moves) if si_bp2: tmp_bp.ponTotal(2, n_jugadas) else: tmp_bp.ponTotal(n_jugadas) for npos, njg in enumerate(li_moves): if tmp_bp.is_canceled(): self.xmanager.remove_gui_dispatch() return move = game.move(njg) if si_bp2: tmp_bp.pon(2, npos + 1) else: tmp_bp.pon(npos) if self.rut_dispatch_bp: self.rut_dispatch_bp(npos, n_jugadas, njg) if tmp_bp.is_canceled(): self.xmanager.remove_gui_dispatch() return # # Fin de game # if move.siJaqueMate or move.is_draw: # continue # # white y black white_move = move.position_before.is_white if white_move: if not is_white: continue else: if not is_black: continue # -# previos if self.delete_previous: move.analysis = None # -# Procesamos if move.analysis is None: resp = self.xmanager.analizaJugadaPartida( game, njg, self.vtime, depth=self.depth, brDepth=self.dpbrilliancies, brPuntos=self.ptbrilliancies, stability=self.stability, st_centipawns=self.st_centipawns, st_depths=self.st_depths, st_timelimit=self.st_timelimit, ) if not resp: self.xmanager.remove_gui_dispatch() return move.analysis = resp cp = move.position_before mrm, pos_act = move.analysis move.complexity = AnalysisIndexes.calc_complexity(cp, mrm) move.winprobability = AnalysisIndexes.calc_winprobability(cp, mrm) move.narrowness = AnalysisIndexes.calc_narrowness(cp, mrm) move.efficientmobility = AnalysisIndexes.calc_efficientmobility( cp, mrm) move.piecesactivity = AnalysisIndexes.calc_piecesactivity(cp, mrm) move.exchangetendency = AnalysisIndexes.calc_exchangetendency( cp, mrm) if si_blunders or si_brilliancies or self.with_variations or self.themes_lichess: rm = mrm.li_rm[pos_act] rm.ponBlunder(0) mj = mrm.li_rm[0] rm_pts = rm.centipawns_abs() dif = mj.centipawns_abs() - rm_pts mx = max(abs(mj.centipawns_abs()), abs(rm_pts)) dif_porc = int(dif * 100 / mx) if mx > 0 else 0 fen = move.position_before.fen() if self.with_variations: limite = self.alm.limit_include_variations if (limite == 0) or (dif >= limite): if not (self.alm.best_variation and dif == 0): move.analisis2variantes(self.alm, self.delete_previous) ok_blunder = dif >= self.kblunders if ok_blunder and self.kblunders_porc > 0: ok_blunder = dif_porc >= self.kblunders_porc if ok_blunder: rm.ponBlunder(dif) self.graba_tactic(game, njg, mrm, pos_act) if self.save_pgn(self.pgnblunders, mrm.name, game.dicTags(), fen, move, rm, mj): si_poner_pgn_original_blunders = True if self.bmtblunders: self.save_bmt(True, fen, mrm, pos_act, cl_game, txt_game) self.si_bmt_blunders = True if rm.level_brilliant(): move.add_nag(NAG_3) self.save_fns(self.fnsbrilliancies, fen) if self.save_pgn(self.pgnbrilliancies, mrm.name, game.dicTags(), fen, move, rm, None): si_poner_pgn_original_brilliancies = True if self.bmtbrilliancies: self.save_bmt(False, fen, mrm, pos_act, cl_game, txt_game) self.si_bmt_brilliancies = True else: nag, color = mrm.set_nag_color(self.configuration, rm) if nag: move.add_nag(nag) if self.themes_lichess and (mj.mate != 0 or dif > 0): move.assign_themes_lichess() # Ponemos el texto original en la ultima if si_poner_pgn_original_blunders and self.oriblunders: with open(self.pgnblunders, "at", encoding="utf-8", errors="ignore") as q: q.write("\n%s\n\n" % game.pgn()) if si_poner_pgn_original_brilliancies and self.oribrilliancies: with open(self.pgnbrilliancies, "at", encoding="utf-8", errors="ignore") as q: q.write("\n%s\n\n" % game.pgn()) self.xmanager.remove_gui_dispatch()