Beispiel #1
0
    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 _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 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()
Beispiel #4
0
 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
Beispiel #5
0
 def reset(self):
     self.stdout_lock.acquire()
     self.mrm = EngineResponse.MultiEngineResponse(self.name, self.is_white)
     self.stdout_lock.release()
Beispiel #6
0
    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