diff --git a/python/src/ffcraft_solver/__main__.py b/python/src/ffcraft_solver/__main__.py index 63df2e4..1100353 100644 --- a/python/src/ffcraft_solver/__main__.py +++ b/python/src/ffcraft_solver/__main__.py @@ -200,7 +200,10 @@ class Solution: def request_solve() -> True: - best_quality.result = solver.Solver(user, recipe).best_quality + all_results = solver.Solver(user, recipe) + best_quality.result = all_results.best_quality + least_steps.result = all_results.least_steps + safe_50.result = all_results.safe_50 dpg.set_value(results, best_quality.result) return True @@ -220,6 +223,8 @@ if __name__ == '__main__': user = User() recipe = Recipe() best_quality = Solution("Best Quality") + least_steps = Solution("Least Steps") + safe_50 = Solution("Safe Margin") full_config = loader.Loader() characters_names = full_config.get_users_names() @@ -280,18 +285,19 @@ if __name__ == '__main__': dpg.add_button(label="Solve!", callback=request_solve) dpg.add_text() dpg.add_collapsing_header(label="Results", leaf=True) + # TODO: Add feedback when pressed with dpg.group(horizontal=True): results = dpg.add_input_text(multiline=True, height=220, readonly=True) with dpg.child_window(autosize_x=True, height=220): dpg.add_button(label="BEST QUALITY", width=136, callback=best_quality.print_result) dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) - dpg.add_button(label="SAFE MARGIN", width=136, callback=best_quality.print_result) - dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) - dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) - dpg.add_button(label="QUICKEST", width=136, callback=best_quality.print_result) - dpg.add_button(label="Macro 1", width=136, callback=best_quality.print_macro_1) - dpg.add_button(label="Macro 2", width=136, callback=best_quality.print_macro_2) + dpg.add_button(label="SAFE MARGIN", width=136, callback=safe_50.print_result) + dpg.add_button(label="Macro 1", width=136, callback=safe_50.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=safe_50.print_macro_2) + dpg.add_button(label="QUICKEST", width=136, callback=least_steps.print_result) + dpg.add_button(label="Macro 1", width=136, callback=least_steps.print_macro_1) + dpg.add_button(label="Macro 2", width=136, callback=least_steps.print_macro_2) # LOG log_window = dpg.add_input_text(multiline=True, default_value=loggers.log, height=50, width=500, diff --git a/python/src/ffcraft_solver/modules/solver.py b/python/src/ffcraft_solver/modules/solver.py index 730182d..5362647 100644 --- a/python/src/ffcraft_solver/modules/solver.py +++ b/python/src/ffcraft_solver/modules/solver.py @@ -58,7 +58,7 @@ Remaining CP: {self.remaining_cp}""" def make_macro(self) -> str: saved_lines = [''] - translated_actions = translator.translate(self.actions, "en") + translated_actions = translator.translate_list(self.actions, "en") count = 0 for action in translated_actions: @@ -106,6 +106,8 @@ class Solver: self.solutions = [] self.best_quality = None + self.least_steps = None + self.safe_50 = None self.solve() self.compute_all() @@ -115,20 +117,48 @@ class Solver: return xiv_craft_solver.solve_from_python(self) def compute_all(self) -> True: - self.compute_best_quality() + if self.solutions: + self.sort_quality() + self.compute_best_quality() + self.compute_least_steps() + self.compute_50percent_quality() + + def sort_quality(self) -> True: + self.solutions.sort(key=lambda x: x.quality) + return True def compute_best_quality(self) -> Result: - best_quality = 0 - output = 0 - if self.solutions: - for e in self.solutions: - if e.quality > best_quality: - best_quality = e.quality - output = e - self.best_quality = Result(output, 'Best quality') - - else: - loggers.add_log('Could not complete craft with current effective stats.') + self.best_quality = Result(self.solutions[-1], 'Best quality') return self.best_quality + def compute_50percent_quality(self) -> Result: + self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') + return self.safe_50 + + # def compute_best_quality(self) -> Result: + # best_quality = 0 + # output = 0 + # if self.solutions: + # for e in self.solutions: + # if e.quality > best_quality: + # best_quality = e.quality + # output = e + # self.best_quality = Result(output, 'Best quality') + # + # else: + # loggers.add_log('Could not complete craft with current effective stats.') + # return self.best_quality + + def compute_least_steps(self) -> Result: + least_steps = 100 + output = None + if self.solutions: + for e in self.solutions: + if e.steps < least_steps: + least_steps = e.steps + output = e + self.least_steps = Result(output, 'Least steps') + + return self.least_steps + diff --git a/python/src/ffcraft_solver/modules/translator.py b/python/src/ffcraft_solver/modules/translator.py index 9219c8a..28c8d02 100644 --- a/python/src/ffcraft_solver/modules/translator.py +++ b/python/src/ffcraft_solver/modules/translator.py @@ -1,5 +1,10 @@ +from ffcraft_solver.modules import log + +loggers = log.Loggers + supported_languages = { "en": { + 'basicSynth': 'Basic Synthesis', 'basicSynth2': 'Basic Synthesis', 'basicTouch': 'Basic Touch', 'mastersMend': "Master's mend", @@ -33,13 +38,20 @@ supported_languages = { } -def translate(actions, lang: str): +def translate_list(actions: list, lang: str): output = [] print(actions) if lang in supported_languages: dictionary = supported_languages[lang] for action in actions: - output.append(dictionary[action]) + try: + output.append(dictionary[action]) + except KeyError: + output.append(supported_languages["en"][action]) + loggers.log('Translation not found. Defaulting to English.\n' + ' Macros will probably be broken because of this.') + + else: print(f'Log: Language code "{lang}" not recognised.')