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.play_time(self.game, 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 juega(self, fen): if self.opening: pv = self.book.eligeJugadaTipo(fen, "au") if pv: self.opening -= 1 rmrival = EngineResponse.EngineResponse("Opening", "w" in fen) rmrival.from_sq = pv[:2] rmrival.to_sq = pv[2:4] rmrival.promotion = pv[4:] return rmrival else: self.opening = 0 total = self.cromo.aleatorio + self.cromo.captura + self.cromo.esquivo + self.cromo.similar + self.cromo.bien bola = random.randint(1, total) if bola <= self.cromo.aleatorio: return self.juega_aleatorio(fen) bola -= self.cromo.aleatorio if bola <= self.cromo.captura: return self.juega_captura(fen) bola -= self.cromo.captura if bola <= self.cromo.esquivo: return self.juega_esquivo(fen) bola -= self.cromo.esquivo if bola <= self.cromo.bien: return self.juega_irina(fen) else: return self.juega_similar(fen)
def valora(self, position, from_sq, to_sq, promotion): self.testEngine() posicionNueva = position.copia() posicionNueva.mover(from_sq, to_sq, promotion) fen = posicionNueva.fen() if FasterCode.fen_ended(fen): rm = EngineResponse.EngineResponse("", position.is_white) rm.sinInicializar = False self.sinMovimientos = True self.pv = from_sq + to_sq + promotion self.from_sq = from_sq self.to_sq = to_sq self.promotion = promotion return rm mrm = self.engine.bestmove_fen(fen, self.motorTiempoJugada, self.motorProfundidad) rm = mrm.mejorMov() rm.cambiaColor(position) mv = from_sq + to_sq + (promotion if promotion else "") rm.pv = mv + " " + rm.pv rm.from_sq = from_sq rm.to_sq = to_sq rm.promotion = promotion if promotion else "" rm.is_white = position.is_white return rm
def _mejorMov(self, max_time, max_depth, is_white): env = "go" if max_depth: env += " depth %d" % max_depth elif max_time: env += " movetime %d" % max_time msTiempo = 10000 if max_time: msTiempo = max_time elif max_depth: msTiempo = int(max_depth * msTiempo / 3.0) if self.gui_dispatch: li_resp, result = self.pwait_list_dispatch(env, "bestmove", msTiempo) else: li_resp, result = self.pwait_list(env, "bestmove", msTiempo) if not result: return None mrm = EngineResponse.MultiEngineResponse(self.name, is_white) for linea in li_resp: mrm.dispatch(linea) mrm.max_time = max_time mrm.max_depth = max_depth mrm.ordena() return mrm
def restore(self, block): dic = Util.zip2var(block) move = dic["move"] self.from_sq, self.to_sq, self.promotion = move[:2], move[2:4], move[ 4:] cp = self.position_before.copia() cp.mover(self.from_sq, self.to_sq, self.promotion) self.position = cp self.in_the_opening = dic["in_the_opening"] if "variations" in dic: self.variations.restore(dic["variations"]) if "comment" in dic: self.comment = dic["comment"] if "time_ms" in dic: self.time_ms = dic["time_ms"] if "li_nags" in dic: self.li_nags = dic["li_nags"] if "analysis" in dic: save_mrm, pos = dic["analysis"] mrm = EngineResponse.MultiEngineResponse("", True) mrm.restore(save_mrm) self.analysis = mrm, pos else: self.analysis = None
def analizaJugadaPartida( self, game, njg, vtime, depth=0, brDepth=5, brPuntos=50, stability=False, st_centipawns=0, st_depths=0, st_timelimit=0, ): self.testEngine() if stability: mrm = self.engine.analysis_stable(game, njg, vtime, depth, True, st_centipawns, st_depths, st_timelimit) else: mrm = self.engine.bestmove_game_jg(game, njg, vtime, depth, is_savelines=True) if njg > 9000: return mrm, 0 move = game.move(njg) mv = move.movimiento() if not mv: return mrm, 0 rm, n = mrm.buscaRM(mv) if rm: if n == 0: mrm.miraBrilliancies(brDepth, brPuntos) return mrm, n # No esta considerado, obliga a hacer el analysis de nuevo from_sq position mrm_next = self.engine.bestmove_game_jg(game, njg + 1, vtime, depth, is_savelines=True) if mrm_next and mrm_next.li_rm: rm = mrm_next.li_rm[0] rm.cambiaColor(move.position) rm.pv = mv + " " + rm.pv else: rm = EngineResponse.EngineResponse(self.name, mrm_next.is_white) rm.pv = mv rm.from_sq = mv[:2] rm.to_sq = mv[2:4] rm.promotion = mv[4] if len(mv) == 5 else "" rm.is_white = move.position_before.is_white pos = mrm.agregaRM(rm) return mrm, pos
def play_next_move(self): if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white if self.game.is_finished(): self.muestra_resultado() return if self.hints == 0: if self.categoria.sinAyudasFinal: self.remove_hints() self.is_tutor_enabled = False siRival = is_white == self.is_engine_side_white self.set_side_indicator(is_white) self.refresh() if siRival: self.thinking(True) self.disable_all() siPensar = True if self.in_the_opening: ok, from_sq, to_sq, promotion = self.opening.run_engine( self.last_fen()) if ok: 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 siPensar = False else: self.in_the_opening = False if siPensar: self.rm_rival = self.xrival.play_game(self.game) self.thinking(False) if self.play_rival(self.rm_rival): self.play_next_move() else: self.human_is_playing = True self.activate_side(is_white) self.analizaInicio()
def analysis_move(self, move, vtime, depth=0, brDepth=5, brPuntos=50): self.check_engine() mrm = self.engine.bestmove_fen(move.position_before.fen(), vtime, depth, is_savelines=True) mv = move.movimiento() if not mv: return mrm, 0 rm, n = mrm.buscaRM(move.movimiento()) if rm: if n == 0: mrm.miraBrilliancies(brDepth, brPuntos) return mrm, n # No esta considerado, obliga a hacer el analysis de nuevo from_sq position if move.is_mate or move.is_draw: rm = EngineResponse.EngineResponse(self.name, move.position_before.is_white) rm.from_sq = mv[:2] rm.to_sq = mv[2:4] rm.promotion = mv[4] if len(mv) == 5 else "" rm.pv = mv else: position = move.position mrm1 = self.engine.bestmove_fen(position.fen(), vtime, depth) if mrm1 and mrm1.li_rm: rm = mrm1.li_rm[0] rm.cambiaColor(position) rm.pv = mv + " " + rm.pv else: rm = EngineResponse.EngineResponse(self.name, mrm1.is_white) rm.pv = mv rm.from_sq = mv[:2] rm.to_sq = mv[2:4] rm.promotion = mv[4] if len(mv) == 5 else "" rm.is_white = move.position_before.is_white pos = mrm.agregaRM(rm) return mrm, pos
def analizaVariation(self, move, vtime, is_white): self.testEngine() mrm = self.engine.bestmove_fen(move.position.fen(), vtime, None) if mrm.li_rm: rm = mrm.li_rm[0] # if is_white != move.position.is_white: # if rm.mate: # rm.mate += +1 if rm.mate > 0 else -1 else: rm = EngineResponse.EngineResponse("", is_white) return rm
def phase2(self, entry:os.DirEntry): db = LIBridge(entry.path) for x in range(len(db)): dato = db[x] dic = eval(dato) if "INIFEN" in dic: g = Game.Game(fen=dic["INIFEN"]) else: g = Game.Game() g.set_tags(dic["LITAGS"]) result = g.get_tag("Result") g.set_termination(dic["TERMINATION"], result if result else RESULT_UNKNOWN) li_moves = dic["MOVES"] current_position = g.last_position.copia() for dic_mv in li_moves: pv = dic_mv["MV"] position = current_position.copia() position.moverPV(pv) move = Move.Move(g, position_before=current_position, position=position, from_sq=pv[:2], to_sq=pv[2:4], promotion=pv[4:]) if "VARIATIONS" in dic_mv: li_varpgn = dic_mv["VARIATIONS"] fen_base = current_position.fen() for varpgn in li_varpgn: gv = Game.fen_game(fen_base, varpgn) if gv: move.add_variation(gv) if "COMMENT" in dic_mv: move.comment = dic_mv["COMMENT"] if "$NAGS" in dic_mv: nags = dic_mv["$NAGS"] for nag in nags.split(" "): if nag.isdigit(): move.add_nag(int(nag)) if "NAGS" in dic_mv: nags = dic_mv["NAGS"] for nag in nags.split(" "): if nag in self.dic_cnags: move.add_nag(self.dic_cnags[nag]) if "MRM" in dic_mv: mrm_pos = dic_mv["MRM_POS"] mrm_save = dic_mv["MRM"] mrm = EngineResponse.MultiEngineResponse(None, True) mrm.restore(mrm_save) move.analysis = mrm, mrm_pos current_position = position.copia() g.add_move(move) print(dic) db.close()
def siguienteJugada(self): if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white self.set_side_indicator(is_white) self.refresh() fen = self.game.last_position.fen() siRival = is_white == self.is_book_side_white book = self.book_rival if siRival else self.book_player self.list_moves = book.get_list_moves(fen) if not self.list_moves: self.put_result() return if siRival: self.disable_all() nli = len(self.list_moves) if nli > 1: resp = self.select_rival_move() else: resp = self.list_moves[0][0], self.list_moves[0][ 1], self.list_moves[0][2] xfrom, xto, promotion = resp self.book_move = EngineResponse.EngineResponse( "Apertura", self.is_book_side_white) self.book_move.from_sq = xfrom self.book_move.to_sq = xto self.book_move.promotion = promotion self.play_rival(self.book_move) self.siguienteJugada() else: self.human_is_playing = True self.activate_side(is_white)
def ajustaPlayer(self, mrm): position = self.game.last_position FasterCode.set_fen(position.fen()) li = FasterCode.get_exmoves() li_options = [] for rm in mrm.li_rm: li_options.append((rm, "%s (%s)" % (position.pgn_translated( rm.from_sq, rm.to_sq, rm.promotion), rm.abrTexto()))) mv = rm.movimiento() for x in range(len(li)): if li[x].move() == mv: del li[x] break for mj in li: rm = EngineResponse.EngineResponse("", position.is_white) rm.from_sq = mj.from_sq() rm.to_sq = mj.to_sq() rm.promotion = mj.promotion() rm.puntos = None li_options.append( (rm, position.pgn_translated(rm.from_sq, rm.to_sq, rm.promotion))) if len(li_options) == 1: return li_options[0][0] menu = QTVarios.LCMenu(self.main_window) titulo = _("White") if position.is_white else _("Black") icono = Iconos.Carpeta() self.main_window.cursorFueraBoard() menu.opcion(None, titulo, icono) menu.separador() icono = Iconos.PuntoNaranja( ) if position.is_white else Iconos.PuntoNegro() for rm, txt in li_options: menu.opcion(rm, txt, icono) while True: resp = menu.lanza() if resp: return resp
def pwait_list_dispatch(self, orden, txt_busca, maxtime): self.put_line(orden) ini = time.time() tm_dispatch = ini li = [] mrm = EngineResponse.MultiEngineResponse(self.name, self.is_white) while time.time() - ini < maxtime: if (time.time() - tm_dispatch) >= 1.0: mrm.ordena() rm = mrm.mejorMov() if not self.gui_dispatch(rm): return li, False tm_dispatch = time.time() line = self.stdout.readline().strip().decode("utf-8", errors="ignore") if self.log: self.log_write(line) li.append(line) mrm.dispatch(line) if line.startswith(txt_busca): return li, True return li, False
def siguiente_jugada(self): self.muestraInformacion() if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white self.ponIndicador(is_white) self.refresh() siRival = is_white == self.is_engine_side_white num_moves = len(self.game) if num_moves >= self.numPV: self.partidaTerminada(True) return pv = self.liPV[num_moves] if siRival: self.disable_all() self.rm_rival = EngineResponse.EngineResponse( "Apertura", self.is_engine_side_white) self.rm_rival.from_sq = pv[:2] self.rm_rival.to_sq = pv[2:4] self.rm_rival.promotion = pv[4:] self.mueve_rival(self.rm_rival) self.siguiente_jugada() else: self.activaColor(is_white) self.human_is_playing = True if self.siAyuda: self.muestraAyuda()
def play_next_move(self): self.muestraInformacion() if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white self.set_side_indicator(is_white) self.refresh() siRival = is_white == self.is_engine_side_white num_moves = len(self.game) if num_moves >= self.numPV: self.gameTerminada(True) return pv = self.li_pv[num_moves] if siRival: self.disable_all() self.rm_rival = EngineResponse.EngineResponse( "Opening", self.is_engine_side_white) self.rm_rival.from_sq = pv[:2] self.rm_rival.to_sq = pv[2:4] self.rm_rival.promotion = pv[4:] self.play_rival(self.rm_rival) self.play_next_move() else: self.activate_side(is_white) self.human_is_playing = True if self.siAyuda: self.muestraAyuda()
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
def play_next_move(self): if self.state == ST_ENDGAME: return self.ponRotuloActual() self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white if self.game.is_finished(): self.autosave() if self.game.is_mate(): si_ganado = self.human_side != is_white if si_ganado: self.movimientos += 2001 self.finJuego(True) self.guardarGanados(si_ganado) return if self.game.is_draw(): self.movimientos += 1001 self.finJuego(True) self.guardarGanados(False) return siRival = is_white == self.is_engine_side_white self.set_side_indicator(is_white) self.refresh() if siRival: self.thinking(True) self.disable_all() siPensar = True puntosRivalPrevio = self.puntosRival if self.in_the_opening: ok, from_sq, to_sq, promotion = self.opening.run_engine( self.last_fen()) if ok: 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 siPensar = False if siPensar: self.rm_rival = self.xrival.juegaSegundos(self.segundos) self.puntosRival = self.rm_rival.centipawns_abs() self.ponRotuloActual() self.thinking(False) if self.play_rival(self.rm_rival): lostmovepoints = self.puntosRival - puntosRivalPrevio if self.siBoxing and self.puntosRival > self.puntos: if self.check(): return if self.siBoxing and self.maxerror and lostmovepoints > self.maxerror: if self.check(): return self.play_next_move() else: self.human_is_playing = True self.activate_side(is_white)
def siguiente_jugada(self): if self.state == ST_ENDGAME: return self.ponRotuloActual() self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white if self.game.is_finished(): if self.game.is_mate(): si_ganado = self.is_human_side_white != is_white if si_ganado: self.movimientos += 2001 self.finJuego(True) self.guardarGanados(si_ganado) return if self.game.is_draw(): self.movimientos += 1001 self.finJuego(True) self.guardarGanados(False) return siRival = is_white == self.is_engine_side_white self.ponIndicador(is_white) self.refresh() if siRival: self.pensando(True) self.disable_all() siPensar = True puntosRivalPrevio = self.puntosRival if self.in_the_opening: siBien, from_sq, to_sq, promotion = self.opening.run_engine( self.fenUltimo()) if siBien: 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 siPensar = False if siPensar: self.rm_rival = self.xrival.juegaSegundos(self.segundos) self.puntosRival = self.rm_rival.centipawns_abs() self.ponRotuloActual() self.pensando(False) if self.mueve_rival(self.rm_rival): lostmovepoints = self.puntosRival - puntosRivalPrevio if self.siBoxing and self.puntosRival > self.puntos: if self.comprueba(): return if self.siBoxing and self.maxerror and lostmovepoints > self.maxerror: if self.comprueba(): return self.siguiente_jugada() else: self.human_is_playing = True self.activaColor(is_white)
def play_next_move(self): if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white num_moves = len(self.game) if self.game.is_finished(): self.show_result() return siRival = is_white == self.is_engine_side_white self.set_side_indicator(is_white) self.refresh() if siRival: self.reloj_start(False) self.thinking(True) self.disable_all() siEncontrada = False if self.book: if self.game.last_position.num_moves >= self.maxMoveBook: self.book = None else: fen = self.last_fen() pv = self.book.eligeJugadaTipo( fen, "au" if len(self.game) > 2 else "ap") if pv: rm_rival = EngineResponse.EngineResponse( "Opening", self.is_engine_side_white) rm_rival.from_sq = pv[:2] rm_rival.to_sq = pv[2:4] rm_rival.promotion = pv[4:] siEncontrada = True else: self.book = None if not siEncontrada: tiempoBlancas = self.vtime[True].tiempoPendiente tiempoNegras = self.vtime[False].tiempoPendiente mrm = self.xrival.play_time_tourney(self.game, tiempoBlancas, tiempoNegras, self.secs_move) if mrm is None: self.thinking(False) return False rm_rival = mrm.mejorMov() self.reloj_stop(False) self.thinking(False) if self.play_rival(rm_rival): self.lirm_engine.append(rm_rival) if self.valoraRMrival(): self.play_next_move() else: if self.game.is_finished(): self.show_result() return else: self.game.set_termination(TERMINATION_RESIGN, RS_WIN_PLAYER) self.show_result() return else: self.reloj_start(True) self.human_is_playing = True self.activate_side(is_white)
def juegaRival(self, is_white): self.board.remove_arrows() self.reloj_start(False) self.timekeeper.start() self.human_is_playing = False self.rm_rival = None self.pon_toolbar() if not self.is_tutor_enabled: self.activate_side(self.human_side) from_sq = to_sq = promotion = "" is_choosed = False # CACHE--------------------------------------------------------------------------------------------------------- fen_ultimo = self.last_fen() if fen_ultimo in self.cache: move = self.cache[fen_ultimo] self.add_move(move, False) self.move_the_pieces(move.liMovs, True) if self.siTiempo: self.vtime[self.is_engine_side_white].restore(move.cacheTime) self.show_clocks() return self.play_next_move() # OPENING MANDATORY--------------------------------------------------------------------------------------------- if self.opening_mandatory: is_choosed, from_sq, to_sq, promotion = self.opening_mandatory.run_engine(fen_ultimo) if not is_choosed: self.opening_mandatory = None # BOOK---------------------------------------------------------------------------------------------------------- if not is_choosed and self.book_rival_active: if self.book_rival_depth == 0 or self.book_rival_depth >= len(self.game): is_choosed, from_sq, to_sq, promotion = self.eligeJugadaBook() if not is_choosed: self.book_rival_active = False else: self.book_rival_active = False self.ponRotuloBasico() if not is_choosed and self.siBookAjustarFuerza: is_choosed, from_sq, to_sq, promotion = self.eligeJugadaBookAjustada() # book de la personalidad if not is_choosed: self.siBookAjustarFuerza = False # -------------------------------------------------------------------------------------------------------------- if is_choosed: rm_rival = EngineResponse.EngineResponse("Opening", self.is_engine_side_white) rm_rival.from_sq = from_sq rm_rival.to_sq = to_sq rm_rival.promotion = promotion self.play_rival(rm_rival) else: self.thinking(True) if self.siTiempo: seconds_white = self.vtime[True].tiempoPendiente seconds_black = self.vtime[False].tiempoPendiente seconds_move = self.segundosJugada else: seconds_white = seconds_black = 10 * 60 seconds_move = 0 self.xrival.play_time_routine( self.game, self.main_window.notify, seconds_white, seconds_black, seconds_move, nAjustado=self.nAjustarFuerza )
def reset(self): self.stdout_lock.acquire() self.mrm = EngineResponse.MultiEngineResponse(self.name, self.is_white) self.stdout_lock.release()
def play_next_move(self): if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white if self.game.is_finished(): self.muestra_resultado() return siRival = is_white == self.is_engine_side_white self.set_side_indicator(is_white) self.refresh() if siRival: self.thinking(True) self.disable_all() iniT = time.time() siPensar = True if self.in_the_opening: dT, hT = 5, 5 ok, from_sq, to_sq, promotion = self.opening.run_engine(self.last_fen()) if ok: rm_rival = EngineResponse.EngineResponse("Opening", self.is_engine_side_white) rm_rival.from_sq = from_sq rm_rival.to_sq = to_sq rm_rival.promotion = promotion siPensar = False if siPensar: if self.siRivalInterno: rm_rival = self.xrival.juega() dT, hT = 5, 15 else: nJugadas = len(self.game) if nJugadas > 30: tp = 300 else: tp = 600 rm_rival = self.xrival.juegaTiempo(tp, tp, 0) # engloba juega + juega Tiempo pts = rm_rival.centipawns_abs() if pts > 100: dT, hT = 5, 15 else: dT, hT = 10, 35 difT = time.time() - iniT t = random.randint(dT * 10, hT * 10) * 0.01 if difT < t: time.sleep(t - difT) self.thinking(False) if self.play_rival(rm_rival): self.lirm_engine.append(rm_rival) if self.valoraRMrival(): self.play_next_move() else: self.muestra_resultado() self.autosave() return else: self.human_is_playing = True self.activate_side(is_white)
def siguiente_jugada(self): if self.state == ST_ENDGAME: return self.state = ST_PLAYING self.human_is_playing = False self.put_view() is_white = self.game.last_position.is_white num_moves = len(self.game) if num_moves > 0: jgUltima = self.game.last_jg() if jgUltima: if jgUltima.is_mate: self.put_result(RS_WIN_OPPONENT if self.is_human_side_white == is_white else RS_WIN_PLAYER) return if jgUltima.is_draw_stalemate: self.put_result(RS_DRAW) return if jgUltima.is_draw_repetition: self.put_result(RS_DRAW_REPETITION) return if jgUltima.is_draw_50: self.put_result(RS_DRAW_50) return if jgUltima.is_draw_material: self.put_result(RS_DRAW_MATERIAL) return siRival = is_white == self.is_engine_side_white self.ponIndicador(is_white) self.refresh() if siRival: self.reloj_start(False) self.pensando(True) self.disable_all() siEncontrada = False if self.book: if self.game.last_position.num_moves >= self.maxMoveBook: self.book = None else: fen = self.fenUltimo() pv = self.book.eligeJugadaTipo(fen, "ap") if pv: rm_rival = EngineResponse.EngineResponse( "Apertura", self.is_engine_side_white) rm_rival.from_sq = pv[:2] rm_rival.to_sq = pv[2:4] rm_rival.promotion = pv[4:] siEncontrada = True else: self.book = None if not siEncontrada: tiempoBlancas = self.vtime[True].tiempoPendiente tiempoNegras = self.vtime[False].tiempoPendiente mrm = self.xrival.juegaTiempoTorneo(self.game, tiempoBlancas, tiempoNegras, self.segundosJugada) if mrm is None: self.pensando(False) return False rm_rival = mrm.mejorMov() self.reloj_stop(False) self.pensando(False) if self.mueve_rival(rm_rival): self.lirm_engine.append(rm_rival) if self.valoraRMrival(rm_rival): self.siguiente_jugada() else: self.put_result(RS_WIN_PLAYER) else: self.reloj_start(True) self.human_is_playing = True self.activaColor(is_white)
def juegaRival(self, is_white): self.board.remove_arrows() self.human_is_playing = False self.rm_rival = None self.pon_toolbar() if not self.is_tutor_enabled: self.activate_side(self.human_side) fen_ultimo = self.last_fen() if fen_ultimo in self.cache: move = self.cache[fen_ultimo] self.add_move(move, False) self.move_the_pieces(move.liMovs, True) if self.siTiempo: self.vtime[self.is_engine_side_white].restore(move.cacheTime) return self.play_next_move() from_sq = to_sq = promotion = "" si_encontrada = False if self.aperturaObl: si_encontrada, from_sq, to_sq, promotion = self.aperturaObl.run_engine( fen_ultimo) if not si_encontrada: self.aperturaObl = None if not si_encontrada and self.bookR: if self.game.last_position.num_moves < self.maxMoveBook: si_encontrada, from_sq, to_sq, promotion = self.eligeJugadaBook( ) if not si_encontrada: self.bookR = None if not si_encontrada and self.aperturaStd: si_encontrada, from_sq, to_sq, promotion = self.aperturaStd.run_engine( fen_ultimo) if not si_encontrada: self.aperturaStd = None if not si_encontrada and self.siBookAjustarFuerza: si_encontrada, from_sq, to_sq, promotion = self.eligeJugadaBookAjustada( ) # book de la personalidad if not si_encontrada: self.siBookAjustarFuerza = False if si_encontrada: rm_rival = EngineResponse.EngineResponse("Opening", self.is_engine_side_white) rm_rival.from_sq = from_sq rm_rival.to_sq = to_sq rm_rival.promotion = promotion self.play_rival(rm_rival) else: self.thinking(True) self.reloj_start(False) self.timekeeper.start() if self.siTiempo: tiempoBlancas = self.vtime[True].tiempoPendiente tiempoNegras = self.vtime[False].tiempoPendiente segundosJugada = self.segundosJugada else: tiempoBlancas = tiempoNegras = 10 * 60 * 1000 segundosJugada = 0 self.xrival.play_time(self.main_window.notify, tiempoBlancas, tiempoNegras, segundosJugada, nAjustado=self.nAjustarFuerza)
def phase2(self, pb: QTUtil2.BarraProgreso1, entry: os.DirEntry): dest = entry.name name = ".".join(entry.name.split(".")[:-2]) pb.ponRotulo(name) li = dest.split(".") dest = ".".join(li[:-2]) path_dest = os.path.join(Code.configuration.folder_databases(), dest + ".lcdb") db_dest = DBgames.DBgames(path_dest) db_ori = LIVersion11(entry.path) total = len(db_ori) pb.ponTotal(total) for x in range(total): pb.pon(x + 1) if pb.is_canceled(): break dic = db_ori[x] g = Game.Game(fen=dic.get("INIFEN")) g.set_tags(dic["LITAGS"]) result = g.get_tag("Result") g.set_termination(dic["TERMINATION"], result if result else RESULT_UNKNOWN) li_moves = dic["MOVES"] current_position = g.last_position.copia() for dic_mv in li_moves: pv = dic_mv["M"] position = current_position.copia() position.moverPV(pv) move = Move.Move(g, position_before=current_position, position=position, from_sq=pv[:2], to_sq=pv[2:4], promotion=pv[4:]) if "VARIATIONS" in dic_mv: li_varpgn = dic_mv["VARIATIONS"] fen_base = current_position.fen() for varpgn in li_varpgn: gv = Game.fen_game(fen_base, varpgn) if gv: move.add_variation(gv) if "COMMENT" in dic_mv: move.comment = dic_mv["COMMENT"] if "$NAGS" in dic_mv: nags = dic_mv["$NAGS"] for nag in nags.split(" "): if nag.isdigit(): move.add_nag(int(nag)) if "NAGS" in dic_mv: nags = dic_mv["NAGS"] for nag in nags.split(" "): if nag in self.dic_cnags: move.add_nag(self.dic_cnags[nag]) if "AMRM" in dic_mv: mrm_pos = dic_mv["APOS"] mrm_save = dic_mv["AMRM"] mrm = EngineResponse.MultiEngineResponse(None, True) mrm.restore(mrm_save) move.analysis = mrm, mrm_pos current_position = position.copia() g.add_move(move) db_dest.insert(g) db_ori.close() if pb.is_canceled(): db_dest.close() return False db_dest.commit() db_dest.close() shutil.move(entry.path, entry.path + ".imported") return True