def preparaTrainingEngines(self, configuration, reg): reg["DICFENM2"] = self.recalcFenM2() reg["TIMES"] = [500, 1000, 2000, 4000, 8000] reg["ENGINES"] = EnginesBunch.bunch(reg["KEY_ENGINE"], reg["NUM_ENGINES"], configuration.dic_engines)
def trainNewEngines(self): training = self.dbop.trainingEngines() color = "WHITE" basepv = self.dbop.basePV mandatory = basepv.count(" ") + 1 if len(basepv) > 0 else 0 control = 10 lost_points = 20 engine_control = self.configuration.tutor.key engine_time = 5.0 num_engines = 20 key_engine = "alaric" ext_engines = [] auto_analysis = True ask_movesdifferent = False times = [500, 1000, 2000, 4000, 8000] books = ["", "", "", "", ""] books_sel = ["", "", "", "", ""] if training is not None: color = training["COLOR"] mandatory = training.get("MANDATORY", mandatory) control = training.get("CONTROL", control) lost_points = training.get("LOST_POINTS", lost_points) engine_control = training.get("ENGINE_CONTROL", engine_control) engine_time = training.get("ENGINE_TIME", engine_time) num_engines = training.get("NUM_ENGINES", num_engines) key_engine = training.get("KEY_ENGINE", key_engine) ext_engines = training.get("EXT_ENGINES", ext_engines) auto_analysis = training.get("AUTO_ANALYSIS", auto_analysis) ask_movesdifferent = training.get("ASK_MOVESDIFFERENT", ask_movesdifferent) times = training.get("TIMES", times) books = training.get("BOOKS", books) books_sel = training.get("BOOKS_SEL", books_sel) separador = FormLayout.separador li_gen = [separador] liJ = [(_("White"), "WHITE"), (_("Black"), "BLACK")] config = FormLayout.Combobox(_("Play with"), liJ) li_gen.append((config, color)) li_gen.append((_("Mandatory moves") + ":", mandatory)) li_gen.append(separador) li_gen.append((_("Moves until the control") + ":", control)) li_gen.append(separador) li_gen.append( (_("Maximum number of lost centipawns to pass control") + ":", lost_points)) li_gen.append(separador) dic_engines = self.configuration.dic_engines li_engines = EnginesBunch.lista(dic_engines) config = FormLayout.Spinbox( "%s: %s" % (_("Automatic selection"), _("number of engines")), 0, len(li_engines), 50) li_gen.append((config, num_engines)) likeys = [(dic_engines[x].name, x) for x in li_engines if x in dic_engines] config = FormLayout.Combobox( "%s: %s" % (_("Automatic selection"), _("bunch of engines")), likeys) li_gen.append((config, key_engine)) li_gen.append(separador) config = FormLayout.Combobox(_("Engine that does the control"), self.configuration.comboMotores()) li_gen.append((config, engine_control)) li_gen.append( (_("Duration of analysis (secs)") + ":", float(engine_time))) li_gen.append(separador) li_gen.append((_("Automatic analysis") + ":", auto_analysis)) li_gen.append(separador) li_gen.append( (_("Ask when the moves are different from the line") + ":", ask_movesdifferent)) li = [("--", "")] for key, cm in self.configuration.dic_engines.items(): li.append((cm.nombre_ext(), key)) li = sorted(li, key=operator.itemgetter(1)) li_ext = [] for x in range(16): config = FormLayout.Combobox("%s %d" % (_("Engine"), x + 1), li) key = ext_engines[x] if len(ext_engines) > x else "" li_ext.append((config, key)) liLevels = [separador] list_books = Books.ListBooks() list_books.restore_pickle(self.configuration.file_books) list_books.check() libooks = [(bookx.name, bookx) for bookx in list_books.lista] libooks.insert(0, ("--", None)) li_books_sel = (("", ""), (_("Uniform random"), "au"), (_("Proportional random"), "ap"), (_("Always the highest percentage"), "mp")) for level in range(5): n = level + 1 title = "%s %d" % (_("Level"), n) # liLevels.append((None, title)) tm = times[level] / 1000.0 if len(times) > level else 0.0 liLevels.append( ("%s. %s:" % (title, _("Time engines think in seconds")), tm)) bk = books[level] if len(books) > level else "" book = list_books.buscaLibro(bk) if bk else None config = FormLayout.Combobox(_("Book"), libooks) liLevels.append((config, book)) config = FormLayout.Combobox(_("Book selection mode"), li_books_sel) liLevels.append((config, books_sel[level])) lista = [] lista.append((li_gen, _("Basic data"), "")) lista.append((li_ext, _("Manual engine selection"), "")) lista.append((liLevels, _("Levels"), "")) resultado = FormLayout.fedit(lista, title=_("With engines"), parent=self, anchoMinimo=360, icon=Iconos.Study()) if resultado is None: return accion, liResp = resultado selMotoresExt = [] li_gen, li_ext, liLevels = liResp for key in li_ext: if key: selMotoresExt.append(key) reg = {} ( reg["COLOR"], reg["MANDATORY"], reg["CONTROL"], reg["LOST_POINTS"], reg["NUM_ENGINES"], reg["KEY_ENGINE"], reg["ENGINE_CONTROL"], reg["ENGINE_TIME"], reg["AUTO_ANALYSIS"], reg["ASK_MOVESDIFFERENT"], ) = li_gen reg["EXT_ENGINES"] = selMotoresExt if (len(selMotoresExt) + reg["NUM_ENGINES"]) == 0: reg["NUM_ENGINES"] = 1 times = [] books = [] books_sel = [] for x in range(5): tm = int(liLevels[x * 3] * 1000) bk = liLevels[x * 3 + 1] bk_mode = liLevels[x * 3 + 2] if tm: times.append(tm) books.append(bk.name if bk else "") books_sel.append(bk_mode) if len(times) == 0: times.append(500) books.append(None) reg["TIMES"] = times reg["BOOKS"] = books reg["BOOKS_SEL"] = books_sel self.dbop.createTrainingEngines(reg, self.procesador) QTUtil2.message_bold(self, _("Created"))