| 
									
										
										
										
											2023-06-28 02:23:50 +02:00
										 |  |  | from functools import lru_cache | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  | from math import floor | 
					
						
							| 
									
										
										
										
											2023-07-20 02:10:48 +02:00
										 |  |  | from typing import List, Collection | 
					
						
							| 
									
										
										
										
											2023-06-25 02:00:56 +02:00
										 |  |  | from pkgutil import get_data | 
					
						
							| 
									
										
										
										
											2023-03-03 00:08:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-20 02:10:48 +02:00
										 |  |  | def build_weighted_int_list(inputs: Collection[float], total: int) -> List[int]: | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     """
 | 
					
						
							|  |  |  |     Converts a list of floats to a list of ints of a given length, using the Largest Remainder Method. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2022-05-09 07:20:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     # Scale the inputs to sum to the desired total. | 
					
						
							|  |  |  |     scale_factor: float = total / sum(inputs) | 
					
						
							|  |  |  |     scaled_input = [x * scale_factor for x in inputs] | 
					
						
							| 
									
										
										
										
											2022-05-09 07:20:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     # Generate whole number counts, always rounding down. | 
					
						
							| 
									
										
										
										
											2023-07-20 02:10:48 +02:00
										 |  |  |     rounded_output: List[int] = [floor(x) for x in scaled_input] | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     rounded_sum = sum(rounded_output) | 
					
						
							| 
									
										
										
										
											2022-05-09 07:20:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     # If the output's total is insufficient, increment the value that has the largest remainder until we meet our goal. | 
					
						
							| 
									
										
										
										
											2023-07-20 02:10:48 +02:00
										 |  |  |     remainders: List[float] = [real - rounded for real, rounded in zip(scaled_input, rounded_output)] | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     while rounded_sum < total: | 
					
						
							|  |  |  |         max_remainder = max(remainders) | 
					
						
							|  |  |  |         if max_remainder == 0: | 
					
						
							|  |  |  |             break | 
					
						
							| 
									
										
										
										
											2022-05-09 07:20:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |         # Consume the remainder and increment the total for the given target. | 
					
						
							|  |  |  |         max_remainder_index = remainders.index(max_remainder) | 
					
						
							|  |  |  |         remainders[max_remainder_index] = 0 | 
					
						
							|  |  |  |         rounded_output[max_remainder_index] += 1 | 
					
						
							|  |  |  |         rounded_sum += 1 | 
					
						
							| 
									
										
										
										
											2022-05-09 07:20:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-18 20:02:57 -07:00
										 |  |  |     return rounded_output | 
					
						
							| 
									
										
										
										
											2022-04-29 00:42:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def define_new_region(region_string): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Returns a region object by parsing a line in the logic file | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_string = region_string[:-1] | 
					
						
							|  |  |  |     line_split = region_string.split(" - ") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_name_full = line_split.pop(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_name_split = region_name_full.split(" (") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_name = region_name_split[0] | 
					
						
							|  |  |  |     region_name_simple = region_name_split[1][:-1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     options = set() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for _ in range(len(line_split) // 2): | 
					
						
							|  |  |  |         connected_region = line_split.pop(0) | 
					
						
							|  |  |  |         corresponding_lambda = line_split.pop(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         options.add( | 
					
						
							|  |  |  |             (connected_region, parse_lambda(corresponding_lambda)) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     region_obj = { | 
					
						
							|  |  |  |         "name": region_name, | 
					
						
							|  |  |  |         "shortName": region_name_simple, | 
					
						
							| 
									
										
										
										
											2023-06-21 00:45:26 +02:00
										 |  |  |         "panels": list() | 
					
						
							| 
									
										
										
										
											2022-04-29 00:42:11 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return region_obj, options | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def parse_lambda(lambda_string): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Turns a lambda String literal like this: a | b & c | 
					
						
							|  |  |  |     into a set of sets like this: {{a}, {b, c}} | 
					
						
							|  |  |  |     The lambda has to be in DNF. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     if lambda_string == "True": | 
					
						
							|  |  |  |         return frozenset([frozenset()]) | 
					
						
							|  |  |  |     split_ands = set(lambda_string.split(" | ")) | 
					
						
							|  |  |  |     lambda_set = frozenset({frozenset(a.split(" & ")) for a in split_ands}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return lambda_set | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-09 04:13:52 +02:00
										 |  |  | class lazy(object): | 
					
						
							|  |  |  |     def __init__(self, func, name=None): | 
					
						
							|  |  |  |         self.func = func | 
					
						
							|  |  |  |         self.name = name if name is not None else func.__name__ | 
					
						
							|  |  |  |         self.__doc__ = func.__doc__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __get__(self, instance, class_): | 
					
						
							|  |  |  |         if instance is None: | 
					
						
							|  |  |  |             res = self.func(class_) | 
					
						
							|  |  |  |             setattr(class_, self.name, res) | 
					
						
							|  |  |  |             return res | 
					
						
							|  |  |  |         res = self.func(instance) | 
					
						
							|  |  |  |         setattr(instance, self.name, res) | 
					
						
							|  |  |  |         return res | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 02:23:50 +02:00
										 |  |  | @lru_cache(maxsize=None) | 
					
						
							| 
									
										
										
										
											2022-06-16 03:04:45 +02:00
										 |  |  | def get_adjustment_file(adjustment_file): | 
					
						
							| 
									
										
										
										
											2023-06-25 02:00:56 +02:00
										 |  |  |     data = get_data(__name__, adjustment_file).decode('utf-8') | 
					
						
							|  |  |  |     return [line.strip() for line in data.split("\n")] | 
					
						
							| 
									
										
										
										
											2022-06-16 03:04:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_disable_unrandomized_list(): | 
					
						
							| 
									
										
										
										
											2022-07-17 12:56:22 +02:00
										 |  |  |     return get_adjustment_file("settings/Disable_Unrandomized.txt") | 
					
						
							| 
									
										
										
										
											2022-06-16 03:04:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_early_utm_list(): | 
					
						
							| 
									
										
										
										
											2022-07-17 12:56:22 +02:00
										 |  |  |     return get_adjustment_file("settings/Early_UTM.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_symbol_shuffle_list(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Symbol_Shuffle.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_door_panel_shuffle_list(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Door_Panel_Shuffle.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_doors_simple_list(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Doors_Simple.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_doors_complex_list(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Doors_Complex.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_doors_max_list(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Doors_Max.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_laser_shuffle(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Laser_Shuffle.txt") | 
					
						
							| 
									
										
										
										
											2022-10-09 04:13:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_audio_logs(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/Audio_Logs.txt") | 
					
						
							| 
									
										
										
										
											2023-02-01 21:18:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_all_individual(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_All.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_obelisks(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_Sides.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_easy(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_Easy.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_no_eclipse(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_NoEclipse.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_no_caves(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_NoCavesEPs.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_no_mountain(): | 
					
						
							|  |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_NoMountainEPs.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_ep_no_videos(): | 
					
						
							| 
									
										
										
										
											2023-06-25 02:00:56 +02:00
										 |  |  |     return get_adjustment_file("settings/EP_Shuffle/EP_Videos.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_sigma_normal_logic(): | 
					
						
							|  |  |  |     return get_adjustment_file("WitnessLogic.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_sigma_expert_logic(): | 
					
						
							|  |  |  |     return get_adjustment_file("WitnessLogicExpert.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_vanilla_logic(): | 
					
						
							|  |  |  |     return get_adjustment_file("WitnessLogicVanilla.txt") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_items(): | 
					
						
							|  |  |  |     return get_adjustment_file("WitnessItems.txt") |