From 873dbf5486af9ae86fde7ae0eae5e1a1b8f9ba61 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:28:24 +0200 Subject: [PATCH 1/3] Simplify data file generation --- worlds/witness/data/generate_data_file.py | 55 ----------------------- 1 file changed, 55 deletions(-) delete mode 100644 worlds/witness/data/generate_data_file.py diff --git a/worlds/witness/data/generate_data_file.py b/worlds/witness/data/generate_data_file.py deleted file mode 100644 index 62dadcca515c..000000000000 --- a/worlds/witness/data/generate_data_file.py +++ /dev/null @@ -1,55 +0,0 @@ -from collections import defaultdict - -if __name__ == "__main__": - with open("APWitnessData.h", "w") as datafile: - datafile.write("""# pragma once - -# include -# include -# include - -""") - area_to_location_ids = defaultdict(list) - area_to_entity_ids = defaultdict(list) - - with open("WitnessLogic.txt") as w: - current_area = "" - - for line in w.readlines(): - line = line.strip() - if not line: - continue - - if line.startswith("=="): - current_area = line[2:-2] - continue - - if line.endswith(":"): - continue - - line_split = line.split(" - ") - location_id = line_split[0] - if location_id.isnumeric(): - area_to_location_ids[current_area].append(location_id) - - entity_id = line_split[1].split(" ", 1)[0] - - area_to_entity_ids[current_area].append(entity_id) - - datafile.write("inline std::map> areaNameToLocationIDs = {\n") - datafile.write( - "\n".join( - '\t{"' + area + '", { ' + ", ".join(location_ids) + " }}," - for area, location_ids in area_to_location_ids.items() - ) - ) - datafile.write("\n};\n\n") - - datafile.write("inline std::map> areaNameToEntityIDs = {\n") - datafile.write( - "\n".join( - '\t{"' + area + '", { ' + ", ".join(entity_ids) + " }}," - for area, entity_ids in area_to_entity_ids.items() - ) - ) - datafile.write("\n};\n") From 1eb0f4c3c1ec7796d9a79ff1ae3494bd421284d5 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:28:44 +0200 Subject: [PATCH 2/3] Simplify data file generation --- worlds/witness/generate_data_file.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 worlds/witness/generate_data_file.py diff --git a/worlds/witness/generate_data_file.py b/worlds/witness/generate_data_file.py new file mode 100644 index 000000000000..50a63a374619 --- /dev/null +++ b/worlds/witness/generate_data_file.py @@ -0,0 +1,45 @@ +from collections import defaultdict + +from data import static_logic as static_witness_logic + +if __name__ == "__main__": + with open("data/APWitnessData.h", "w") as datafile: + datafile.write("""# pragma once + +# include +# include +# include + +""") + + area_to_location_ids = defaultdict(list) + area_to_entity_ids = defaultdict(list) + + for entity_id, entity_object in static_witness_logic.ENTITIES_BY_HEX.items(): + location_id = entity_object["id"] + + area = entity_object["area"]["name"] + area_to_entity_ids[area].append(entity_id) + + if location_id is None: + continue + + area_to_location_ids[area].append(str(location_id)) + + datafile.write("inline std::map> areaNameToLocationIDs = {\n") + datafile.write( + "\n".join( + '\t{"' + area + '", { ' + ", ".join(location_ids) + " }}," + for area, location_ids in area_to_location_ids.items() + ) + ) + datafile.write("\n};\n\n") + + datafile.write("inline std::map> areaNameToEntityIDs = {\n") + datafile.write( + "\n".join( + '\t{"' + area + '", { ' + ", ".join(entity_ids) + " }}," + for area, entity_ids in area_to_entity_ids.items() + ) + ) + datafile.write("\n};\n\n") From 3baca534498cca68c1a2bf6458ffb304a89d7cf1 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sat, 22 Jun 2024 05:37:21 +0200 Subject: [PATCH 3/3] prevent div 0 --- worlds/witness/entity_hunt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/worlds/witness/entity_hunt.py b/worlds/witness/entity_hunt.py index 6d40ac54b443..8fed9e65a8e1 100644 --- a/worlds/witness/entity_hunt.py +++ b/worlds/witness/entity_hunt.py @@ -103,10 +103,12 @@ def _get_eligible_panels(self) -> Tuple[List[str], Dict[str, Set[str]]]: return all_eligible_panels, eligible_panels_by_area def _get_percentage_of_hunt_entities_by_area(self): + hunt_entities_picked_so_far_prevent_div_0 = max(len(self.HUNT_ENTITIES), 1) + contributing_percentage_per_area = dict() for area, eligible_entities in self.ELIGIBLE_ENTITIES_PER_AREA.items(): amount_of_already_chosen_entities = len(self.ELIGIBLE_ENTITIES_PER_AREA[area] & self.HUNT_ENTITIES) - current_percentage = amount_of_already_chosen_entities / len(self.HUNT_ENTITIES) + current_percentage = amount_of_already_chosen_entities / hunt_entities_picked_so_far_prevent_div_0 contributing_percentage_per_area[area] = current_percentage return contributing_percentage_per_area