def getAllFen(self): stFENm2 = set() lilipv = [LCEngine.xpv2pv(xpv).split(" ") for xpv in self.li_xpv] for lipv in lilipv: LCEngine.setFenInicial() for pv in lipv: fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) stFENm2.add(fenM2) LCEngine.makeMove(pv) return stFENm2
def recalcFenM2(self): lilipv = [LCEngine.xpv2pv(xpv).split(" ") for xpv in self.li_xpv] dicFENm2 = {} for lipv in lilipv: LCEngine.setFenInicial() for pv in lipv: fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) if fenM2 not in dicFENm2: dicFENm2[fenM2] = set() dicFENm2[fenM2].add(pv) LCEngine.makeMove(pv) return dicFENm2
def totree(self): parent = ItemTree(None, None, None, None) dic = AperturasStd.ap.dicFenM2 for xpv in self.li_xpv: lipv = LCEngine.xpv2pv(xpv).split(" ") lipgn = LCEngine.xpv2pgn(xpv).replace("\n", " ").strip().split(" ") linom = [] LCEngine.setFenInicial() for pv in lipv: LCEngine.makeMove(pv) fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) linom.append(dic[fenM2].trNombre if fenM2 in dic else "") parent.addLista(lipv, lipgn, linom) return parent
def baseXPV(self, xpv): lipv = LCEngine.xpv2pv(xpv).split(" ") last_ap = None LCEngine.setFenInicial() mx = self.max_ply + 3 for n, pv in enumerate(lipv): if n > mx: break LCEngine.makeMove(pv) fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) if fenM2 in self.dicFenM2: last_ap = self.dicFenM2[fenM2] return last_ap
def preparaTraining(self, reg): maxmoves = reg["MAXMOVES"] siBlancas = reg["COLOR"] == "WHITE" siRandom = reg["RANDOM"] lilipv = [LCEngine.xpv2pv(xpv).split(" ") for xpv in self.li_xpv] if maxmoves: for pos, lipv in enumerate(lilipv): if len(lipv) > maxmoves: lilipv[pos] = lipv[:maxmoves] # Ultimo el usuario for pos, lipv in enumerate(lilipv): if len(lipv) % 2 == (0 if siBlancas else 1): lilipv[pos] = lipv[:-1] # Duplicados stBorrar = set() lista = [(pos, "".join(lipv)) for pos, lipv in enumerate(lilipv)] lista.sort(key=lambda elem: elem[1]) for pos, (posli, pv) in enumerate(lista): for pos1 in range(pos + 1, len(lista)): if lista[pos1][1].startswith(pv): stBorrar.add(posli) break lilipv = [ lipv for pos, lipv in enumerate(lilipv) if pos not in stBorrar ] if siRandom: random.shuffle(lilipv) ligamesST = [] ligamesSQ = [] dicFENm2 = {} for lipv in lilipv: game = {} game["LIPV"] = lipv game["NOERROR"] = 0 game["TRIES"] = [] ligamesST.append(game) game = dict(game) ligamesSQ.append(game) LCEngine.setFenInicial() for pv in lipv: fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) if fenM2 not in dicFENm2: dicFENm2[fenM2] = set() dicFENm2[fenM2].add(pv) LCEngine.makeMove(pv) reg["LIGAMES_STATIC"] = ligamesST if reg["RANDOM"]: random.shuffle(ligamesSQ) reg["LIGAMES_SEQUENTIAL"] = ligamesSQ reg["DICFENM2"] = dicFENm2 bcolor = " w " if siBlancas else " b " liTrainPositions = [] for fenM2 in dicFENm2: if bcolor in fenM2: data = {} data["FENM2"] = fenM2 data["MOVES"] = dicFENm2[fenM2] data["NOERROR"] = 0 data["TRIES"] = [] liTrainPositions.append(data) random.shuffle(liTrainPositions) reg["LITRAINPOSITIONS"] = liTrainPositions
def preparaTraining(self, reg, procesador): maxmoves = reg["MAXMOVES"] siBlancas = reg["COLOR"] == "WHITE" siRandom = reg["RANDOM"] siRepetir = False lilipv = [LCEngine.xpv2pv(xpv).split(" ") for xpv in self.li_xpv] if maxmoves: for pos, lipv in enumerate(lilipv): if len(lipv) > maxmoves: lilipv[pos] = lipv[:maxmoves] # Ultimo el usuario for pos, lipv in enumerate(lilipv): if len(lipv) % 2 == (0 if siBlancas else 1): lilipv[pos] = lipv[:-1] # Quitamos las repetidas lilipvfinal = [] nt = len(lilipv) for x in range(nt - 1): pvmirar = "".join(lilipv[x]) esta = False for y in range(x + 1, nt): pvotro = "".join(lilipv[y]) if pvotro.startswith(pvmirar): esta = True break if not esta: lilipvfinal.append(lilipv[x]) lilipv = lilipvfinal ligamesST = [] ligamesSQ = [] dicFENm2 = {} for lipv in lilipv: game = {} game["LIPV"] = lipv game["NOERROR"] = 0 game["TRIES"] = [] ligamesST.append(game) game = dict(game) ligamesSQ.append(game) LCEngine.setFenInicial() for pv in lipv: fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) if fenM2 not in dicFENm2: dicFENm2[fenM2] = set() dicFENm2[fenM2].add(pv) LCEngine.makeMove(pv) if not siRepetir: stBorrar = set() xanalyzer = procesador.XAnalyzer() for stpv, fenM2 in dicFENm2.iteritems(): if len(stpv) > 1: siW = " w " in fenM2 if siW and siBlancas: dic = self.getfenvalue(fenM2) if "ANALISIS" not in dic: dic["ANALISIS"] = xanalyzer.analiza(fen) self.setfenvalue(fenM2, dic) mrm = dic["ANALISIS"] pvsel = stpv[0] # el primero que encuentre por defecto for rm in mrm.liMultiPV(): pv0 = rm.movimiento() if pv0 in stpv: pvsel = pv0 stpv.remove(pvsel) break dicFENm2[fenM2] = {pvsel} for pv in stpv: stBorrar.add("%s|%s" % (fenM2, pv)) liBorrar = [] for n, game in enumerate(ligamesSQ): LCEngine.setFenInicial() for pv in game["LIPV"]: fen = LCEngine.getFen() fenM2 = LCEngine.fen2fenM2(fen) key = "%s|%s" % (fenM2, pv) if key in stBorrar: liBorrar.append(n) break LCEngine.makeMove(pv) liBorrar.sort(reverse=True) for n in liBorrar: del ligamesSQ[n] del ligamesST[n] if siRandom: random.shuffle(ligamesSQ) random.shuffle(ligamesST) reg["LIGAMES_STATIC"] = ligamesST reg["LIGAMES_SEQUENTIAL"] = ligamesSQ reg["DICFENM2"] = dicFENm2 bcolor = " w " if siBlancas else " b " liTrainPositions = [] for fenM2 in dicFENm2: if bcolor in fenM2: data = {} data["FENM2"] = fenM2 data["MOVES"] = dicFENm2[fenM2] data["NOERROR"] = 0 data["TRIES"] = [] liTrainPositions.append(data) random.shuffle(liTrainPositions) reg["LITRAINPOSITIONS"] = liTrainPositions