Advertisement
imbued

SRM Heap Manip Script Prototype (untested with spectrum)

Dec 20th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 250.14 KB | None | 0 0
  1. from copy import copy
  2. import itertools
  3. import numpy as np
  4.  
  5. """
  6.  
  7. - This script does NOT handle spawners (except for rupee clusters)
  8. - This script does NOT handle scarecrow memory leak
  9.  
  10. - This script does not account for ISoT memory leak for solution options
  11.  
  12.  
  13. FOR DEKU PALACE, THIS DOES NOT ACCOUNT FOR SOME ROOMS BEING ABLE TO SPAWN SIGNS
  14. ALSO DOES NOT ACCOUNT FOR POTENTIALLY NEEDING TO BREAK A POT FOR THE SUPERSLIDE
  15.  
  16. """
  17.  
  18.  
  19.  
  20. """
  21.  
  22. Note: Node size is 0x10 = 16 on English and 0x30 = 48 on JP
  23.  
  24. """
  25.  
  26. version = 'English'
  27.  
  28. if version == 'English':
  29.     node_size = 0x10
  30. elif version == 'JP':
  31.     nodesize = 0x30
  32. else:
  33.     print('Error: Invalid Version (choose "English" or "JP" )')
  34.  
  35.  
  36.  
  37. class Actor:
  38.    
  39.     """
  40.    
  41.    name: name of the actor, some string
  42.    
  43.    Id: Actor id, string of 4 integers
  44.    
  45.    size: the size of an actor instance for this actor (number of bytes, in decimal)
  46.    
  47.    category: the actor category (category 5 is treated differently than others)
  48.              For now, giving everything not category 5 a category of 0
  49.  
  50.    overlay_type: determines where the AF loads in the heap
  51.    
  52.    unloadable: a boolean for whether or not it is possible to deallocate this actor without changing rooms
  53.    
  54.    address: the memory address of the actor in decimal (can convert to a hex string for output)
  55.             Note: The earliest address we handle is 0x40B150 = 4239696. All addresses must be multiples of 16
  56.            
  57.    room_number: the number of the room these actors are associated with; if the actor is a transition (i..e Plane
  58.                or Door), then set room_numer = False
  59.                
  60.    
  61.    priority: an index to differentiate copies of the same instance
  62.    
  63.    from_spawner: True or False (True if it is from a spawner, like rupees from a cluster; False otherwise)
  64.    
  65.    transition: False is the actor is not a Loading Plane or a Door. Otherwise, it is a list of the rooms that the transition actor connects, ordered from least to greatest room number
  66.    
  67.    clearable: True if it is possible to set a flag to make this actor not respawn upon reloading the room (though, unless it it Category 5, it will attempt to reload and then immediately deallocate), False otherwise
  68.    
  69.    cleared: True if the flag was set to clear this actor, False otherwise
  70.    
  71.    """
  72.    
  73.     def __init__(self, name, Id, size, category, overlay_type, unloadable, address, room_number, priority, from_spawner, transition, clearable, cleared):
  74.         self.name = name
  75.         self.Id = Id
  76.         self.size = size
  77.         self.category = category
  78.         self.overlay_type = overlay_type
  79.         self.unloadable = unloadable
  80.         self.address = address
  81.         self.room_number = room_number
  82.         self.priority = priority
  83.         self.from_spawner = from_spawner
  84.         self.transition = transition
  85.         self.clearable = clearable
  86.         self.cleared = cleared
  87.  
  88. class Room:
  89.    
  90.     """
  91.    
  92.    number: the room number (i.e. Room 0 has number 0)
  93.    
  94.    priority_queue: this will be the list of actor instances of the room, in order
  95.    
  96.    clock_exists: boolean for whether or not the clock is an actor in the queue
  97.    
  98.    clock_priority: if clock_exists == False, then clock_priority will be a number
  99.                    to determine where in the queue the clock should be loaded, for
  100.                    example, if clock_priority is 2, then it means that the clock
  101.                    should be the 3rd actor to appear in the queue (first index is 0)
  102.    
  103.    """
  104.    
  105.     def __init__(self, number, priority_queue, clock_exists, clock_priority):
  106.         self.number = number
  107.         self.priority_queue = priority_queue
  108.         self.clock_exists = clock_exists
  109.         self.clock_priority = clock_priority
  110.  
  111. class Node:
  112.    
  113.     """
  114.    address: which address in memory the node is at (as a base-10 integer for now)
  115.    
  116.    size: nodes should be 16 bytes (english), so input 16
  117.    
  118.    """
  119.    
  120.     def __init__(self, address, size):
  121.         self.address = address
  122.         self.size = size
  123.  
  124. class Overlay:
  125.    
  126.     def __init__(self, address, Id, size):
  127.         self.address = address
  128.         self.Id = Id
  129.         self.size = size
  130.  
  131.  
  132. """
  133.  
  134. We define the Clock actor ahead of time as it is not necessarily present in each room
  135.  
  136. """
  137.  
  138.  
  139. Clock = Actor(name='Clock', Id='015A', size=340, category=0, overlay_type='A', unloadable=False, address=0, room_number=False, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  140.  
  141.  
  142.  
  143. Room0_queue = [
  144.         Actor(name='Wooden Door', Id='0005', size=460, category=0, overlay_type='B', unloadable=False, address=0, room_number=False, priority=0, from_spawner=False, transition=[0,3], clearable=False, cleared=False),
  145.         Actor(name='Loading Plane', Id='0018', size=332, category=0, overlay_type='B', unloadable=False, address=0, room_number=False, priority=0, from_spawner=False, transition=[0,1], clearable=False, cleared=False),
  146.         Actor(name='Rupee Cluster', Id='00E8', size=360, category=0, overlay_type='A', unloadable=True, address=0, room_number=0, priority=0, from_spawner=False, transition=False, clearable=True, cleared=False),
  147.         Actor(name='Dripping Water Effect', Id='0170', size=3644, category=0, overlay_type='A', unloadable=False, address=0, room_number=0, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False),
  148.         Actor(name='Dripping Water Effect', Id='0170', size=3644, category=0, overlay_type='A', unloadable=False, address=0, room_number=0, priority=1, from_spawner=False, transition=False, clearable=False, cleared=False),
  149.         Actor(name='Torch Stand (Generic)', Id='0039', size=500, category=0, overlay_type='A', unloadable=False, address=0, room_number=0, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False),
  150.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=0, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False),
  151.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=0, priority=1, from_spawner=False, transition=False, clearable=False, cleared=False),
  152.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=0, priority=2, from_spawner=False, transition=False, clearable=False, cleared=False),
  153.         Actor(name='???0158', Id='0158', size=328, category=0, overlay_type='A', unloadable=False, address=0, room_number=0, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  154.         ]
  155.  
  156.  
  157. Room1_queue = [
  158.         Actor(name='Door Shutter', Id='001E', size=360, category=0, overlay_type='B', unloadable=False, address=0, room_number=False, priority=0, from_spawner=False, transition=[1,2], clearable=False, cleared=False),
  159.         Room0_queue[1],
  160.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=0, from_spawner=False, transition=False, clearable=True, cleared=False),
  161.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=1, from_spawner=False, transition=False, clearable=True, cleared=False),
  162.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=2, from_spawner=False, transition=False, clearable=True, cleared=False),
  163.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=3, from_spawner=False, transition=False, clearable=True, cleared=False),
  164.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=4, from_spawner=False, transition=False, clearable=True, cleared=False),
  165.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=5, from_spawner=False, transition=False, clearable=True, cleared=False),
  166.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=6, from_spawner=False, transition=False, clearable=True, cleared=False),
  167.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=7, from_spawner=False, transition=False, clearable=True, cleared=False),
  168.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=8, from_spawner=False, transition=False, clearable=True, cleared=False),
  169.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=9, from_spawner=False, transition=False, clearable=True, cleared=False),
  170.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=10, from_spawner=False, transition=False, clearable=True, cleared=False),
  171.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=11, from_spawner=False, transition=False, clearable=True, cleared=False),
  172.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=12, from_spawner=False, transition=False, clearable=True, cleared=False),
  173.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=13, from_spawner=False, transition=False, clearable=True, cleared=False),
  174.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=14, from_spawner=False, transition=False, clearable=True, cleared=False),
  175.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=15, from_spawner=False, transition=False, clearable=True, cleared=False),
  176.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=16, from_spawner=False, transition=False, clearable=True, cleared=False),
  177.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=17, from_spawner=False, transition=False, clearable=True, cleared=False),
  178.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=18, from_spawner=False, transition=False, clearable=True, cleared=False),
  179.         Actor(name='Bad Bat', Id='015B', size=476, category=5, overlay_type='A', unloadable=True, address=0, room_number=1, priority=19, from_spawner=False, transition=False, clearable=True, cleared=False),
  180.         Actor(name='Torch Stand (Generic)', Id='0039', size=500, category=0, overlay_type='A', unloadable=False, address=0, room_number=1, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False),
  181.         Actor(name='Torch Stand (Generic)', Id='0039', size=500, category=0, overlay_type='A', unloadable=False, address=0, room_number=1, priority=1, from_spawner=False, transition=False, clearable=False, cleared=False),
  182.         Actor(name='Torch Stand (Generic)', Id='0039', size=500, category=0, overlay_type='A', unloadable=False, address=0, room_number=1, priority=2, from_spawner=False, transition=False, clearable=False, cleared=False),
  183.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=1, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False),
  184.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=1, priority=1, from_spawner=False, transition=False, clearable=False, cleared=False),
  185.         Actor(name='Pot', Id='0082', size=412, category=0, overlay_type='A', unloadable=True, address=0, room_number=1, priority=2, from_spawner=False, transition=False, clearable=False, cleared=False),
  186.         Actor(name='Chest', Id='0006', size=548, category=0, overlay_type='A', unloadable=False, address=0, room_number=1, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  187.         ]
  188.  
  189. ###############################################################################
  190.  
  191. Room0 = Room(0, Room0_queue, False, 2)
  192. Room1 = Room(1, Room1_queue, False, 2)
  193.  
  194. """
  195.  
  196. Define the list of Rooms that we consider
  197.  
  198. """
  199.  
  200. Room_List = [Room0, Room1]
  201.  
  202.  
  203. """
  204.  
  205. In Overlay_dict we collect all of the Overlays of Type A, where the keys are
  206. the corresponding actor ids
  207.  
  208. """
  209.  
  210. # NOTE: This must be named "Overlay_dict" because it is hardcoded in some functions, like the Deallocate() function
  211. Overlay_dict = {
  212.         '015A' : Overlay(address=0, Id='015A', size=6000),
  213.         '00E8' : Overlay(address=0, Id='00E8', size=1984),
  214.         '0170' : Overlay(address=0, Id='0170', size=10688),
  215.         '0039' : Overlay(address=0, Id='0039', size=3552),
  216.         '0082' : Overlay(address=0, Id='0082', size=9040),
  217.         '0158' : Overlay(address=0, Id='0158', size=1104),
  218.         '015B' : Overlay(address=0, Id='015B', size=6048),
  219.         '0006' : Overlay(address=0, Id='0006', size=8640),
  220.         '0017' : Overlay(address=0, Id='0017', size=10432),
  221.         '017B' : Overlay(address=0, Id='017B', size=14320),
  222.         '007B' : Overlay(address=0, Id='007B', size=5104),
  223.         '00A2' : Overlay(address=0, Id='00A2', size=24448)
  224.             }
  225.  
  226. """
  227.  
  228. Here we collect a list of the actors that we allow ourselves to spawn
  229.  
  230. Notes:
  231.    'Zora Fins' means 2 fins
  232.    'Bugs' means a set of 3 bugs
  233.    
  234.  
  235. """
  236.  
  237. Allocation_List = [
  238.         'Nothing',
  239.         'Bomb',
  240.         'Smoke',
  241.         'Arrow',
  242.         'Hookshot',
  243.         'Charged Spin Attack',
  244.         'Chu',
  245.         'Zora Fins',
  246.         'Fish',
  247.         'Bugs'
  248.         ]
  249.  
  250. ######
  251.  
  252.  
  253. """
  254.  
  255. NOTE: We NEED to have 'Hookshot' and 'Charged Spin Attack' as the last two options
  256. in order to consider all cases
  257.  
  258. Don't have 'Bomb' before 'Smoke' to ensure that the Smoke always gets allocated first
  259.  
  260. maybe in the future you could jumble/randomize the order of things in this list at each step
  261. of the solver
  262.  
  263. """
  264. Hardcoded_Allocation_List = [
  265.         'Smoke',
  266.         'Smoke',
  267.         'Smoke',
  268.         'Chu',
  269.         'Chu',
  270.         'Chu',
  271.         'Arrow',
  272.         'Arrow',
  273.         'Arrow',
  274.         'Arrow',
  275.         'Arrow',
  276.         'Bomb',
  277.         'Bomb',
  278.         'Bomb',
  279.         'Zora Fins',
  280.         'Fish',
  281.         'Fish',
  282.         'Bugs',
  283.         'Bugs',
  284.         'Hookshot',
  285.         'Charged Spin Attack'
  286.         ]
  287.  
  288. """
  289.  
  290. Here we collect a list of the Ids grabbable actors that we can use for superslide SRM
  291. So far this includes:
  292.    
  293.    0082: Pot
  294.  
  295. """
  296.  
  297. Grabbable_Actors = ['0082']
  298.  
  299.  
  300. """
  301.  
  302. Here we collect a list of Actor Ids for spawners. So far this includes:
  303.    
  304.    00E8: Rupee Cluster
  305.  
  306. """
  307.  
  308. Spawner_Ids = ['00E8']
  309.  
  310.  
  311. """
  312.  
  313. We initialize the Heap as a list, putting a node with address 0x40B140 in the 0th entry
  314. and we place a dummy node at the end of the Heap so that there will always exist two
  315. consecutive nodes for us to define a condition for which free space in the Heap exists
  316.  
  317. Keep in mind that the 0x5FFFFF address in the dummy node will not reflect the actual
  318. address of the corresponding node in-game, but it also isn't relevant to heap manipulation
  319. since it is so far down
  320.  
  321. """
  322.  
  323.  
  324. Heap = [Node(0x40B140, node_size), Node(0x5FFFFF, node_size)]
  325.  
  326.  
  327.  
  328. def Overlay_In_Heap(Heap, overlay):
  329.    
  330.     """
  331.    
  332.    Overlay is the overlay that we want to check whether or not it is in the Heap
  333.    
  334.    This function will return True if Overlay is in the Heap and False otherwise
  335.    
  336.    """
  337.    
  338.     overlay_in_heap = False
  339.    
  340.     for entry in Heap:
  341.        
  342.         if type(entry) == Overlay and entry.Id == overlay.Id:
  343.            
  344.             overlay_in_heap = True
  345.        
  346.     return overlay_in_heap
  347.  
  348.  
  349. def Actor_Id_In_Heap(Heap, actor_id):
  350.    
  351.     """
  352.    
  353.    actor_id is the Id that we want to check for
  354.    
  355.    This function will return True if there exists an Actor in the Heap that
  356.    has actor_id as its Id and it will return False otherwise
  357.    
  358.    """
  359.    
  360.     actor_id_in_heap = False
  361.    
  362.     for entry in Heap:
  363.        
  364.         if type(entry) == Actor and entry.Id == actor_id:
  365.            
  366.             actor_id_in_heap = True
  367.    
  368.     return actor_id_in_heap
  369.  
  370.  
  371. def Find_Gaps(Heap):
  372.    
  373.     """
  374.    
  375.    This function will find all consecutive nodes and output a list of 4-tuples
  376.    where the first two entries correspond to the indices of each node in the list
  377.    and the last two entries correspond to the addresses of each node
  378.    
  379.    The list should be in order, from the start of the Heap to the end of the Heap
  380.    
  381.    """
  382.    
  383.     consecutive_node_count = 0
  384.    
  385.     node_1_address = 0
  386.     node_2_address = 0
  387.     node_1_index = 0
  388.     node_2_index = 0
  389.    
  390.     consecutive_node_list = []
  391.     for entry in Heap:
  392.         if type(entry) == Node and consecutive_node_count == 0:
  393.             node_1_address = entry.address
  394.             node_1_index = Heap.index(entry)
  395.             consecutive_node_count += 1
  396.         elif type(entry) == Node and consecutive_node_count == 1:
  397.             node_2_address = entry.address
  398.             node_2_index = Heap.index(entry)
  399.            
  400.             consecutive_node_list.append((node_1_index, node_2_index, node_1_address, node_2_address))
  401.            
  402.             consecutive_node_count += 1
  403.         elif type(entry) != Node:
  404.             consecutive_node_count = 0
  405.         elif type(entry) == Node and consecutive_node_count > 1:
  406.             consecutive_node_count += 1
  407.             print("ERROR: More than 2 consecutive nodes!! (Find_Gaps() Error Message)")
  408.        
  409.    
  410.     return consecutive_node_list
  411.    
  412.  
  413.  
  414.  
  415. def Allocate(Heap, actor, Overlay_Dict):
  416.    
  417.     """
  418.    
  419.    actor is the actor that we want to allocate into the Heap
  420.    
  421.    Overlay_Dict is a dictionary where the keys are the actor ids which point to the corresponding Overlays
  422.    
  423.    This function will account for placing nodes and overlays
  424.    
  425.    """
  426.    
  427.    
  428.     #Overlay = Overlay_Dict[actor.Id]
  429.    
  430.     #Overlay_Allocated = False
  431.    
  432.     #if Overlay_In_Heap(Heap, Overlay) == True:
  433.     #    Overlay_Allocated = True
  434.    
  435.     Actor_Allocated = False
  436.    
  437.     """
  438.    ##### Not yet defined, not sure if I will bother; not really necessary. Probably should for debugging
  439.    if Actor_In_Heap == True:
  440.        print('Error: This Actor is already allocated!! (Error message from Allocate() function)')
  441.    """
  442.    
  443.     gap_list = Find_Gaps(Heap)
  444.    
  445.     # Because we initialize the Heap with 2 nodes, there should always be at least one gap
  446.     if len(gap_list) < 1:
  447.         print('ERROR: len(gap_list) < 1 in Allocate() function')
  448.    
  449.    
  450.     # If the Overlay is type A and the Overlay is not already in the Heap, then we want to allocate the overlay first
  451.     if actor.overlay_type == 'A':
  452.        
  453.         ##### We only define Overlay for Type A overlays because Overlay_Dict only has Type A overlays
  454.         Overlay = Overlay_Dict[actor.Id]
  455.         Overlay_Allocated = False
  456.        
  457.         if Overlay_In_Heap(Heap, Overlay) == True:
  458.             Overlay_Allocated = True
  459.        
  460.        
  461.         if Overlay_In_Heap(Heap, Overlay) == False:
  462.        
  463.             for gap in gap_list:
  464.                
  465.                 if Overlay_Allocated == True:
  466.                     break ##### This ensures we don't add in the same Overlay multiple times
  467.                
  468.                 node_2_index = gap[1]
  469.                 node_1_address = gap[2]
  470.                 node_2_address = gap[3]
  471.                
  472.                 gap_size = node_2_address - node_1_address - node_size
  473.                
  474.                 ##### Case 1: the Overlay can fit, but there is NOT enough space for an extra node
  475.                 # Note that gap_size is always a multiple of 16
  476.                
  477.                 if Overlay.size <= gap_size and Overlay.size > gap_size - 2*node_size:
  478.                    
  479.                     Overlay.address = node_1_address + node_size
  480.                     Heap.insert(node_2_index, Overlay)
  481.                     Overlay_Allocated = True
  482.                    
  483.                
  484.                 ##### Case 2: the Overlay can fit and a new node can also fit
  485.                
  486.                 elif Overlay.size <= gap_size and Overlay.size <= gap_size - 2*node_size:
  487.                    
  488.                     Overlay.address = node_1_address + node_size
  489.                     Heap.insert(node_2_index, Overlay)
  490.                    
  491.                     ########### ADD IN THE NODE HERE
  492.                     if Overlay.size%16 > 0:
  493.                         Heap.insert(node_2_index + 1, Node(address=Overlay.address + Overlay.size + (16 - Overlay.size%16), size=node_size))
  494.                     elif Overlay.size%16 == 0:
  495.                         Heap.insert(node_2_index + 1, Node(address=Overlay.address + Overlay.size, size=node_size))
  496.                        
  497.                     Overlay_Allocated = True
  498.                
  499.     ############ Now the overlay (if applicable) has been allocated. Now we need to allocate the actor.
  500.    
  501.     ##### We need to update the gaps_list to account for the overlay being allocated in the Heap already
  502.     gap_list = Find_Gaps(Heap)
  503.    
  504.     for gap in gap_list:
  505.        
  506.         if Actor_Allocated == True:
  507.             break ##### This ensures we don't add in the same Actor multiple times
  508.        
  509.         node_2_index = gap[1]
  510.         node_1_address = gap[2]
  511.         node_2_address = gap[3]
  512.        
  513.         gap_size = node_2_address - node_1_address - node_size
  514.        
  515.         ##### Case 1: the Actor can fit, but there is NOT enough space for an extra node
  516.         # Note that gap_size is always a multiple of 16
  517.        
  518.         if actor.size <= gap_size and actor.size > gap_size - 2*node_size:
  519.            
  520.             actor.address = node_1_address + node_size
  521.             Heap.insert(node_2_index, actor)
  522.             Actor_Allocated = True
  523.            
  524.        
  525.         ##### Case 2: the Actor can fit and a new node can also fit
  526.        
  527.         elif actor.size <= gap_size and actor.size <= gap_size - 2*node_size:
  528.            
  529.             actor.address = node_1_address + node_size
  530.             Heap.insert(node_2_index, actor)
  531.            
  532.             ########### ADD IN THE NODE HERE
  533.             if actor.size%16 > 0:
  534.                 Heap.insert(node_2_index + 1, Node(address=actor.address + actor.size + (16 - actor.size%16), size=node_size))
  535.             elif actor.size%16 == 0:
  536.                 Heap.insert(node_2_index + 1, Node(address=actor.address + actor.size, size=node_size))
  537.                    
  538.             Actor_Allocated = True
  539.  
  540. def Borders_Node(Heap, entry):
  541.    
  542.     """
  543.    
  544.    This function takes an entry of the Heap as input and determines whether or
  545.    not this entry is adjacent to a node in the heap (the purpose of this is to
  546.    check if a node is bordering another node since actors and overlays should
  547.    be bordering two nodes under every circumstance)
  548.    
  549.    Returns True if the entry is bordering a node, returns False otherwise    
  550.    
  551.    """
  552.    
  553.     borders_node = False
  554.    
  555.     entry_index = Heap.index(entry)
  556.    
  557.     border_1_is_node = False
  558.     border_2_is_node = False
  559.    
  560.     if entry_index != 0:
  561.         border_1 = Heap[entry_index - 1]
  562.         if type(border_1) == Node:
  563.             border_1_is_node = True
  564.    
  565.     if entry_index != len(Heap) - 1:
  566.         border_2 = Heap[entry_index + 1]
  567.         if type(border_2) == Node:
  568.             border_2_is_node = True
  569.    
  570.     if border_1_is_node == True or border_2_is_node == True:
  571.         borders_node = True
  572.    
  573.     return borders_node
  574.        
  575.  
  576.  
  577. def Deallocate(Heap, actor, Overlay_dict):
  578.    
  579.    
  580.     """
  581.    
  582.    actor is the actor that we want to be deallocated from the Heap
  583.    
  584.    This function will account for removing nodes and overlays
  585.    
  586.    ##### Remove the actor AND node if applicable
  587.    ##### Check if any actors with the same Id are still in the Heap
  588.    ##### if not (and the actor has overlay Type A), then remove the overlay
  589.    
  590.    We only remove a node if it is part of a gap before deallocating the actor
  591.    That is, we only remove a node if it borders another node before the actor is deallocated
  592.    
  593.    """
  594.    
  595.     if type(actor) != Actor:
  596.         print("ERROR: Attempted to deallocate something other than an Actor (Deallocate() function error message)")
  597.    
  598.     # The index of where the actor is in the Heap before being deallocated; this will change after we remove the first node
  599.     actor_index = Heap.index(actor)
  600.    
  601.     ##### First check the node above the actor in the Heap
  602.     node_1 = Heap[actor_index - 1]
  603.     if type(node_1) != Node:
  604.         print("ERROR: One of the nodes is not actually a node! (Deallocate() function error message)")
  605.    
  606.     if Borders_Node(Heap, node_1) == True:
  607.         Heap.remove(node_1)
  608.        
  609.     ########## Now the first node has been removed and the indices of the Heap shift
  610.    
  611.     ##### Now we check the node below the actor in the Heap
  612.    
  613.     # The index of where the actor is in the Heap before being deallocated; this will change after we remove the first node
  614.     actor_index = Heap.index(actor)
  615.    
  616.     node_2 = Heap[actor_index + 1]
  617.     if type(node_2) != Node:
  618.         print("ERROR: One of the nodes is not actually a node! (Deallocate() function error message)")
  619.    
  620.     if Borders_Node(Heap, node_2) == True:
  621.         Heap.remove(node_2)
  622.    
  623.     ###########################################################################
  624.     ##### Now we have removed both of the nodes, if applicable and we must remove the actor itself
  625.    
  626.     Heap.remove(actor)
  627.    
  628.     """
  629.    
  630.    Now if the actor has a Type A overlay, then we must check if the Heap contains
  631.    any other actors that have the same Id as actor and if not, then we must also
  632.    remove its overlay from the Heap
  633.    
  634.    We must also account for removing the nodes around the overlay, if applicable
  635.    
  636.    """
  637.    
  638.     if actor.overlay_type == 'A' and Actor_Id_In_Heap(Heap, actor.Id) == False:
  639.        
  640.         ##### First check the node above the overlay
  641.         overlay_index = Heap.index(Overlay_dict[actor.Id])
  642.         node1 = Heap[overlay_index - 1]
  643.        
  644.         if type(node1) != Node:
  645.             print("ERROR: One of the nodes is not actually a node! (Deallocate() function error message)")
  646.        
  647.         if Borders_Node(Heap, node1) == True:
  648.             Heap.remove(node1)
  649.        
  650.        
  651.         ##### Now we check the node below the overlay
  652.         overlay_index = Heap.index(Overlay_dict[actor.Id])
  653.         node2 = Heap[overlay_index + 1]
  654.        
  655.         if type(node2) != Node:
  656.             print("ERROR: One of the nodes is not actually a node! (Deallocate() function error message)")
  657.        
  658.         if Borders_Node(Heap, node2) == True:
  659.             Heap.remove(node2)
  660.        
  661.         ###########################################################################
  662.         ##### Now we have removed both of the nodes, if applicable and we must remove the overlay itself
  663.        
  664.         Heap.remove(Overlay_dict[actor.Id])
  665.  
  666.  
  667.  
  668. def Load_Scene(Heap, room, Overlay_dict):
  669.    
  670.     if len(Heap) != 2:
  671.         print("ERROR: Attempted to use Load_Scene() with an inappropriate Heap")
  672.    
  673.     entry_count = 0
  674.     for entry in room.priority_queue:
  675.        
  676.         ##### If the clock is not in the room's set of actors, then we must allocate the clock at the appropriate time when we load the scene
  677.         if entry_count == room.clock_priority and room.clock_exists == False:
  678.            
  679.             ##### Allocate the 3-Day Clock actor
  680.             Allocate(Heap, Clock, Overlay_dict)
  681.             entry_count += 1
  682.        
  683.         ##### Allocate the entry in the room's priority queue
  684.         Allocate(Heap, entry, Overlay_dict)
  685.        
  686.         entry_count += 1
  687.    
  688.     ##### Now that all of the actors have been allocated, we want to add in all of the actors that the spawners spawn
  689.    
  690.     """
  691.    
  692.    NOTE: THIS DOES NOT HANDLE SPAWNERS OTHER THAN RUPEE CLUSTERS AT THE MOMENT
  693.    
  694.    In the future, it will need to be considered how the actors created by spawners
  695.    prioritize over each other... Spring MV is maybe the only place where this really matters
  696.    
  697.    """
  698.    
  699.     ##### Check for Rupee Cluster
  700.     if Overlay_In_Heap(Heap, Overlay_dict['00E8']) == True:
  701.        
  702.         for j in range(7):
  703.             rupee = Actor(name='Collectible (Rupee from Rupee Cluster)', Id='000E', size=424, category=0, overlay_type='B', unloadable=True, address=0, room_number=room.number, priority=j, from_spawner=True, transition=False, clearable=True, cleared=False)
  704.            
  705.             Allocate(Heap, rupee, Overlay_dict)
  706.  
  707.  
  708.  
  709. def Actor_From_Room_In_Heap(Heap, Room_Number):
  710.    
  711.     """
  712.    
  713.    This function takes the Heap and the number of the Room in question as input
  714.    It returns True if there exists an Actor in the Heap with the inputted Room_Number and False otherwise
  715.    
  716.    """
  717.    
  718.     actor_from_room_in_heap = False
  719.    
  720.     for entry in Heap:
  721.        
  722.         if type(entry) == Actor and entry.room_number is Room_Number:
  723.            
  724.             actor_from_room_in_heap = True
  725.    
  726.     return actor_from_room_in_heap
  727.  
  728. def Cleared_Actor_In_Heap(Heap):
  729.    
  730.     """
  731.    
  732.    This function returns True if there is a cleared actor in the Heap and False otherwise
  733.    
  734.    """
  735.    
  736.     cleared_actor_in_heap = False
  737.    
  738.     for entry in Heap:
  739.        
  740.         if type(entry) == Actor and entry.cleared == True:
  741.            
  742.             cleared_actor_in_heap = True
  743.        
  744.     return cleared_actor_in_heap
  745.  
  746.  
  747. def Shared_Transition_Count(Heap, Room_Number_1, Room_Number_2):
  748.    
  749.     """
  750.    
  751.    This function returns the number of transitions (Planes/Doors) that are shared between
  752.    the two rooms with room numbers Room_Number_1 and Room_Number_2
  753.    
  754.    """
  755.    
  756.     shared_transition_count = 0
  757.    
  758.     for entry in Heap:
  759.        
  760.         if type(entry) == Actor and entry.transition != False:
  761.            
  762.             if (entry.transition[0] == Room_Number_1 and entry.transition[1] == Room_Number_2) or (entry.transition[0] == Room_Number_2 and entry.transition[1] == Room_Number_1):
  763.                
  764.                 shared_transition_count += 1
  765.    
  766.     return shared_transition_count
  767.  
  768. def Is_Shared_Transition(actor, Room_Number_1, Room_Number_2):
  769.    
  770.     """
  771.    
  772.    If actor is a transition shared between Rooms with numbers Room_Number_1 and Room_Number_2,
  773.    then this function returns True. Otherwise it returns False
  774.    
  775.    """
  776.    
  777.     is_shared_transition = False
  778.    
  779.     if type(actor) == Actor and actor.transition != False:
  780.        
  781.         if (actor.transition[0] == Room_Number_1 and actor.transition[1] == Room_Number_2) or (actor.transition[0] == Room_Number_2 and actor.transition[1] == Room_Number_1):
  782.            
  783.             is_shared_transition = True
  784.    
  785.     return is_shared_transition
  786.        
  787.  
  788. def Transition_Is_In_Room(actor, Room_Number):
  789.    
  790.     transition_is_in_room = False
  791.    
  792.     if type(actor) == Actor and actor.transition != False:
  793.        
  794.         if actor.transition[0] == Room_Number or actor.transition[1] == Room_Number:
  795.            
  796.             transition_is_in_room = True
  797.    
  798.     return transition_is_in_room
  799.  
  800.  
  801. def Find_Clock_List(Heap):
  802.    
  803.     """
  804.    
  805.    This function finds all clock actor instances in the Heap and returns a list of them, in order
  806.    
  807.    """
  808.    
  809.     clock_list = []
  810.    
  811.     for entry in Heap:
  812.        
  813.         if type(entry) == Actor and entry.Id == '015A':
  814.            
  815.             clock_list.append(entry)
  816.    
  817.     return clock_list
  818.    
  819.  
  820. def Load_Room(Heap, room, transition, Overlay_dict):
  821.    
  822.    
  823.     """
  824.    
  825.    This function updates the Heap after you enter room through transition
  826.    For example, you might enter Room0 through Plane1 or Door3
  827.    
  828.    Before executing the script, should probably define Plane1, Plane2, ...
  829.    Door1, Door2, ..., etc. as the corresponding entries from the room queues.
  830.    This will make the code more readable when looking for solutions
  831.    
  832.    
  833.    * First we load all of the actors from the new room
  834.    * Next, we deallocate everything (well, not literally everything...) from the previous room
  835.    
  836.    
  837.    Things that this function needs to handle:
  838.        
  839.        - make sure that you check if each actor was cleared or not (if clearable == True, otherwise it isn't applicable)
  840.        and then check if it is Category 5 to determine if it loads and immediately deallocates or not
  841.        
  842.        - checking which clock to deallocate (i.e. deallocate the one that comes later
  843.        on in the Heap if there are more than one). Maybe define a Find_Clocks function
  844.        
  845.        - make sure transition never deallocates and never attempts to allocate
  846.        
  847.        - make sure that the other Transitions unload and then reload (if applicable) after all of
  848.        the stuff from the previous room deallocated
  849.        
  850.        - when deallocating stuff from the room that isn't the room you're entering, be sure
  851.        not to deallocate the clock. Also be careful of relevant Transitions as they don't have
  852.        actual room numbers (replaced with False)
  853.        
  854.        - allocate stuff from spawners after the fact (even after planes)
  855.        
  856.    
  857.    """
  858.    
  859.     if transition not in Heap:
  860.         print('2222222222')
  861.        
  862.     if transition not in room.priority_queue:
  863.         print('44444444')
  864.    
  865.     if (transition not in Heap) or (transition not in room.priority_queue):
  866.         print("ERROR: Attempted to use Load_Room() with an invalid transition")
  867.    
  868.     current_room_number = -1
  869.     new_room_number = room.number
  870.    
  871.     if transition.transition[0] == room.number:
  872.         current_room_number = transition.transition[1]
  873.     elif transition.transition[1] == room.number:
  874.         current_room_number = transition.transition[0]
  875.     else:
  876.         print("ERROR: Error with transition list (Load_Room() error message)")
  877.    
  878.     """
  879.    First we load all of the actors from the new room, EXCEPT for: the plane/door
  880.    we pass through AND any other shared transitions AND any actors with both
  881.    cleared == True and Category == 5 (these ones never attempt to load)
  882.    """
  883.    
  884.     for actor in room.priority_queue:
  885.        
  886.         ### If the actor is not a Transition OR if the actor is a transition but doesn't connect to the current room
  887.         if (actor.transition == False) or (actor.transition != False and actor.transition[0] != current_room_number and actor.transition[1] != current_room_number):
  888.            
  889.             ### If the actor is Category 5, then only attempt to load it if it has not been cleared
  890.             if actor.category != 5 or actor.cleared == False:
  891.                
  892.                 Allocate(Heap, actor, Overlay_dict)
  893.    
  894.     """
  895.    - Now all of the relevant actors from the new room have been allocated
  896.    - Now we need to immediately deallocate any actors with Clearable == True and Cleared == True
  897.    - We also need to deallocate any transitions which are shared between the current room and the new room
  898.      EXCEPT for transition itself (the transition that we passed through to get to the new room)
  899.    - We also need to deallocate the second clock actor in the Heap if it exists (do this after everything else for simplicity)
  900.      
  901.      Note that "current_room_number" is the room number of the room we were in before loading the new room
  902.    """
  903.  
  904.     while Actor_From_Room_In_Heap(Heap, current_room_number) == True or Cleared_Actor_In_Heap(Heap) == True or Shared_Transition_Count(Heap, current_room_number, new_room_number) > 1:
  905.        
  906.         for entry in Heap:
  907.            
  908.             if (type(entry) == Actor) and (entry.room_number is current_room_number or entry.cleared == True or Is_Shared_Transition(entry, current_room_number, new_room_number) == True or  (entry.transition != False and Transition_Is_In_Room(entry, new_room_number) == False )  ) and (entry != transition):
  909.                
  910.                 Deallocate(Heap, entry, Overlay_dict)
  911.    
  912.     ########## Now we will find all of the clocks and deallocate the second clock if it exists (and report error if more than two clocks)
  913.    
  914.     Clock_List = Find_Clock_List(Heap)
  915.    
  916.     if len(Clock_List) > 2:
  917.         print("ERROR: More than 2 Clocks in the Actor Heap (Load_Room() Error Message)")
  918.     elif len(Clock_List) < 1:
  919.         print("ERROR: No Clock Actor Instance in the Actor Heap (Load_Room() Error Message)")
  920.    
  921.     ##### If there are two clocks, then we deallocate the second clock that appears in the Heap
  922.     if len(Clock_List) > 1:
  923.        
  924.         Deallocate(Heap, Clock_List[1], Overlay_dict)
  925.    
  926.    
  927.     ##### Now we allocate any shared transitions EXCEPT for transition itself (the door/plane we entered to get into this room)
  928.    
  929.     for entry in room.priority_queue:
  930.        
  931.         # If entry is a shared transition and is NOT the transition that we passed through
  932.         if (type(entry) == Actor) and (entry.transition != False) and Is_Shared_Transition(entry, current_room_number, new_room_number) == True and (entry != transition):
  933.            
  934.             Allocate(Heap, entry, Overlay_dict)
  935.    
  936.     ###################################### Now we only have to account for allocating things from spawners
  937.    
  938.    
  939.     """
  940.    
  941.    NOTE: THIS DOES NOT HANDLE SPAWNERS OTHER THAN RUPEE CLUSTERS AT THE MOMENT
  942.    
  943.    In the future, it will need to be considered how the actors created by spawners
  944.    prioritize over each other... Spring MV is maybe the only place where this really matters
  945.    
  946.    """
  947.    
  948.     ##### Check for Rupee Cluster
  949.     if Overlay_In_Heap(Heap, Overlay_dict['00E8']) == True:
  950.        
  951.         for j in range(7):
  952.             rupee = Actor(name='Collectible (Rupee from Rupee Cluster)', Id='000E', size=424, category=0, overlay_type='B', unloadable=True, address=0, room_number=room.number, priority=j, from_spawner=True, transition=False, clearable=True, cleared=False)
  953.            
  954.             Allocate(Heap, rupee, Overlay_dict)
  955.        
  956.  
  957.  
  958.  
  959.  
  960. def Display_Heap(Heap):
  961.    
  962.     for entry in Heap:
  963.        
  964.         if type(entry) == Node:
  965.            
  966.             print(hex(entry.address) + '-----' + 'NODE-----------------')
  967.            
  968.         elif type(entry) == Overlay:
  969.            
  970.             print(hex(entry.address) + '     ' + entry.Id + '     ' + 'OVERLAY')
  971.        
  972.         elif type(entry) == Actor:
  973.            
  974.             print(hex(entry.address) + '     ' + entry.Id + '     ' + 'INSTANCE')
  975.        
  976.         else:
  977.             print("ERROR!!! Unexpected Entry Type in Heap!!!!!!!!!")
  978.  
  979.  
  980. ###############################################################################
  981. ###############################################################################
  982. ###############################################################################
  983. ###############################################################################
  984. ###############################################################################
  985. ###############################################################################
  986.  
  987. def Allocate_Fish(Heap, Room_Number, Overlay_dict):
  988.    
  989.     Fish = Actor(name='Fish', Id='0017', size=636, category=0, overlay_type='A', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  990.    
  991.     Allocate(Heap, Fish, Overlay_dict)
  992.  
  993.  
  994. def Allocate_Bugs(Heap, Room_Number, Overlay_dict):
  995.    
  996.     """
  997.    
  998.    This function allocates a set of 3 bugs to the Heap
  999.    
  1000.    """
  1001.    
  1002.     for i in range(3):
  1003.         Bug = Actor(name='Bug', Id='017B', size=884, category=0, overlay_type='A', unloadable=True, address=0, room_number=Room_Number, priority=i, from_spawner=False, transition=False, clearable=False, cleared=False)
  1004.    
  1005.         Allocate(Heap, Bug, Overlay_dict)
  1006.  
  1007.  
  1008. def Allocate_Bomb(Heap, Room_Number, Overlay_dict):
  1009.    
  1010.     Bomb = Actor(name='Bomb', Id='0009', size=516, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1011.    
  1012.     Allocate(Heap, Bomb, Overlay_dict)
  1013.  
  1014.  
  1015. def Allocate_Smoke(Heap, Room_Number, Overlay_dict):
  1016.    
  1017.     """
  1018.    
  1019.    This function allocates a bomb, then allocates smoke (this happens when the bomb explodes)
  1020.    and then deallocates the bomb (we bothered allocating the bomb to ensure that the smoke
  1021.    appears in the right spot in the Heap)
  1022.    
  1023.    Note that we should never allow ourselves to allocate smoke AFTER calling Allocate_Bomb()
  1024.    because in reality the first bomb would explode first (this isn't strictly true, but we should
  1025.    do it this way at least in the simple script)
  1026.    
  1027.    """
  1028.    
  1029.     Bomb = Actor(name='Bomb', Id='0009', size=516, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1030.    
  1031.     Allocate(Heap, Bomb, Overlay_dict)
  1032.    
  1033.     Smoke = Actor(name='Smoke', Id='00A2', size=11908, category=0, overlay_type='A', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1034.    
  1035.     Allocate(Heap, Smoke, Overlay_dict)
  1036.    
  1037.     Deallocate(Heap, Bomb, Overlay_dict)
  1038.  
  1039. def Allocate_Arrow(Heap, Room_Number, Overlay_dict):
  1040.    
  1041.     """
  1042.    
  1043.    This function allocates an arrow into the heap. Note that Deku Bubbles are
  1044.    the same actor as arrows (in that they're both 000F)
  1045.    
  1046.    """
  1047.    
  1048.     Arrow = Actor(name='Arrow', Id='000F', size=632, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1049.    
  1050.     Allocate(Heap, Arrow, Overlay_dict)
  1051.  
  1052.  
  1053. def Allocate_Hookshot(Heap, Room_Number, Overlay_dict):
  1054.    
  1055.     Hookshot = Actor(name='Hookshot', Id='003D', size=528, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1056.    
  1057.     Allocate(Heap, Hookshot, Overlay_dict)
  1058.  
  1059.  
  1060. def Allocate_Chu(Heap, Room_Number, Overlay_dict):
  1061.    
  1062.     Chu = Actor(name='Chu', Id='006A', size=480, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1063.    
  1064.     Allocate(Heap, Chu, Overlay_dict)
  1065.  
  1066.  
  1067. def Allocate_Zora_Fins(Heap, Room_Number, Overlay_dict):
  1068.    
  1069.     """
  1070.    
  1071.    This function allocates 2 Zora Fin actor instances
  1072.    
  1073.    """
  1074.    
  1075.     for i in range(2):
  1076.        
  1077.         Zora_Fin = Actor(name='Zora Fin', Id='0020', size=500, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1078.        
  1079.         Allocate(Heap, Zora_Fin, Overlay_dict)
  1080.  
  1081.  
  1082. def Allocate_Charged_Spin_Attack(Heap, Room_Number, Overlay_dict):
  1083.    
  1084.     """
  1085.    
  1086.    This functions allocates the Spin Attack & Sword Beam Effects and then the
  1087.    Spin Attack Charge Particles (This is the order they get allocated in when
  1088.    you charge a spin attack)
  1089.    
  1090.    """
  1091.    
  1092.     Spin_Attack_and_Sword_Beam_Effects = Actor(name='Spin Attack & Sword Beam Effects', Id='0035', size=452, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1093.    
  1094.     Allocate(Heap, Spin_Attack_and_Sword_Beam_Effects, Overlay_dict)
  1095.    
  1096.     Spin_Attack_Charge_Particles = Actor(name='Spin Attack Charge Particles', Id='007B', size=1367, category=0, overlay_type='A', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1097.    
  1098.     Allocate(Heap, Spin_Attack_Charge_Particles, Overlay_dict)
  1099.  
  1100.  
  1101.  
  1102. """
  1103.  
  1104. Before proceeding, we should define all of the transitions we plan on passing through
  1105.  
  1106. Since "Beneath the Graveyard" is relatively simple and I currently only want to consider
  1107. passing through a single plane, I will just define Plane_1 to be the plane shared between
  1108. Room0 and Room1
  1109.  
  1110. This loading plane happens the be the second element in Room0_queue, so I will define it based on that
  1111.  
  1112. """
  1113.  
  1114. Plane_1 = Room0_queue[1]
  1115.  
  1116.  
  1117. Transition_List= [Plane_1]
  1118.  
  1119.  
  1120. """
  1121.  
  1122.    Grabbable_dict is a dictionary of the grabbable actors (such as pots) that
  1123.    we want to attempt to use for superslide SRM where the keys are the grabbable
  1124.    actors and the values are lists with 3-bit strings where each bit means:
  1125.        
  1126.        100 : Possible to enter Plane with both Bomb and Smoke loaded
  1127.        010 : Possible to enter Plane with Smoke loaded, but no Bomb loaded
  1128.        001 : Possible to enter Plane with no Smoke loaded
  1129.    
  1130.    and Transitions, where the transitions are the ones you can superslide through
  1131.    
  1132.    
  1133.    
  1134. """
  1135.  
  1136. Grabbable_dict = {
  1137.         Room0_queue[6] : ['100', Plane_1],
  1138.         Room0_queue[7] : ['100', Plane_1],
  1139.         Room1_queue[25] : ['110', Plane_1],
  1140.         Room1_queue[26] : ['100', Plane_1],
  1141.         Room1_queue[27] : ['011', Plane_1]
  1142.         }
  1143.  
  1144.  
  1145. """
  1146.  
  1147. Below this we can consider a sequence of Room loads and then display the Heap
  1148.  
  1149. """
  1150.  
  1151.  
  1152. #Load_Scene(Heap, Room0)
  1153.  
  1154.  
  1155. #Load_Room(Heap, Room1, Plane_1, Overlay_dict)
  1156.  
  1157. #Load_Room(Heap, Room0, Plane_1, Overlay_dict)
  1158.  
  1159. #Load_Room(Heap, Room1, Plane_1, Overlay_dict)
  1160.  
  1161. #Load_Room(Heap, Room0, Plane_1, Overlay_dict)
  1162.  
  1163.  
  1164. #Display_Heap(Heap)
  1165.  
  1166. ###############################################################################
  1167. ###############################################################################
  1168. ###############################################################################
  1169. ###############################################################################
  1170. ###############################################################################
  1171. ###############################################################################
  1172.  
  1173.  
  1174. def Grabbable_In_Room(room, grabbable_actor_list):
  1175.    
  1176.     """
  1177.    
  1178.    This function checks the inputted room to see if it contains a grabbale actor
  1179.    that we can use for the superslide for SRM (in theory at least...)
  1180.    
  1181.    """
  1182.    
  1183.     grabbable_in_room = False
  1184.    
  1185.     for actor in room.priority_queue:
  1186.        
  1187.         if type(actor) == Actor and actor.Id in grabbable_actor_list:
  1188.            
  1189.             grabbable_in_room = True
  1190.    
  1191.     return grabbable_in_room
  1192.  
  1193.  
  1194. def Valid_Grabbable_In_Room(room, grabbable_actor_dict):
  1195.    
  1196.     """
  1197.    
  1198.    This function checks the inputted room to see if it contains a grabbale actor
  1199.    that we can use for the superslide for SRM
  1200.    
  1201.    """
  1202.    
  1203.     valid_grabbable_in_room = False
  1204.    
  1205.     for actor in room.priority_queue:
  1206.        
  1207.         if actor in grabbable_actor_dict.keys():
  1208.            
  1209.             valid_grabbable_in_room = True
  1210.    
  1211.     return valid_grabbable_in_room
  1212.  
  1213.  
  1214. def Chest_In_Room(room):
  1215.    
  1216.     """
  1217.    
  1218.    This function checks the inputted room to see if it contains a chest
  1219.    
  1220.    """
  1221.    
  1222.     chest_in_room = False
  1223.    
  1224.     for actor in room.priority_queue:
  1225.        
  1226.         if type(actor) == Actor and actor.Id == '0006':
  1227.            
  1228.             chest_in_room = True
  1229.    
  1230.     return chest_in_room
  1231.  
  1232.  
  1233. def Deku_Guard_In_Room(room):
  1234.    
  1235.     """
  1236.    
  1237.    This function checks the inputted room to see if it contains a Deku Guard
  1238.    
  1239.    """
  1240.    
  1241.     deku_guard_in_room = False
  1242.    
  1243.     for actor in room.priority_queue:
  1244.        
  1245.         if type(actor) == Actor and actor.Id == '017A':
  1246.            
  1247.             deku_guard_in_room = True
  1248.    
  1249.     return deku_guard_in_room
  1250.  
  1251.  
  1252. def Transition_List(room):
  1253.    
  1254.     """
  1255.    
  1256.    This function takes a room as input and returns a list of all of its transitions
  1257.    (i.e. doors/loading planes that lead to other rooms)
  1258.    
  1259.    """
  1260.    
  1261.     transition_list = []
  1262.    
  1263.     for actor in room.priority_queue:
  1264.        
  1265.         if actor.transition != False:
  1266.            
  1267.             transition_list.append(actor)
  1268.            
  1269.     return transition_list
  1270.    
  1271.  
  1272. def Shared_Transitions(room1, room2):
  1273.    
  1274.     """
  1275.    
  1276.    This function takes two Rooms as input and returns a list of their shared transitions
  1277.    (essentially returns the edges connecting these rooms if we view the rooms are nodes
  1278.    in a graph)
  1279.    
  1280.    """
  1281.    
  1282.     shared_transitions = []
  1283.    
  1284.     for transition in Transition_List(room1):
  1285.        
  1286.         if Is_Shared_Transition(transition, room1.number, room2.number) == True:
  1287.            
  1288.             shared_transitions.append(transition)
  1289.    
  1290.     return shared_transitions
  1291.  
  1292.  
  1293. def Shared_Transition_Exists(room1, room2):
  1294.    
  1295.     """
  1296.    
  1297.    This function takes two Rooms as input and returns True if they share a transition
  1298.    and False otherwise
  1299.    
  1300.    """
  1301.    
  1302.     shared_transition_exists = False
  1303.    
  1304.     for transition in Transition_List(room1):
  1305.        
  1306.         if Is_Shared_Transition(transition, room1.number, room2.number) == True:
  1307.            
  1308.             shared_transition_exists = True
  1309.    
  1310.     return shared_transition_exists
  1311.  
  1312.  
  1313. def Neighbors(room, Room_List):
  1314.    
  1315.     """
  1316.    
  1317.    This function takes a room as input along with a list of all potential rooms
  1318.    and returns a list of all rooms that share a transition with this room (excluding itself)
  1319.    
  1320.    """
  1321.    
  1322.     neighbors = []
  1323.    
  1324.     for ROOM in Room_List:
  1325.        
  1326.         if ROOM != room and Shared_Transition_Exists(room, ROOM) == True:
  1327.            
  1328.             neighbors.append(ROOM)
  1329.    
  1330.     return neighbors
  1331.    
  1332.  
  1333. def New_Room(room, transition, Room_List):
  1334.    
  1335.     """
  1336.    
  1337.    This function takes a room, a transition, and a list of all available rooms
  1338.    as input and returns the room that you would be in if you started in room
  1339.    and passed through transition
  1340.    
  1341.    """
  1342.    
  1343.     if transition not in Transition_List(room):
  1344.         print("ERROR: Invalid input into New_Room() function; transition is not in room")
  1345.        
  1346.     for ROOM in Room_List:
  1347.        
  1348.         if ROOM != room and (transition.transition[0] == ROOM.number or transition.transition[1] == ROOM.number) and ROOM.number != room.number:
  1349.            
  1350.             new_room = ROOM
  1351.    
  1352.     return new_room
  1353.  
  1354.    
  1355. def Current_Room(Room_Load_Permutation, Room_List):
  1356.    
  1357.     """
  1358.    
  1359.    Room_Load_Permutation is a list whose first element is the initial room that is started at
  1360.    
  1361.    All subsequent entries are transitions (Actor class objects with transition != False)
  1362.    
  1363.    
  1364.    Room_List is a list of all available Rooms
  1365.    
  1366.    
  1367.    This function returns what Room you would be in after entering every transition listed in
  1368.    the permutation, assuming that you start in the initial room
  1369.    
  1370.    """
  1371.    
  1372.     if type(Room_Load_Permutation[0]) != Room:
  1373.         print("ERROR: no initial room in permutation (Current_Room() function error message)")
  1374.    
  1375.     current_room = Room_Load_Permutation[0]
  1376.    
  1377.     if len(Room_Load_Permutation) > 1:
  1378.    
  1379.         for transition in Room_Load_Permutation[1:len(Room_Load_Permutation)]:
  1380.            
  1381.             current_room = New_Room(current_room, transition, Room_List)
  1382.    
  1383.     return current_room
  1384.  
  1385.  
  1386. def Room_Order_List(Room_Load_Permutation, Room_List):
  1387.    
  1388.     """
  1389.    
  1390.    Room_Load_Permutation is a list whose first element is the initial room that is started at
  1391.    
  1392.    All subsequent entries are transitions (Actor class objects with transition != False)
  1393.    
  1394.    
  1395.    Room_List is a list of all available Rooms
  1396.    
  1397.    
  1398.    This function returns a list of what Room you would be in at each step of
  1399.    entering transitions
  1400.    
  1401.    """
  1402.    
  1403.     if type(Room_Load_Permutation[0]) != Room:
  1404.         print("ERROR: no initial room in permutation (Get_Room_Load_List() function error message)")
  1405.    
  1406.     room_order_list = []
  1407.    
  1408.     for i in range(0, len(Room_Load_Permutation)):
  1409.        
  1410.         current_room = Current_Room(Room_Load_Permutation[0:i+1], Room_List)
  1411.        
  1412.         room_order_list.append(current_room)
  1413.    
  1414.     return room_order_list
  1415.  
  1416.  
  1417. def Generate_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count):
  1418.    
  1419.     """
  1420.    
  1421.    TODO: Debug this function... try calling: Generate_Room_Load_Permutations(Room0, Room_List, 1)
  1422.    
  1423.    
  1424.    This function seems to run for now, but it is untested for when we have multiple planes
  1425.    I will test this once I do Deku Palace input
  1426.    
  1427.    """
  1428.    
  1429.     """
  1430.    
  1431.    This function takes as input the initial room (Initial_Room) that the scene was loaded in
  1432.    the list of all Rooms we want to consider visiting (Room_List), and Max_Transition_Count
  1433.    which is the maximum number of times we want to allow ourselves to load a new room
  1434.    
  1435.    This function returns a list of all permutations of ways to enter new rooms after starting
  1436.    from the initial room (while limiting the number of room loads we do to be exactly Max_Transition_Count)
  1437.    where each permutation is a list in the form [Initial_Room, Transition1, Transition2, Transition3, ..., TransitionX]
  1438.    for X = Max_Transition_Count (so to get all permutations for X <= Max_Transition_Count, just
  1439.    use a for loop and call this function in each iteration of the foor loop and concatenate the lists)
  1440.    
  1441.    """
  1442.    
  1443.     if Max_Transition_Count == 0:
  1444.        
  1445.         new_permutation_list = [[Initial_Room]]
  1446.        
  1447.         return new_permutation_list
  1448.  
  1449.    
  1450.     else:
  1451.        
  1452.         new_permutation_list = []
  1453.         permutation_list = Generate_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count - 1)
  1454.        
  1455.         for permutation in permutation_list:
  1456.             for room in Neighbors(Current_Room(permutation, Room_List), Room_List):
  1457.                 for transition in Shared_Transitions(Current_Room(permutation, Room_List), room):
  1458.                     new_permutation = copy(permutation)
  1459.                     new_permutation.append(transition)
  1460.                     #permutation_list.append(new_permutation)
  1461.                     new_permutation_list.append(new_permutation)
  1462.                    
  1463.         return new_permutation_list
  1464.  
  1465.  
  1466. def Generate_All_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count):
  1467.    
  1468.     """
  1469.    
  1470.    This function returns all permutations of ways to load a room starting from the initial room
  1471.    where the number of room loads is <= Max_Transition_Count
  1472.    
  1473.    """
  1474.    
  1475.     permutation_list = []
  1476.    
  1477.     for N in range(Max_Transition_Count):
  1478.        
  1479.         new_permutation_list = Generate_Room_Load_Permutations(Initial_Room, Room_List, N)
  1480.         permutation_list = permutation_list + new_permutation_list
  1481.    
  1482.     return permutation_list
  1483.  
  1484.  
  1485. def Generate_Almost_All_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count):
  1486.    
  1487.     """
  1488.    
  1489.    This function returns all permutations of ways to load a room starting from the initial room
  1490.    where the number of room loads is <= Max_Transition_Count
  1491.    
  1492.    this will always output a list with length at least 2, which is why it is different
  1493.    from Generate_All_Room_Load_Permutations
  1494.    
  1495.    """
  1496.    
  1497.     permutation_list = []
  1498.    
  1499.     for N in range(1, Max_Transition_Count):
  1500.        
  1501.         new_permutation_list = Generate_Room_Load_Permutations(Initial_Room, Room_List, N)
  1502.         permutation_list = permutation_list + new_permutation_list
  1503.    
  1504.     return permutation_list
  1505.  
  1506.  
  1507. def Generate_All_Room_Order_Lists(Initial_Room, Room_List, Max_Transition_Count):
  1508.    
  1509.     """
  1510.    
  1511.    This function returns all permutations of ways to traverse through rooms, starting
  1512.    from the initial room where the number of room loads is <= Max_Transition_Count
  1513.    
  1514.    The distinction between this and Generate_All_Room_Load_Permutations is that
  1515.    this will, instead of listing transitions, list the Room you're currently in
  1516.    at each step
  1517.    
  1518.    """
  1519.    
  1520.     room_order_permutation_list = []
  1521.    
  1522.     room_load_permutation_list = Generate_All_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count)
  1523.    
  1524.    
  1525.     iteration_count = 0
  1526.     for room_load_permutation in room_load_permutation_list:
  1527.        
  1528.         print("Generate_All_Room_Order_Lists: %d out of %d" %(iteration_count, len(room_load_permutation_list)))
  1529.         iteration_count += 1
  1530.        
  1531.         room_order_list = Room_Order_List(room_load_permutation, Room_List)
  1532.        
  1533.         room_order_permutation_list.append(room_order_list)
  1534.    
  1535.     return room_order_permutation_list
  1536.        
  1537.  
  1538. def Generate_Allocation_Permutations(allocation_list):
  1539.    
  1540.     """
  1541.    
  1542.    Whatever, I'm just hardcoding a list of all of the actor names I want to allow
  1543.    and then using itertools to make a list of all of the permutations
  1544.    
  1545.    """
  1546.    
  1547.     """
  1548.    
  1549.    TODO: Finish this function, also generalize it in the future
  1550.    
  1551.    """
  1552.    
  1553.     """
  1554.    
  1555.    THIS FUNCTION IS SIMPLIFIED AT THE MOMENT AND COULD BE IMPROVED TO GENERATE
  1556.    EVEN MORE POSSIBLE PERMUTATIONS
  1557.    
  1558.    allocation_list is a list of strings of things to allocate
  1559.    
  1560.    for example:
  1561.        
  1562.        allocation_list = [
  1563.        'Nothing',
  1564.        'Bomb',
  1565.        'Smoke',
  1566.        'Arrow',
  1567.        'Hookshot',
  1568.        'Charged Spin Attack',
  1569.        'Chu',
  1570.        'Zora Fins',
  1571.        'Fish',
  1572.        'Bugs'
  1573.        ]
  1574.    
  1575.    """
  1576.    
  1577.     allocation_permutation_list = []
  1578.    
  1579.    
  1580.     for i in range(len(allocation_list) + 1):
  1581.        
  1582.         print("Generate_Allocation_Permutations: %d out of %d" %(i, len(allocation_list)))
  1583.        
  1584.        
  1585.         Permutations = list(itertools.permutations(allocation_list, i))
  1586.        
  1587.         allocation_permutation_list = allocation_permutation_list + Permutations
  1588.    
  1589.     return allocation_permutation_list
  1590.  
  1591.  
  1592. def Clear_Instances(actor_id, room):
  1593.    
  1594.     """
  1595.    
  1596.    This function takes an actor_id and room as input and sets actor.cleared = True
  1597.    for all actors with actor.id == actor_id in room
  1598.    
  1599.    Call this before loading the scene or anything if you want some specific
  1600.    actor cleared already. For example, I'd call Clear_Instances('015B', Room1)
  1601.    to clear all of the bad bats in Beneath the Graveyard
  1602.    
  1603.    """
  1604.    
  1605.     for actor in room.priority_queue:
  1606.        
  1607.         if actor.Id == actor_id and actor.clearable == True:
  1608.            
  1609.             actor.cleared = True
  1610.  
  1611.  
  1612. def Clear_Instance(actor, room):
  1613.    
  1614.     """
  1615.    
  1616.    This function takes a specific actor in a room as input and sets
  1617.    actor.cleared = True
  1618.    
  1619.    """
  1620.    
  1621.     if actor.clearable == True:
  1622.        
  1623.         actor.cleared = True
  1624.  
  1625.  
  1626. def Generate_Deallocation_Combinations(room):
  1627.    
  1628.     """
  1629.    ##### Note: we actually get combinations instead of permutations because
  1630.    the order in which we deallocate actors doesn't matter
  1631.    
  1632.    This function returns a list of combinations (stored as tuples of Actors)
  1633.    
  1634.    
  1635.    
  1636.    Some things this (or maybe some other) function needs to account for:
  1637.        
  1638.        if any rupee from a rupee cluster is deallocated in a deallocation step,
  1639.        then clear the rupee cluster actor instance (00E8) [note that there is
  1640.        at most one rupee cluster instance in every room in the game, so there is
  1641.        no need to check which cluster the rupees are associated with]
  1642.        
  1643.        if all bad bats are deallocated on the same deallocation step, then they
  1644.        must all be cleared... actually, stronger: if all Category 5 actors with
  1645.        the same Id in a given room are deallocated on the same deallocation step,
  1646.        then clear all instances... actually this isn't good enough (need to add
  1647.        this into the input I believe or just treat bad bats as a special case)
  1648.        
  1649.    
  1650.    """
  1651.    
  1652.     deallocation_list = []
  1653.    
  1654.     for actor in room.priority_queue:
  1655.        
  1656.         if actor.cleared == False and actor.unloadable == True:
  1657.            
  1658.             deallocation_list.append(actor)
  1659.    
  1660.     ##### Now we have a list of all actors in room that we have the option of deallocationg
  1661.    
  1662.     ##### Now want want to generate a list of permutations
  1663.     ########## ACTUALLY, order doesn't matter for deallocation, so all combinations suffices
  1664.    
  1665.     combination_list = []
  1666.    
  1667.     for i in range(len(deallocation_list) + 1):
  1668.        
  1669.         Combinations = list(itertools.combinations(deallocation_list, i))
  1670.        
  1671.         combination_list = combination_list + Combinations
  1672.        
  1673.     return combination_list
  1674.  
  1675.  
  1676.  
  1677.  
  1678. def Build_Room_Deallocation_Combination_Graph(room_order_list):
  1679.    
  1680.    
  1681.     """
  1682.    
  1683.    This function takes a room_order_list as input (that is, a list in the form
  1684.    [initial_room, Room1, Room2, Room3, ..., RoomN] which describes the order we
  1685.    visit rooms in (note that Roomi could be equal to Roomj even for i =/= j)) and
  1686.    returns a dictionary where the keys are vertices whose values are lists of the
  1687.    other vertices that they are connected to. Each vertex represents a deallocation
  1688.    combination for the room that it corresponds to.
  1689.    
  1690.    If the edges are directed, then this can be viewed as a multitree with some
  1691.    dummy root vertex and then each generation corresponds to a Room.
  1692.    
  1693.    """
  1694.    
  1695.     room_count = 0
  1696.    
  1697.     #### Encode a dummy root node to make finding paths easier
  1698.     graph = {('root', room_count - 1) : []}
  1699.    
  1700.    
  1701.     iteration_count = 0
  1702.     ### for all rooms except for the last one
  1703.     for room in room_order_list[0:len(room_order_list)-1]:
  1704.        
  1705.         print("Build_Room_Deallocation_Combination_Graph: %d out of %d" %(iteration_count, len(room_order_list) - 1))
  1706.         iteration_count += 1
  1707.        
  1708.         combination_list = Generate_Deallocation_Combinations(room)
  1709.        
  1710.         for combination in combination_list:
  1711.            
  1712.             for key in graph.keys():
  1713.                
  1714.                 ### If the key is from the previous generation, then append every combination to its list
  1715.                 if key[1] == room_count - 1:
  1716.                    
  1717.                     graph[key].append(combination)
  1718.            
  1719.             graph[(combination, room_count)] = []
  1720.        
  1721.         room_count += 1
  1722.            
  1723.     return graph
  1724.  
  1725.  
  1726. def Find_Leaves(graph):
  1727.    
  1728.     """
  1729.    
  1730.    This function takes a graph (really a dictionary) created by Build_Room_Deallocation_Combination_Graph()
  1731.    and returns a list of all of its leaves
  1732.    
  1733.    """
  1734.    
  1735.     leaf_list = []
  1736.  
  1737.     for key in graph:
  1738.         # only leaves will point to empty lists
  1739.         if graph[key] == []:
  1740.             leaf_list.append(key)
  1741.    
  1742.     return leaf_list
  1743.  
  1744.  
  1745. def Find_All_Paths(graph, start, end, path=[]):
  1746.        
  1747.         """
  1748.        
  1749.        This function takes a graph (really a dictionary) and start and end vertices
  1750.        as input and returns a list of all paths from start to end
  1751.        
  1752.        TODO: maybe don't rely on hardcoding what the root's key is and instead write
  1753.        a function to find it (though hardcode is prob faster if you don't make mistakes)
  1754.        
  1755.        I will use this to find all paths from ('root', -1) [note that I am hardcoding
  1756.        this instead of just finding a root without any parent] to a given lead, and
  1757.        I will do this for all leafs (which I can get by doing Find_Leaves(graph))
  1758.        
  1759.        """
  1760.        
  1761.        
  1762.         path = path + [start]
  1763.         if start == end:
  1764.             return [path]
  1765.         if not (start in graph):
  1766.             return []
  1767.         paths = []
  1768.         for vertex in graph[start]:
  1769.             if vertex not in path:
  1770.                 newpaths = Find_All_Paths(graph, vertex, end, path)
  1771.                 for newpath in newpaths:
  1772.                     paths.append(newpath)
  1773.         return paths
  1774.  
  1775.  
  1776. def Find_All_Deallocation_Combination_Paths(graph):
  1777.    
  1778.     """
  1779.    
  1780.    TODO: Note that I hardcode what the key of the root vertex is: ('root', -1)
  1781.    
  1782.    This returns a list of all (n-1)-permutations of deallocation combinations
  1783.    for a given room_order_list (where we assume there are n rooms we travel to
  1784.    including the initial room). This gives us the thing we called D1
  1785.    
  1786.    """
  1787.    
  1788.     all_deallocation_combination_paths = []
  1789.    
  1790.     leaf_list = Find_Leaves(graph)
  1791.    
  1792.     iteration_count = 0
  1793.     for leaf in leaf_list:
  1794.        
  1795.         print("Find_All_Deallocation_Combination_Paths: %d out of %d" %(iteration_count, len(leaf_list)))
  1796.         iteration_count += 1
  1797.        
  1798.         # I hardcode the root key to be ('root', -1)
  1799.         path_to_leaf = Find_All_Paths(graph, ('root', -1), leaf)
  1800.        
  1801.         all_deallocation_combination_paths = all_deallocation_combination_paths + path_to_leaf
  1802.        
  1803.        
  1804.     ##### Since every key is a tuple in the form (combination, number), get rid of number part
  1805.     for path in all_deallocation_combination_paths:
  1806.         for vertex in path:
  1807.             path[path.index(vertex)] = vertex[0]
  1808.    
  1809.     return all_deallocation_combination_paths
  1810.  
  1811.  
  1812.  
  1813.  
  1814. def Generate_Action_Permutations(room_order_list, allocation_list):
  1815.    
  1816.     """
  1817.    
  1818.    THIS IS THE FUNCTION THAT FINALLY GIVES US ALL OF THE PERMUTATIONS OF THINGS
  1819.    TO DO FOR A GIVEN room_order_list and the allocation_list.
  1820.    
  1821.    
  1822.    
  1823.    WE WILL RUN THIS FUNCTION ON EVERY PERMUTATION OF ROOM ORDER LISTS USING
  1824.    Generate_All_Room_Order_Lists(Initial_Room, Room_List, Max_Transition_Count)
  1825.    
  1826.    
  1827.    ONCE WE DO THAT WE WILL HAVE EVERY SINGLE PERMUTATION THAT WE WANT TO TEST
  1828.    
  1829.    """
  1830.    
  1831.     allocation_permutations = Generate_Allocation_Permutations(allocation_list)
  1832.    
  1833.     ##### Now we want all (n-1)-permutations of allocation permutations
  1834.     A1 = list(itertools.permutations(allocation_permutations, len(room_order_list) - 1))
  1835.    
  1836.     #### deallocation combination graph
  1837.     graph = Build_Room_Deallocation_Combination_Graph(room_order_list)
  1838.    
  1839.     D1 = Find_All_Deallocation_Combination_Paths(graph)
  1840.    
  1841.     ###########################################################################
  1842.    
  1843.     # create output list o
  1844.     o = []
  1845.     for i in range(len(A1)):
  1846.        
  1847.         print("Generate_Action_Permutations: %d out of %d" %(i, len(A1)))
  1848.        
  1849.         for j in range(len(D1)):
  1850.             for b in range(2**(len(room_order_list) - 1)):
  1851.                 # create new empty list p
  1852.                 p = []
  1853.                 for k in range(len(room_order_list) - 1):
  1854.                     p.append(room_order_list[k])
  1855.                    
  1856.                     if bin(b)[2:].zfill(len(room_order_list)-1) == 1:
  1857.                        
  1858.                         # add each element of A1[i][k] to p
  1859.                         for element in A1[i][k]:
  1860.                             p.append(element)
  1861.                         # add each element of D1[j][k] to p
  1862.                         for element in D1[j][k]:
  1863.                             p.append(element)
  1864.                            
  1865.                     elif bin(b)[2:].zfill(len(room_order_list)-1) == 0:
  1866.                        
  1867.                         # add each element of D1[j][k] to p
  1868.                         for element in D1[j][k]:
  1869.                             p.append(element)
  1870.                         # add each element of A1[i][k] to p
  1871.                         for element in A1[i][k]:
  1872.                             p.append(element)
  1873.                
  1874.                 # Add the last room to p
  1875.                 p.append(room_order_list[len(room_order_list)-1])
  1876.                 # append p to o
  1877.                 o = o + p
  1878.    
  1879.     return o
  1880.  
  1881.  
  1882.  
  1883. def Generate_Heap_Permutations(Initial_Room, Room_List, Max_Transition_Count, allocation_list):
  1884.    
  1885.     """
  1886.    
  1887.    This function takes the initial room, the Room List, the Maximum Number of Transitions
  1888.    that we want to allow, and the allocation list as input and returns every permutation
  1889.    for heap manip setups to try (possibilities currently mostly limited by allocation_list)
  1890.    
  1891.    WE WILL USE THIS FUNCTION IN THE HEAP MANIP SOLVER
  1892.    
  1893.    """
  1894.    
  1895.     heap_permutations = []
  1896.    
  1897.     All_Room_Order_Lists = Generate_All_Room_Order_Lists(Initial_Room, Room_List, Max_Transition_Count)
  1898.    
  1899.     iteration_count= 0
  1900.     for room_order_list in All_Room_Order_Lists:
  1901.        
  1902.         print("Iteration %d out of %d" %(iteration_count, len(All_Room_Order_Lists)))
  1903.        
  1904.         action_permutations = Generate_Action_Permutations(room_order_list, allocation_list)
  1905.        
  1906.         heap_permutations = heap_permutations + action_permutations
  1907.        
  1908.         iteration_count += 1
  1909.    
  1910.    
  1911.     print("HEAP PERMUTATION GENERATION COMPLETE")
  1912.    
  1913.     return heap_permutations
  1914.        
  1915.    
  1916.  
  1917. ###############################################################################
  1918. ###############################################################################
  1919. ###############################################################################
  1920. ###############################################################################
  1921. ###############################################################################
  1922. ###############################################################################
  1923. ###############################################################################
  1924.    
  1925. def Actor_Is_In_Heap(Heap, actor):
  1926.    
  1927.     """
  1928.    
  1929.    actor is the Actor that we want to check for
  1930.    
  1931.    This function will return True if this Actor is in the Heap and False otherwise
  1932.    
  1933.    """
  1934.    
  1935.     actor_is_in_heap = False
  1936.    
  1937.     for entry in Heap:
  1938.        
  1939.         if type(entry) == Actor and entry == actor:
  1940.            
  1941.             actor_is_in_heap = True
  1942.    
  1943.     return actor_is_in_heap
  1944.  
  1945. def Actor_Is_In_Room(room, actor):
  1946.        
  1947.     """
  1948.    
  1949.    actor is the Actor that we want to check for
  1950.    
  1951.    This function will return True if this Actor is in the room and False otherwise
  1952.    
  1953.    """
  1954.    
  1955.     actor_is_in_room = False
  1956.    
  1957.     for entry in room.priority_queue:
  1958.        
  1959.         if type(entry) == Actor and entry == actor:
  1960.            
  1961.             actor_is_in_room = True
  1962.            
  1963.     return actor_is_in_room
  1964.  
  1965.  
  1966.  
  1967. def Bomb_And_Smoke_Superslide(Heap, Room_Number, Overlay_dict):
  1968.    
  1969.     """
  1970.    
  1971.    This function allocates a bomb, then allocates smoke (this happens when the bomb explodes)
  1972.    
  1973.    """
  1974.    
  1975.     Bomb = Actor(name='Bomb', Id='0009', size=516, category=0, overlay_type='B', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1976.    
  1977.     Allocate(Heap, Bomb, Overlay_dict)
  1978.    
  1979.     Smoke = Actor(name='Smoke', Id='00A2', size=11908, category=0, overlay_type='A', unloadable=True, address=0, room_number=Room_Number, priority=0, from_spawner=False, transition=False, clearable=False, cleared=False)
  1980.    
  1981.     Allocate(Heap, Smoke, Overlay_dict)
  1982.    
  1983.  
  1984.  
  1985.  
  1986.  
  1987. def Copy_Room_List(Room_List):
  1988.    
  1989.     """
  1990.    
  1991.    This function takes a list of all Rooms, Room_List, as input
  1992.    and returns a list of copies of all of the Rooms in Room_List
  1993.    
  1994.    """
  1995.    
  1996.     ##### First we want a list of all shared entries between the Room priority queues
  1997.    
  1998.     shared_actor_list = []
  1999.    
  2000.     for room1 in Room_List:
  2001.         for room2 in Room_List:
  2002.            
  2003.             if room2 != room1:
  2004.                
  2005.                 for actor1 in room1.priority_queue:
  2006.                     for actor2 in room2.priority_queue:
  2007.                         if (actor1 == actor2) and (actor1 not in shared_actor_list):
  2008.                            
  2009.                             shared_actor_list.append(actor1)
  2010.                            
  2011.     ##### Now make a list of copies of each entry of the above list
  2012.    
  2013.     shared_actor_copy_list = []
  2014.     for actor in shared_actor_list:
  2015.         shared_actor_copy_list.append(copy(actor))
  2016.    
  2017.     Room_List_Copy = []
  2018.    
  2019.     for room in Room_List:
  2020.        
  2021.         priority_queue_copy = []
  2022.        
  2023.         for actor in room.priority_queue:
  2024.            
  2025.             if actor not in shared_actor_list:
  2026.                
  2027.                 priority_queue_copy.append(copy(actor))
  2028.                
  2029.             elif actor in shared_actor_list:
  2030.                 append_count = 0
  2031.                 for actor2 in shared_actor_copy_list:
  2032.                    
  2033.                     # If all attributes of the actor and the copy are the same, then assume they are copies of each other
  2034.                     if actor2.name == actor.name and actor2.Id == actor.Id and actor2.size == actor.size and actor2.category == actor.category and actor2.overlay_type == actor.overlay_type and actor2.unloadable == actor.unloadable and actor2.address == actor.address and actor2.room_number == actor.room_number and actor2.priority == actor.priority and actor2.from_spawner == actor.from_spawner and actor2.transition == actor.transition and actor2.clearable == actor.clearable and actor2.cleared == actor.cleared:
  2035.                         # append the copy  
  2036.                         priority_queue_copy.append(actor2)
  2037.                         append_count += 1
  2038.                        
  2039.                         if append_count > 1:
  2040.                             print("ERROR: There were two or more copies of the same Actor in shared_actor_copy_list (Copy_Room_List() error message)")
  2041.        
  2042.        
  2043.         room_copy = Room(number=room.number, priority_queue=priority_queue_copy, clock_exists=room.clock_exists, clock_priority=room.clock_priority)
  2044.        
  2045.         Room_List_Copy.append(room_copy)
  2046.    
  2047.     return Room_List_Copy
  2048.  
  2049.  
  2050.  
  2051.  
  2052. def Main_Actor_Attributes_Match(actor1, actor2):
  2053.    
  2054.     """
  2055.    
  2056.    This function returns True is the two Actors taken as input have the same
  2057.    values for all of their main attributes and False otherwise
  2058.    
  2059.    the main attributes do not include things like "address" and such that can
  2060.    change as the state updates
  2061.    
  2062.    """
  2063.    
  2064.     main_actor_attributes_match = False
  2065.    
  2066.     if actor1.name == actor2.name and actor1.Id == actor2.Id and actor1.size == actor2.size and actor1.category == actor2.category and actor1.overlay_type == actor2.overlay_type and actor1.unloadable == actor2.unloadable and actor1.room_number is actor2.room_number and actor1.priority is actor2.priority and actor1.from_spawner == actor2.from_spawner and actor1.transition == actor2.transition and actor1.clearable == actor2.clearable:
  2067.         main_actor_attributes_match = True
  2068.    
  2069.     return main_actor_attributes_match
  2070.  
  2071.  
  2072. def Main_Overlay_Attributes_Match(overlay1, overlay2):
  2073.    
  2074.     main_overlay_attributes_match = False
  2075.    
  2076.     if overlay1.Id == overlay2.Id and overlay1.size == overlay2.size:
  2077.         main_overlay_attributes_match = True
  2078.    
  2079.     return main_overlay_attributes_match
  2080.    
  2081.  
  2082. def Copy_Overlay_Dict(Overlay_Dict):
  2083.    
  2084.     overlay_dict_copy = {}
  2085.    
  2086.     for key in Overlay_Dict:
  2087.         overlay_dict_copy[key] = copy(Overlay_Dict[key])
  2088.    
  2089.     return overlay_dict_copy
  2090.        
  2091.  
  2092. def Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy):
  2093.    
  2094.     """
  2095.    
  2096.    This function takes the Heap as input and returns a copy of the Heap where
  2097.    every actor copy in the Heap copy is the same class instance as each corresponding
  2098.    actor in the room list copy priority queues (same for Overlay_Dict_Copy)
  2099.    
  2100.    """
  2101.    
  2102.     Heap_Copy = []
  2103.    
  2104.     for entry in Heap:
  2105.        
  2106.         entry_allocated = False
  2107.         not_allocated_count = 0
  2108.         while entry_allocated is False:
  2109.            
  2110.             if not_allocated_count > 4:
  2111.                 print("UHHHHHHHHHHHHHHHHHHHHHHHH (Copy_Heap() Error Message)")
  2112.        
  2113.             if type(entry) == Node:
  2114.                
  2115.                 Heap_Copy.append(copy(entry))
  2116.                 entry_allocated = True
  2117.                
  2118.             elif type(entry) == Overlay:
  2119.                
  2120.                 for key in Overlay_Dict_Copy:
  2121.                     if Main_Overlay_Attributes_Match(Overlay_Dict_Copy[key], entry) == True:
  2122.                         Heap_Copy.append(Overlay_Dict_Copy[key])
  2123.                         entry_allocated = True
  2124.            
  2125.             elif type(entry) == Actor:
  2126.                
  2127.                 allocated_count = 0
  2128.                 for room in Room_List_Copy:
  2129.                    
  2130.                     if entry_allocated == True:
  2131.                         break
  2132.                    
  2133.                     for actor in room.priority_queue:
  2134.                        
  2135.                         if allocated_count > 1:
  2136.                             print("ERROR: tried to allocate multiple copies (Copy_Heap() Error Message)")
  2137.                        
  2138.                         if Main_Actor_Attributes_Match(entry, actor) == True:
  2139.                             Heap_Copy.append(actor)
  2140.                             allocated_count += 1
  2141.                             entry_allocated = True
  2142.                             break
  2143.                
  2144.                 # If it isn't in any of the priority queues, then it must be something you spawned
  2145.                 if entry_allocated == False:
  2146.                     Heap_Copy.append(copy(entry))
  2147.                     entry_allocated = True
  2148.                
  2149.             else:
  2150.                 print("ERROR: entry in Heap is not an Actor, Node, or Overlay (Copy_Heap() error message)")
  2151.            
  2152.             not_allocated_count += 1
  2153.     return Heap_Copy
  2154.  
  2155.  
  2156. def Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy):
  2157.    
  2158.     """
  2159.    
  2160.    This function takes the Grabbable_Dict as input and returns a copy of the it where
  2161.    each transition in it is a the same Actor class instance copy as the ones used in
  2162.    the priority queues of the Rooms in Room_List_Copy
  2163.    
  2164.    """
  2165.    
  2166.     grabbable_dict_copy = {}
  2167.    
  2168.     for pot in Grabbable_Dict:
  2169.        
  2170.         pot_in_dict = False
  2171.  
  2172.            
  2173.         for room in Room_List_Copy:
  2174.             if pot_in_dict == True:
  2175.                 break
  2176.             for actor in room.priority_queue:
  2177.                 if Main_Actor_Attributes_Match(pot, actor) == True:
  2178.                    
  2179.                     key = actor
  2180.                    
  2181.                     for room1 in Room_List_Copy:
  2182.                         if pot_in_dict == True:
  2183.                             break
  2184.                         for actor1 in room1.priority_queue:
  2185.                            
  2186.                             # Finding the transition
  2187.                             if Main_Actor_Attributes_Match(Grabbable_Dict[pot][1], actor1):
  2188.                                
  2189.                                 grabbable_dict_copy[key] = [Grabbable_Dict[pot][0], actor1]
  2190.                                 pot_in_dict = True
  2191.                                    
  2192.     return grabbable_dict_copy
  2193.    
  2194.  
  2195. def Find_Actor_Copy(actor, Room_List_Copy):
  2196.    
  2197.     """
  2198.    
  2199.    This function takes an Actor as input (actor) and a copy of the list of rooms
  2200.    (Room_List_Copy) and returns the copy of the inputted actor that is found in
  2201.    the priority queue of a Room in Room_List_Copy
  2202.    
  2203.    """
  2204.    
  2205.     actor_copy = None
  2206.    
  2207.     copy_found = False
  2208.     for room in Room_List_Copy:
  2209.         if copy_found == True:
  2210.             break
  2211.         for actor1 in room.priority_queue:
  2212.             if Main_Actor_Attributes_Match(actor1, actor):
  2213.                 actor_copy = actor1
  2214.                 copy_found = True
  2215.                 break
  2216.    
  2217.     return actor_copy
  2218.            
  2219.  
  2220. """
  2221.  
  2222. TODO: Make the solver take the initial heap layout as input so that it is easy
  2223. to test successive heap manip setups in the future
  2224.  
  2225. DO NOT FORGET TO CLEAR ALL OF THE BAD BATS IF YOU THINK THAT THAT IS SOMETHING
  2226. THAT YOU WANT TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2227.  
  2228. ALSO IGNORE THAT FUNCTION BELOW, COMPLETELY REWRITE FROM SCRATCH BUT MAYBE READ
  2229. IT FIRST TO SEE IF IT REMINDS YOU OF ANY IDEAS YOU HAD
  2230.  
  2231. """
  2232.  
  2233.  
  2234. def Randomized_Solver(Initial_Room, Room_List, Max_Transition_Count, allocation_list, Grabbable_Dict, Overlay_Dict, filename, Offset_List, Initial_Heap):
  2235.    
  2236.     """
  2237.    
  2238.    This function does not currently account for the possibility that you might need to break
  2239.    another pot in order to superslide off of a given pot. While this might not be strictly
  2240.    true for the pot we currently use in deku palace, it would be good at add more information
  2241.    to Grabbable_Dict to account for this
  2242.    
  2243.    """
  2244.    
  2245.     """
  2246.    
  2247.    Okay, the Initial_Heap argument will not work as I initially intended because of things
  2248.    like rupee clusters being cleared, etc. So if I want to test a Heap from an initial Heap
  2249.    distribution, then I will have to hardcode it to perform the necessary steps to get to it each time
  2250.    
  2251.    """
  2252.    
  2253.     """
  2254.    
  2255.    filename is the complete name (i.e. including the path) that we want to write to
  2256.    
  2257.    This function will randomly choose solutions to test (it may have repeats)
  2258.    
  2259.    Offset_List is a list of offsets that we want to check for. The grabbable object (e.g. a pot)
  2260.    will be first when calculating the offset. So if doing chest SRM, we want
  2261.    pot - chest = 0x160 or pot - chest = 0x1F0, so we want Offset_List = [0x160, 0x1F0]
  2262.    We make this Offset_List by default
  2263.    
  2264.    Grabbable_dict is a dictionary of the grabbable actors (such as pots) that
  2265.    we want to attempt to use for superslide SRM where the keys are the grabbable
  2266.    actors and the values are 3-bit strings where each bit means:
  2267.        
  2268.        100 : Possible to enter Plane with both Bomb and Smoke loaded
  2269.        010 : Possible to enter Plane with Smoke loaded, but no Bomb loaded
  2270.        001 : Possible to enter Plane with no Smoke loaded
  2271.    
  2272.    """
  2273.    
  2274.     angle_solution_count = 0
  2275.     position_solution_count = 0
  2276.     permutation_count = 0
  2277.    
  2278.     ### Keep doing this forever (infinite loop so we keep trying new permutations)
  2279.     while True:
  2280.        
  2281.         all_room_load_lists = Generate_Almost_All_Room_Load_Permutations(Initial_Room, Room_List, Max_Transition_Count)
  2282.        
  2283.         for room_load_list in all_room_load_lists:
  2284.            
  2285.             if permutation_count%500 == 0:
  2286.                 print("%d Permutations Tested     %d Angle Solutions     %d Position Solutions" %(permutation_count, angle_solution_count, position_solution_count))
  2287.             permutation_count += 1
  2288.            
  2289.             Heap = copy(Initial_Heap)
  2290.            
  2291.             ##### Initialize the actor addresses and other attributes each time
  2292.        
  2293.             for room in Room_List:
  2294.                
  2295.                 for actor in room.priority_queue:
  2296.                    
  2297.                     actor.address = 0
  2298.                     actor.cleared = False
  2299.                    
  2300.                     ##### Clear all bad bats (optional, but I want to do this for beneath the graveyard)
  2301.                     Clear_Instances('015B', room)
  2302.             ###################################################################
  2303.            
  2304.             #####
  2305.             ##### Perform seuqence of steps here if you want to initialize your heap to something
  2306.             #####
  2307.            
  2308.             # We will use this to collect things we do in the permutation to help output the solution
  2309.             action_list = []
  2310.            
  2311.             room_count = 0
  2312.             # NOTE: the first "transition" is actually not a transition; it is the initial room
  2313.             for transition in room_load_list[0:len(room_load_list)-1]:
  2314.                
  2315.                 room = Current_Room(room_load_list[0:room_count + 1], Room_List)
  2316.                
  2317.                 # If this is the Initial_Room AND the Heap is empty, then we want to load the scene
  2318.                 if (room_count is 0) and (len(Heap) == 2):
  2319.                    
  2320.                     if room != Initial_Room:
  2321.                         print("ERROR: first entry in room_load_list is not Initial_Room (Randomnized_Solver() Error Message)")
  2322.                    
  2323.                     Load_Scene(Heap, Initial_Room, Overlay_Dict)
  2324.                     action_list.append("Load Scene: Room %d" %(Initial_Room.number))
  2325.                    
  2326.                 else:
  2327.                    
  2328.                     Load_Room(Heap, room, transition, Overlay_Dict)
  2329.                    
  2330.                     action_list.append("Load Room: Room %d" %(room.number) + " with " + transition.name + " %d" %(transition.priority))
  2331.                    
  2332.                     """
  2333.                    
  2334.                    Now randomly (with some chosen distribution) choose things to allocate
  2335.                    and/or things to deallocate (in your current room). Make it so that
  2336.                    you can only choose a specific action once. For example, if allocation_list
  2337.                    has ['bomb', 'bomb, 'bomb', 'fish'] in it, then make it so you can only use
  2338.                    fish once, but you can use bomb 3 times
  2339.                    
  2340.                    Somehow try to encode that hookshot/charged spin are mutually exclusive
  2341.                    and that if either of them exist then they must be the last action
  2342.                    
  2343.                    Allow yourself to deallocate things before allocating things even
  2344.                    though it might be impossible or slow in some cases
  2345.                    
  2346.                    """
  2347.                    
  2348.                     # Do a coinflip to decide between allocating or deallocating first
  2349.                     decision_coin_flip = np.random.uniform(0,1)
  2350.                    
  2351.                     # With probability 1/2, we allocate first and deallocate second
  2352.                     # if we allocate first, don't allow 'Charged Spin Attack'
  2353.                     if decision_coin_flip > .5:
  2354.                        
  2355.                         explosive_count = 0
  2356.                         droppable_count = 0
  2357.                        
  2358.                         ##### ALLOCATION
  2359.                         for action in allocation_list:
  2360.                            
  2361.                             # whether or not we add an action is based off of this
  2362.                             coin_flip = decision_coin_flip = np.random.uniform(0,1)
  2363.                            
  2364.                             if action == 'Smoke' and coin_flip > .5:
  2365.                                
  2366.                                 Allocate_Smoke(Heap, room.number, Overlay_Dict)
  2367.                                 action_list.append("Allocate: Smoke")
  2368.                                
  2369.                             elif action == 'Chu' and coin_flip > .5 and explosive_count < 3:
  2370.                                
  2371.                                 Allocate_Chu(Heap, room.number, Overlay_Dict)
  2372.                                 action_list.append("Allocate: Chu")
  2373.                                 explosive_count += 1
  2374.                                
  2375.                             elif action == 'Arrow' and coin_flip > .5:
  2376.                                
  2377.                                 Allocate_Arrow(Heap, room.number, Overlay_Dict)
  2378.                                 action_list.append("Allocate: Arrow")
  2379.                            
  2380.                             elif action == 'Bomb' and coin_flip > .5 and explosive_count < 3:
  2381.                                
  2382.                                 Allocate_Bomb(Heap, room.number, Overlay_Dict)
  2383.                                 action_list.append("Allocate: Bomb")
  2384.                                 explosive_count += 1
  2385.                                
  2386.                             elif action == 'Zora Fins' and coin_flip > .5:
  2387.                                
  2388.                                 Allocate_Zora_Fins(Heap, room.number, Overlay_Dict)
  2389.                                 action_list.append("Allocate: Zora Fins")
  2390.                            
  2391.                             elif action == 'Fish' and coin_flip > .5 and droppable_count < 2:
  2392.                                
  2393.                                 Allocate_Fish(Heap, room.number, Overlay_Dict)
  2394.                                 action_list.append("Allocate: Fish")
  2395.                                 droppable_count += 1
  2396.                                
  2397.                             elif action == 'Bugs' and coin_flip > .5 and droppable_count < 2:
  2398.                                
  2399.                                 Allocate_Bugs(Heap, room.number, Overlay_Dict)
  2400.                                 action_list.append("Allocate: Bugs")
  2401.                                 droppable_count += 1
  2402.                            
  2403.                             elif action == 'Hookshot' and coin_flip > .5:
  2404.                                
  2405.                                 Allocate_Hookshot(Heap, room.number, Overlay_Dict)
  2406.                                 action_list.append("Allocate: Hookshot")
  2407.                        
  2408.                             ### We don't include 'Charged Spin Attack' in this
  2409.                        
  2410.                         ##### DEALLOCATION
  2411.                         for actor in room.priority_queue:
  2412.                            
  2413.                             # whether or not we deallocate an actor is based off of this
  2414.                             coin_flip = decision_coin_flip = np.random.uniform(0,1)
  2415.                            
  2416.                             if actor.unloadable == True and Actor_Is_In_Heap(Heap, actor) == True and coin_flip > .5:
  2417.                                
  2418.                                
  2419.                                 if actor.Id == '00E8' or actor.name == 'Collectible (Rupee from Rupee Cluster)':
  2420.                                    
  2421.                                     Deallocate(Heap, actor, Overlay_Dict)
  2422.                                     # There is at most one rupee cluster per room, so this is fine to clear it
  2423.                                     Clear_Instances('00E8', room)
  2424.                                     action_list.append("Deallocate: " + actor.name + " (Priority %d)" %(actor.priority))
  2425.                                    
  2426.                                 else:
  2427.                                    
  2428.                                     Deallocate(Heap, actor, Overlay_Dict)
  2429.                                     action_list.append("Deallocate: " + actor.name + " (Priority %d)" %(actor.priority))
  2430.  
  2431.                    
  2432.                     # With probability 1/2, we deallocate first and allocate second
  2433.                     elif decision_coin_flip <= .5:
  2434.                    
  2435.                         explosive_count = 0
  2436.                         droppable_count = 0
  2437.                         hookshot_exists = False
  2438.                        
  2439.                         ##### DEALLOCATION
  2440.                         for actor in room.priority_queue:
  2441.                            
  2442.                             # whether or not we deallocate an actor is based off of this
  2443.                             coin_flip = decision_coin_flip = np.random.uniform(0,1)
  2444.                            
  2445.                             if actor.unloadable == True and Actor_Is_In_Heap(Heap, actor) == True and coin_flip > .5:
  2446.                                
  2447.                                
  2448.                                 if actor.Id == '00E8' or actor.name == 'Collectible (Rupee from Rupee Cluster)':
  2449.                                    
  2450.                                     Deallocate(Heap, actor, Overlay_Dict)
  2451.                                     # There is at most one rupee cluster per room, so this is fine to clear it
  2452.                                     Clear_Instances('00E8', room)
  2453.                                     action_list.append("Deallocate: " + actor.name + " (Priority %d)" %(actor.priority))
  2454.                                    
  2455.                                 else:
  2456.                                    
  2457.                                     Deallocate(Heap, actor, Overlay_Dict)
  2458.                                     action_list.append("Deallocate: " + actor.name + " (Priority %d)" %(actor.priority))
  2459.                        
  2460.  
  2461.                         ##### ALLOCATION
  2462.                         for action in allocation_list:
  2463.                            
  2464.                             # whether or not we add an action is based off of this
  2465.                             coin_flip = decision_coin_flip = np.random.uniform(0,1)
  2466.                            
  2467.                             if action == 'Smoke' and coin_flip > .5:
  2468.                                
  2469.                                 Allocate_Smoke(Heap, room.number, Overlay_Dict)
  2470.                                 action_list.append("Allocate: Smoke")
  2471.                                
  2472.                             elif action == 'Chu' and coin_flip > .5 and explosive_count < 3:
  2473.                                
  2474.                                 Allocate_Chu(Heap, room.number, Overlay_Dict)
  2475.                                 action_list.append("Allocate: Chu")
  2476.                                 explosive_count += 1
  2477.                                
  2478.                             elif action == 'Arrow' and coin_flip > .5:
  2479.                                
  2480.                                 Allocate_Arrow(Heap, room.number, Overlay_Dict)
  2481.                                 action_list.append("Allocate: Arrow")
  2482.                            
  2483.                             elif action == 'Bomb' and coin_flip > .5 and explosive_count < 3:
  2484.                                
  2485.                                 Allocate_Bomb(Heap, room.number, Overlay_Dict)
  2486.                                 action_list.append("Allocate: Bomb")
  2487.                                 explosive_count += 1
  2488.                                
  2489.                             elif action == 'Zora Fins' and coin_flip > .5:
  2490.                                
  2491.                                 Allocate_Zora_Fins(Heap, room.number, Overlay_Dict)
  2492.                                 action_list.append("Allocate: Zora Fins")
  2493.                            
  2494.                             elif action == 'Fish' and coin_flip > .5 and droppable_count < 2:
  2495.                                
  2496.                                 Allocate_Fish(Heap, room.number, Overlay_Dict)
  2497.                                 action_list.append("Allocate: Fish")
  2498.                                 droppable_count += 1
  2499.                                
  2500.                             elif action == 'Bugs' and coin_flip > .5 and droppable_count < 2:
  2501.                                
  2502.                                 Allocate_Bugs(Heap, room.number, Overlay_Dict)
  2503.                                 action_list.append("Allocate: Bugs")
  2504.                                 droppable_count += 1
  2505.                            
  2506.                             elif action == 'Hookshot' and coin_flip > .5:
  2507.                                
  2508.                                 Allocate_Hookshot(Heap, room.number, Overlay_Dict)
  2509.                                 action_list.append("Allocate: Hookshot")
  2510.                                 hookshot_exists = True
  2511.                                
  2512.                             elif action == 'Charged Spin Attack' and hookshot_exists is False:
  2513.                                
  2514.                                 Allocate_Charged_Spin_Attack(Heap, room.number, Overlay_Dict)
  2515.                                 action_list.append("Allocate: Charged Spin Attack")
  2516.                        
  2517.                    
  2518.                 room_count += 1
  2519.            
  2520.             ##### Now we load the last room in room_order_list
  2521.             current_room = Current_Room(room_load_list, Room_List)
  2522.             most_recent_transition = room_load_list[-1]
  2523.             Load_Room(Heap, current_room, most_recent_transition, Overlay_Dict)
  2524.            
  2525.             action_list.append("Load Room: Room %d" %(current_room.number) + " with " + most_recent_transition.name + " %d" %(most_recent_transition.priority))
  2526.            
  2527.            
  2528.             """
  2529.            
  2530.            Now that we have iterated through all of the rooms, we want to check to see
  2531.            if we are in a room with a valid grabbale object. If so, then store the addresses
  2532.            of all of them and make a copy of the current Heap state. From here, we want to try
  2533.            every possibility in the sense that we want to check every valid grabbable object
  2534.            in every room that we can get to and also check every superslide case that is possible
  2535.            (based on the binary number associated with each valid grabbable object) and then
  2536.            check if either the Angle or Position (input this into the function via Offset_List)
  2537.            line up with the chest or deku guard
  2538.            
  2539.            There aren't too many possibilities from here in practice, so we might as well check them all
  2540.            
  2541.            Also encode that if we superslide into a room with a chest/deku guard, then we must
  2542.            exit the room and then reenter it (or enter another room with a chest/deku guard; we will
  2543.            test every case) and after doing that we will check the chest/deku guard addresses
  2544.            and see if any of them line up with any of the pots that we stored the addresses of
  2545.            
  2546.            We'll eventually want to write stuff to a text file, so maybe set file as an input argument
  2547.            or just hardcode it, not sure
  2548.            
  2549.            """
  2550.            
  2551.             """
  2552.            
  2553.            WE MAKE THE ASSUMPTION THAT YOU LAND IN A ROOM THAT EITHER IS A ROOM
  2554.            WITH A CHEST/DEKU GUARD OR A ROOM THAT NEIGHBORS A ROOM WITH A CHEST/DEKU GUARD
  2555.            BECAUSE I CANNOT THINK OF ANY PLACES WHERE THIS WOULDN'T HAPPEN WHEN TESTING
  2556.            SUPERSLIDE SRM (ZORA FIN WOULD BE DIFFERENT, BUT THIS SOLVER DOESN'T TEST IT)
  2557.            
  2558.            Also, before supersliding, we assume that you're in a room that either has
  2559.            a valid grabbable object, or is next to a room with a valid grabbable object.
  2560.            Of course, this means fewer possibilities are being tested in a place like
  2561.            oceanside, but there are already so many possibilities to test to begin with that
  2562.            this probably isn't a big deal for now. This also affects deku palace, but maybe
  2563.            I'll change this by the time I work on deku palace (because if you end in Room2,
  2564.            then nothing happens)
  2565.            
  2566.            """
  2567.            
  2568.             """
  2569.            
  2570.            Nevermind some of those other comments, here is what I'm really assuming.
  2571.            
  2572.            I will be assuming that if you end in a room without a valid grabbable
  2573.            actor, then it will search all neighbors of that room for valid grabbable
  2574.            actors and if none of those have valid grabbable objects then it will
  2575.            search all of those neighbors and choose the first one it finds (this
  2576.            will allow for ending in Room 2 in Deku Palace). Otherwise it does nothing
  2577.            (though this will never happen for the cases I plan on checking for now)
  2578.            
  2579.            (*Coded)If you are in a room with a valid grabbable actor and no chest/deku guard,
  2580.            then we will check the addresses of all valid grabbable actors in this room
  2581.            and superslide into the chest room, exit and reenter it. Then we will check the address of the
  2582.            chest and see if it lines up with any of the pot addresses from the previous
  2583.            room.
  2584.            
  2585.            (*Coded)If you are in a room with a valid grabbable actor AND a chest/deku guard, then
  2586.            you will record the valid grabbable actor addresses then superslide to exit the
  2587.            room and then check all neighbors of the room you enter for having a chest/deku guard
  2588.            and test all of them
  2589.            
  2590.            
  2591.            
  2592.            """
  2593.            
  2594.             valid_grabbable_actor_room_list = []
  2595.            
  2596.             for room in Room_List:
  2597.                 if Valid_Grabbable_In_Room(room, Grabbable_Dict) is True:
  2598.                     valid_grabbable_actor_room_list.append(room)
  2599.            
  2600.             # This gives a list of all ways we can exit our current room
  2601.             #transition_list_possibilities = Generate_Room_Load_Permutations(current_room, Room_List, 1)
  2602.            
  2603.             ##### Case 1: there is a valid grabbable actor in the current room, but no chest/deku guard (the guard thing doesn't matter because this never happens in palace anyway)
  2604.             if (current_room in valid_grabbable_actor_room_list) and (Chest_In_Room(current_room) is False) and (Deku_Guard_In_Room(current_room) is False):
  2605.                
  2606.                 valid_pot_list = []
  2607.                 pot_address_list = []
  2608.                
  2609.                 for pot in Grabbable_Dict:
  2610.                    
  2611.                     if Actor_Is_In_Room(current_room, pot) is True:
  2612.                         valid_pot_list.append(pot)
  2613.                         pot_address_list.append(pot.address)
  2614.                
  2615.                 """
  2616.                
  2617.                Now for each pot in valid_pot_list, we want to test every applicable
  2618.                superslide scenario
  2619.                
  2620.                Before each one, we need to copy the current state and then modify the copies
  2621.                to check for the solution
  2622.                
  2623.                """
  2624.                
  2625.                 for pot in valid_pot_list:
  2626.                    
  2627.                     # both bomb and smoke loaded on superslide
  2628.                     if Grabbable_Dict[pot][0][0] == '1':
  2629.                        
  2630.                         action_list100 = []
  2631.                        
  2632.                         # COPY STATE
  2633.                         #######################################################
  2634.                         Room_List_Copy = Copy_Room_List(Room_List)
  2635.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  2636.                        
  2637.                         room_copy_dict = {}
  2638.                         for room in Room_List_Copy:
  2639.                             room_copy_dict[room.number] = room
  2640.                        
  2641.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  2642.                        
  2643.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  2644.                         #######################################################
  2645.                        
  2646.                         Bomb_And_Smoke_Superslide(Heap_Copy, current_room.number, Overlay_Dict_Copy)
  2647.                         action_list100.append("Superslide with Bomb and Smoke still allocated")
  2648.                        
  2649.                         # The room we superslide into through the plane corresponding to the given pot
  2650.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  2651.                        
  2652.                         destination_room_copy = room_copy_dict[destination_room.number]
  2653.                         current_room_copy = room_copy_dict[current_room.number]
  2654.                        
  2655.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  2656.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  2657.                        
  2658.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2659.                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2660.                        
  2661.                         # Now exit the chest room
  2662.                         Load_Room(Heap_Copy, current_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2663.                         action_list100.append("Load Room: Room %d" %(current_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2664.                        
  2665.                         # Now reenter the chest room
  2666.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2667.                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2668.                        
  2669.                         ##### Now check for chests/deku guards
  2670.                        
  2671.                         chest_guard_list = []
  2672.                        
  2673.                         for entry in Heap_Copy:
  2674.                            
  2675.                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  2676.                                 chest_guard_list.append(entry)
  2677.                        
  2678.                         soln_found = False
  2679.                         for entry in chest_guard_list:
  2680.                             if (pot.address - entry.address) in Offset_List:
  2681.                                
  2682.                                 action_list100.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  2683.                                
  2684.                                 if (pot.address - entry.address) == 0x160:
  2685.                                     angle_solution_count += 1
  2686.                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2687.                                 elif (pot.address - entry.address) == 0x1F0:
  2688.                                     position_solution_count += 1
  2689.                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2690.                                
  2691.                                 soln_found = True
  2692.                                
  2693.                         if soln_found is True:
  2694.                             total_action_list = action_list + action_list100
  2695.                            
  2696.                             # the "a" argument is important so we don't overwrite previous solutions
  2697.                             with open(filename, "a") as file:
  2698.                                
  2699.                                 for action in total_action_list:
  2700.                                    
  2701.                                     file.write(action + "\n")
  2702.                                 file.write("-----\n")
  2703.                    
  2704.                    
  2705.                     ##### Only smoke is loaded from superslide
  2706.                     elif Grabbable_Dict[pot][0][1] == '1':
  2707.                        
  2708.                         action_list010 = []
  2709.                        
  2710.                         # COPY STATE
  2711.                         #######################################################
  2712.                         Room_List_Copy = Copy_Room_List(Room_List)
  2713.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  2714.                        
  2715.                         room_copy_dict = {}
  2716.                         for room in Room_List_Copy:
  2717.                             room_copy_dict[room.number] = room
  2718.                        
  2719.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  2720.                        
  2721.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  2722.                         #######################################################
  2723.                        
  2724.                         Allocate_Smoke(Heap_Copy, current_room.number, Overlay_Dict_Copy)
  2725.                         action_list010.append("Superslide with Smoke still allocated")
  2726.                        
  2727.                         # The room we superslide into through the plane corresponding to the given pot
  2728.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  2729.                        
  2730.                         destination_room_copy = room_copy_dict[destination_room.number]
  2731.                         current_room_copy = room_copy_dict[current_room.number]
  2732.                        
  2733.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  2734.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  2735.                        
  2736.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2737.                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2738.                        
  2739.                         # Now exit the chest room
  2740.                         Load_Room(Heap_Copy, current_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2741.                         action_list010.append("Load Room: Room %d" %(current_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2742.                        
  2743.                         # Now reenter the chest room
  2744.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2745.                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2746.                        
  2747.                        
  2748.                         ##### Now check for chests/deku guards
  2749.                        
  2750.                         chest_guard_list = []
  2751.                        
  2752.                         for entry in Heap_Copy:
  2753.                            
  2754.                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  2755.                                 chest_guard_list.append(entry)
  2756.                        
  2757.                         soln_found = False
  2758.                         for entry in chest_guard_list:
  2759.                             if (pot.address - entry.address) in Offset_List:
  2760.                                
  2761.                                 action_list010.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  2762.                                
  2763.                                 if (pot.address - entry.address) == 0x160:
  2764.                                     angle_solution_count += 1
  2765.                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2766.                                 elif (pot.address - entry.address) == 0x1F0:
  2767.                                     position_solution_count += 1
  2768.                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2769.                                
  2770.                                 soln_found = True
  2771.                                
  2772.                         if soln_found is True:
  2773.                             total_action_list = action_list + action_list010
  2774.                            
  2775.                             # the "a" argument is important so we don't overwrite previous solutions
  2776.                             with open(filename, "a") as file:
  2777.                                
  2778.                                 for action in total_action_list:
  2779.                                    
  2780.                                     file.write(action + "\n")
  2781.                                 file.write("-----\n")
  2782.                    
  2783.                    
  2784.                     #### Bomb and Smoke are both unloaded
  2785.                     elif Grabbable_Dict[pot][0][2] == '1':
  2786.                        
  2787.                         action_list001 = []
  2788.                        
  2789.                         # COPY STATE
  2790.                         #######################################################
  2791.                         Room_List_Copy = Copy_Room_List(Room_List)
  2792.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  2793.                        
  2794.                         room_copy_dict = {}
  2795.                         for room in Room_List_Copy:
  2796.                             room_copy_dict[room.number] = room
  2797.                        
  2798.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  2799.                        
  2800.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  2801.                         #######################################################
  2802.                        
  2803.                         # Do not allocate anything
  2804.                         action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  2805.                        
  2806.                         # The room we superslide into through the plane corresponding to the given pot
  2807.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  2808.                        
  2809.                         destination_room_copy = room_copy_dict[destination_room.number]
  2810.                         current_room_copy = room_copy_dict[current_room.number]
  2811.                        
  2812.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  2813.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  2814.                        
  2815.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2816.                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2817.                        
  2818.                         # Now exit the chest room
  2819.                         Load_Room(Heap_Copy, current_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2820.                         action_list001.append("Load Room: Room %d" %(current_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2821.                        
  2822.                         # Now reenter the chest room
  2823.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2824.                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2825.                        
  2826.                        
  2827.                         ##### Now check for chests/deku guards
  2828.                        
  2829.                         chest_guard_list = []
  2830.                        
  2831.                         for entry in Heap_Copy:
  2832.                            
  2833.                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  2834.                                 chest_guard_list.append(entry)
  2835.                        
  2836.                         soln_found = False
  2837.                         for entry in chest_guard_list:
  2838.                             if (pot.address - entry.address) in Offset_List:
  2839.                                
  2840.                                 action_list001.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  2841.                                
  2842.                                 if (pot.address - entry.address) == 0x160:
  2843.                                     angle_solution_count += 1
  2844.                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2845.                                 elif (pot.address - entry.address) == 0x1F0:
  2846.                                     position_solution_count += 1
  2847.                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2848.                                
  2849.                                 soln_found = True
  2850.                                
  2851.                         if soln_found is True:
  2852.                             total_action_list = action_list + action_list001
  2853.                            
  2854.                             # the "a" argument is important so we don't overwrite previous solutions
  2855.                             with open(filename, "a") as file:
  2856.                                
  2857.                                 for action in total_action_list:
  2858.                                    
  2859.                                     file.write(action + "\n")
  2860.                                 file.write("-----\n")
  2861.                                
  2862.                                
  2863.                                
  2864.             # Case 2: there is a valid grabbable actor in the current room AND there is a chest or deku guard                  
  2865.             elif (current_room in valid_grabbable_actor_room_list) and ((Chest_In_Room(current_room) is True) or (Deku_Guard_In_Room(current_room) is True)):      
  2866.                
  2867.                 valid_pot_list = []
  2868.                 pot_address_list = []
  2869.                
  2870.                 for pot in Grabbable_Dict:
  2871.                    
  2872.                     if Actor_Is_In_Room(current_room, pot) is True:
  2873.                         valid_pot_list.append(pot)
  2874.                         pot_address_list.append(pot.address)
  2875.                
  2876.                
  2877.                 """
  2878.                
  2879.                Now for each pot in valid_pot_list, we want to test every applicable
  2880.                superslide scenario
  2881.                
  2882.                Before each one, we need to copy the current state and then modify the copies
  2883.                to check for the solution
  2884.                
  2885.                Also, for every case, we need to consider every possible room that contains
  2886.                a chest/deku guard that neighbors the room we just entered (meaning you
  2887.                will need to make copies of the copies of the state)
  2888.                
  2889.                """
  2890.                
  2891.                 for pot in valid_pot_list:
  2892.                    
  2893.                     # both bomb and smoke loaded on superslide
  2894.                     if Grabbable_Dict[pot][0][0] == '1':
  2895.                        
  2896.                         action_list100 = []
  2897.                        
  2898.                         # COPY STATE
  2899.                         #######################################################
  2900.                         Room_List_Copy = Copy_Room_List(Room_List)
  2901.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  2902.                        
  2903.                         room_copy_dict = {}
  2904.                         for room in Room_List_Copy:
  2905.                             room_copy_dict[room.number] = room
  2906.                        
  2907.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  2908.                        
  2909.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  2910.                         #######################################################
  2911.                        
  2912.                         Bomb_And_Smoke_Superslide(Heap_Copy, current_room.number, Overlay_Dict_Copy)
  2913.                         action_list100.append("Superslide with Bomb and Smoke still allocated")
  2914.                        
  2915.                         # The room we superslide into through the plane corresponding to the given pot
  2916.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  2917.                        
  2918.                         destination_room_copy = room_copy_dict[destination_room.number]
  2919.                        
  2920.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  2921.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  2922.                        
  2923.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  2924.                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  2925.                        
  2926.                         """
  2927.                        
  2928.                        Now we check all neighbors of our current room (destination_room) and for
  2929.                        each neighbor that has a chest or deku guard in it, we will create a copy
  2930.                        of our copy of the state, then enter each of them through each possible
  2931.                        loading plane and then check the chest/guard addresses and see if anything
  2932.                        lines up
  2933.                        
  2934.                        """
  2935.                        
  2936.                         for neighbor in Neighbors(destination_room, Room_List):
  2937.                            
  2938.                             if Chest_In_Room(neighbor) == True or Deku_Guard_In_Room(neighbor) == True:
  2939.                                
  2940.                                 for transition in Shared_Transitions(destination_room, neighbor):
  2941.                                    
  2942.                                      # COPY STATE
  2943.                                     #######################################################
  2944.                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  2945.                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  2946.                                    
  2947.                                     room_copy_dict_2 = {}
  2948.                                     for room in Room_List_Copy_2:
  2949.                                         room_copy_dict_2[room.number] = room
  2950.                                    
  2951.                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  2952.                                    
  2953.                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  2954.                                     #######################################################
  2955.                                    
  2956.                                     action_list_2 = []
  2957.                                    
  2958.                                     transition_copy = Find_Actor_Copy(transition, Room_List_Copy_2)
  2959.                                    
  2960.                                     neighbor_copy = room_copy_dict_2[neighbor.number]
  2961.                                    
  2962.                                     Load_Room(Heap_Copy_2, neighbor_copy, transition_copy, Overlay_Dict_Copy_2)
  2963.                                     action_list_2.append("Load Room: Room %d" %(neighbor_copy.number) + " with " + transition_copy.name + " %d" %(transition_copy.priority))
  2964.                                    
  2965.                                    
  2966.                                     ##### Now check for chests/deku guards
  2967.                        
  2968.                                     chest_guard_list = []
  2969.                                    
  2970.                                     for entry in Heap_Copy_2:
  2971.                                        
  2972.                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  2973.                                             chest_guard_list.append(entry)
  2974.                                    
  2975.                                     soln_found = False
  2976.                                     for entry in chest_guard_list:
  2977.                                         if (pot.address - entry.address) in Offset_List:
  2978.                                            
  2979.                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  2980.  
  2981.                                             if (pot.address - entry.address) == 0x160:
  2982.                                                 angle_solution_count += 1
  2983.                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2984.                                             elif (pot.address - entry.address) == 0x1F0:
  2985.                                                 position_solution_count += 1
  2986.                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  2987.  
  2988.                                             soln_found = True
  2989.                                            
  2990.                                     if soln_found is True:
  2991.                                         total_action_list = action_list + action_list100 + action_list_2
  2992.                                        
  2993.                                         # the "a" argument is important so we don't overwrite previous solutions
  2994.                                         with open(filename, "a") as file:
  2995.                                            
  2996.                                             for action in total_action_list:
  2997.                                                
  2998.                                                 file.write(action + "\n")
  2999.                                             file.write("-----\n")
  3000.                    
  3001.                    
  3002.                     ##### Only smoke is loaded from superslide
  3003.                     elif Grabbable_Dict[pot][0][1] == '1':
  3004.                        
  3005.                         action_list010 = []
  3006.                        
  3007.                         # COPY STATE
  3008.                         #######################################################
  3009.                         Room_List_Copy = Copy_Room_List(Room_List)
  3010.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  3011.                        
  3012.                         room_copy_dict = {}
  3013.                         for room in Room_List_Copy:
  3014.                             room_copy_dict[room.number] = room
  3015.                        
  3016.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  3017.                        
  3018.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  3019.                         #######################################################
  3020.                        
  3021.                         Allocate_Smoke(Heap_Copy, current_room.number, Overlay_Dict_Copy)
  3022.                         action_list010.append("Superslide with Smoke still allocated")
  3023.                        
  3024.                         # The room we superslide into through the plane corresponding to the given pot
  3025.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  3026.                        
  3027.                         destination_room_copy = room_copy_dict[destination_room.number]
  3028.                        
  3029.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  3030.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  3031.                        
  3032.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  3033.                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3034.                        
  3035.                         """
  3036.                        
  3037.                        Now we check all neighbors of our current room (destination_room) and for
  3038.                        each neighbor that has a chest or deku guard in it, we will create a copy
  3039.                        of our copy of the state, then enter each of them through each possible
  3040.                        loading plane and then check the chest/guard addresses and see if anything
  3041.                        lines up
  3042.                        
  3043.                        """
  3044.                        
  3045.                         for neighbor in Neighbors(destination_room, Room_List):
  3046.                            
  3047.                             if Chest_In_Room(neighbor) == True or Deku_Guard_In_Room(neighbor) == True:
  3048.  
  3049.                                 for transition in Shared_Transitions(destination_room, neighbor):
  3050.                                    
  3051.                                     # COPY STATE
  3052.                                     #######################################################
  3053.                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  3054.                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3055.                                    
  3056.                                     room_copy_dict_2 = {}
  3057.                                     for room in Room_List_Copy_2:
  3058.                                         room_copy_dict_2[room.number] = room
  3059.                                    
  3060.                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3061.                                    
  3062.                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  3063.                                     #######################################################
  3064.                                    
  3065.                                     action_list_2 = []
  3066.                                    
  3067.                                     transition_copy = Find_Actor_Copy(transition, Room_List_Copy_2)
  3068.                                    
  3069.                                     neighbor_copy = room_copy_dict_2[neighbor.number]
  3070.                                    
  3071.                                     Load_Room(Heap_Copy_2, neighbor_copy, transition_copy, Overlay_Dict_Copy_2)
  3072.                                     action_list_2.append("Load Room: Room %d" %(neighbor_copy.number) + " with " + transition_copy.name + " %d" %(transition_copy.priority))
  3073.                                    
  3074.                                    
  3075.                                     ##### Now check for chests/deku guards
  3076.                        
  3077.                                     chest_guard_list = []
  3078.                                    
  3079.                                     for entry in Heap_Copy_2:
  3080.                                        
  3081.                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3082.                                             chest_guard_list.append(entry)
  3083.                                    
  3084.                                     soln_found = False
  3085.                                     for entry in chest_guard_list:
  3086.                                         if (pot.address - entry.address) in Offset_List:
  3087.                                            
  3088.                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3089.  
  3090.                                             if (pot.address - entry.address) == 0x160:
  3091.                                                 angle_solution_count += 1
  3092.                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3093.                                             elif (pot.address - entry.address) == 0x1F0:
  3094.                                                 position_solution_count += 1
  3095.                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3096.  
  3097.                                             soln_found = True
  3098.                                            
  3099.                                     if soln_found is True:
  3100.                                         total_action_list = action_list + action_list010 + action_list_2
  3101.                                        
  3102.                                         # the "a" argument is important so we don't overwrite previous solutions
  3103.                                         with open(filename, "a") as file:
  3104.                                            
  3105.                                             for action in total_action_list:
  3106.                                                
  3107.                                                 file.write(action + "\n")
  3108.                                             file.write("-----\n")
  3109.                        
  3110.                        
  3111.                     #### Bomb and Smoke are both unloaded
  3112.                     elif Grabbable_Dict[pot][0][2] == '1':
  3113.                        
  3114.                         action_list001 = []
  3115.                        
  3116.                         # COPY STATE
  3117.                         #######################################################
  3118.                         Room_List_Copy = Copy_Room_List(Room_List)
  3119.                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  3120.                        
  3121.                         room_copy_dict = {}
  3122.                         for room in Room_List_Copy:
  3123.                             room_copy_dict[room.number] = room
  3124.                        
  3125.                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  3126.                        
  3127.                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  3128.                         #######################################################
  3129.                        
  3130.                         # Do not allocate anything
  3131.                         action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  3132.                        
  3133.                         # The room we superslide into through the plane corresponding to the given pot
  3134.                         destination_room = Current_Room([current_room, Grabbable_Dict[pot][1]], Room_List)
  3135.                        
  3136.                         destination_room_copy = room_copy_dict[destination_room.number]
  3137.                        
  3138.                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy)
  3139.                         superslide_transition_copy = Grabbable_Dict_Copy[pot_copy][1]
  3140.                        
  3141.                         Load_Room(Heap_Copy, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy)
  3142.                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3143.                        
  3144.                         """
  3145.                        
  3146.                        Now we check all neighbors of our current room (destination_room) and for
  3147.                        each neighbor that has a chest or deku guard in it, we will create a copy
  3148.                        of our copy of the state, then enter each of them through each possible
  3149.                        loading plane and then check the chest/guard addresses and see if anything
  3150.                        lines up
  3151.                        
  3152.                        """
  3153.                        
  3154.                         for neighbor in Neighbors(destination_room, Room_List):
  3155.                            
  3156.                             if Chest_In_Room(neighbor) == True or Deku_Guard_In_Room(neighbor) == True:
  3157.  
  3158.                                 for transition in Shared_Transitions(destination_room, neighbor):
  3159.  
  3160.                                     # COPY STATE
  3161.                                     #######################################################
  3162.                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  3163.                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3164.                                    
  3165.                                     room_copy_dict_2 = {}
  3166.                                     for room in Room_List_Copy_2:
  3167.                                         room_copy_dict_2[room.number] = room
  3168.                                    
  3169.                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3170.                                    
  3171.                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  3172.                                     #######################################################
  3173.  
  3174.                                     action_list_2 = []
  3175.                                    
  3176.                                     transition_copy = Find_Actor_Copy(transition, Room_List_Copy_2)
  3177.                                    
  3178.                                     neighbor_copy = room_copy_dict_2[neighbor.number]
  3179.                                    
  3180.                                     Load_Room(Heap_Copy_2, neighbor_copy, transition_copy, Overlay_Dict_Copy_2)
  3181.                                     action_list_2.append("Load Room: Room %d" %(neighbor_copy.number) + " with " + transition_copy.name + " %d" %(transition_copy.priority))
  3182.                                    
  3183.                                    
  3184.                                     ##### Now check for chests/deku guards
  3185.                        
  3186.                                     chest_guard_list = []
  3187.                                    
  3188.                                     for entry in Heap_Copy_2:
  3189.                                        
  3190.                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3191.                                             chest_guard_list.append(entry)
  3192.                                    
  3193.                                     soln_found = False
  3194.                                     for entry in chest_guard_list:
  3195.                                         if (pot.address - entry.address) in Offset_List:
  3196.                                            
  3197.                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3198.  
  3199.                                             if (pot.address - entry.address) == 0x160:
  3200.                                                 angle_solution_count += 1
  3201.                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3202.                                             elif (pot.address - entry.address) == 0x1F0:
  3203.                                                 position_solution_count += 1
  3204.                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3205.  
  3206.                                             soln_found = True
  3207.                                            
  3208.                                     if soln_found is True:
  3209.                                         total_action_list = action_list + action_list001 + action_list_2
  3210.                                        
  3211.                                         # the "a" argument is important so we don't overwrite previous solutions
  3212.                                         with open(filename, "a") as file:
  3213.                                            
  3214.                                             for action in total_action_list:
  3215.                                                
  3216.                                                 file.write(action + "\n")
  3217.                                             file.write("-----\n")
  3218.                        
  3219.                        
  3220.             ##### Case 3: there is NOT a valid grabbable actor in the current room            
  3221.             elif (current_room not in valid_grabbable_actor_room_list):
  3222.                
  3223.                 for neighbor in Neighbors(current_room, Room_List):
  3224.                    
  3225.                     ##### Valid grabbable actor in neighbor
  3226.                     if neighbor in valid_grabbable_actor_room_list:
  3227.                        
  3228.                        
  3229.                         ##### Iterate through all pots in this room
  3230.                        
  3231.                         valid_pot_list = []
  3232.                         pot_address_list = []
  3233.                        
  3234.                         for pot in Grabbable_Dict:
  3235.                            
  3236.                             if Actor_Is_In_Room(neighbor, pot) is True:
  3237.                                 valid_pot_list.append(pot)
  3238.                                 pot_address_list.append(pot.address)
  3239.                        
  3240.                         # For every transition in Shared_Transitions(current_room, neighbor)
  3241.                         for transition in Shared_Transitions(current_room, neighbor):
  3242.                            
  3243.                             action_list_transition = []
  3244.                            
  3245.                             ##### COPY THE STATE
  3246.                             #######################################################
  3247.                             Room_List_Copy = Copy_Room_List(Room_List)
  3248.                             Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  3249.                            
  3250.                             room_copy_dict = {}
  3251.                             for room in Room_List_Copy:
  3252.                                 room_copy_dict[room.number] = room
  3253.                            
  3254.                             Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  3255.                            
  3256.                             Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  3257.                             #######################################################
  3258.                            
  3259.                             ##### ENTER neighbor after copying it
  3260.                            
  3261.                             neighbor_copy = room_copy_dict[neighbor.number]
  3262.                             transition_copy = Find_Actor_Copy(transition, Room_List_Copy)
  3263.  
  3264.                             Load_Room(Heap_Copy, neighbor_copy, transition_copy, Overlay_Dict_Copy)
  3265.                             action_list_transition.append("Load Room: Room %d" %(neighbor_copy.number) + " with " + transition_copy.name + " %d" %(transition_copy.priority))
  3266.                                
  3267.                            
  3268.                             # If there is a chest/guard, superslide, then check neighbors for chests/guards and test all (copy state)
  3269.                             if Chest_In_Room(neighbor) == True or Deku_Guard_In_Room(neighbor) == True:
  3270.                                
  3271.                                 for pot in valid_pot_list:
  3272.                                    
  3273.                                     # both bomb and smoke loaded on superslide
  3274.                                     if Grabbable_Dict[pot][0][0] == '1':
  3275.                                        
  3276.                                         action_list100 = []
  3277.                                        
  3278.                                         # COPY STATE
  3279.                                         #######################################################
  3280.                                         Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  3281.                                         Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3282.                                        
  3283.                                         room_copy_dict_SS = {}
  3284.                                         for room in Room_List_Copy_SS:
  3285.                                             room_copy_dict_SS[room.number] = room
  3286.                                        
  3287.                                         Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  3288.                                        
  3289.                                         Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  3290.                                         #######################################################
  3291.                                        
  3292.                                         Bomb_And_Smoke_Superslide(Heap_Copy_SS, neighbor.number, Overlay_Dict_Copy_SS)
  3293.                                         action_list100.append("Superslide with Bomb and Smoke still allocated")
  3294.                                        
  3295.                                         # The room we superslide into through the plane corresponding to the given pot
  3296.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3297.                                        
  3298.                                         destination_room_copy = room_copy_dict_SS[destination_room.number]
  3299.                                        
  3300.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  3301.                                         superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  3302.                                        
  3303.                                         Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  3304.                                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3305.                                        
  3306.                                         """
  3307.                                        
  3308.                                        Now we check all neighbors of our current room (destination_room) and for
  3309.                                        each neighbor that has a chest or deku guard in it, we will create a copy
  3310.                                        of our copy of the state, then enter each of them through each possible
  3311.                                        loading plane and then check the chest/guard addresses and see if anything
  3312.                                        lines up
  3313.                                        
  3314.                                        """
  3315.                                        
  3316.                                         for bordering_room in Neighbors(destination_room, Room_List):
  3317.                                            
  3318.                                             if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  3319.                                                
  3320.                                                 for loading_plane in Shared_Transitions(destination_room, bordering_room):
  3321.                                                    
  3322.                                                      # COPY STATE
  3323.                                                     #######################################################
  3324.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  3325.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  3326.                                                    
  3327.                                                     room_copy_dict_2 = {}
  3328.                                                     for room in Room_List_Copy_2:
  3329.                                                         room_copy_dict_2[room.number] = room
  3330.                                                    
  3331.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3332.                                                    
  3333.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  3334.                                                     #######################################################
  3335.                                                    
  3336.                                                     action_list_2 = []
  3337.                                                    
  3338.                                                     loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  3339.                                                    
  3340.                                                     bordering_room_copy = room_copy_dict_2[bordering_room.number]
  3341.                                                    
  3342.                                                     Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  3343.                                                     action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  3344.                                                    
  3345.                                                    
  3346.                                                     ##### Now check for chests/deku guards
  3347.                                        
  3348.                                                     chest_guard_list = []
  3349.                                                    
  3350.                                                     for entry in Heap_Copy_2:
  3351.                                                        
  3352.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3353.                                                             chest_guard_list.append(entry)
  3354.                                                    
  3355.                                                     soln_found = False
  3356.                                                     for entry in chest_guard_list:
  3357.                                                         if (pot.address - entry.address) in Offset_List:
  3358.                                                            
  3359.                                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3360.  
  3361.                                                             if (pot.address - entry.address) == 0x160:
  3362.                                                                 angle_solution_count += 1
  3363.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3364.                                                             elif (pot.address - entry.address) == 0x1F0:
  3365.                                                                 position_solution_count += 1
  3366.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3367.  
  3368.                                                             soln_found = True
  3369.                                                            
  3370.                                                     if soln_found is True:
  3371.                                                         total_action_list = action_list + action_list_transition + action_list100 + action_list_2
  3372.                                                        
  3373.                                                         # the "a" argument is important so we don't overwrite previous solutions
  3374.                                                         with open(filename, "a") as file:
  3375.                                                            
  3376.                                                             for action in total_action_list:
  3377.                                                                
  3378.                                                                 file.write(action + "\n")
  3379.                                                             file.write("-----\n")
  3380.                                    
  3381.                                        
  3382.                                        
  3383.                                     ##### Only smoke is loaded from superslide
  3384.                                     elif Grabbable_Dict[pot][0][1] == '1':
  3385.                                        
  3386.                                         action_list010 = []
  3387.                                        
  3388.                                         # COPY STATE
  3389.                                         #######################################################
  3390.                                         Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  3391.                                         Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3392.                                        
  3393.                                         room_copy_dict_SS = {}
  3394.                                         for room in Room_List_Copy_SS:
  3395.                                             room_copy_dict_SS[room.number] = room
  3396.                                        
  3397.                                         Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  3398.                                        
  3399.                                         Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  3400.                                         #######################################################
  3401.                                        
  3402.                                         Allocate_Smoke(Heap_Copy_SS, neighbor.number, Overlay_Dict_Copy_SS)
  3403.                                         action_list010.append("Superslide with Smoke still allocated")
  3404.                                        
  3405.                                         # The room we superslide into through the plane corresponding to the given pot
  3406.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3407.                                        
  3408.                                         destination_room_copy = room_copy_dict_SS[destination_room.number]
  3409.                                        
  3410.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  3411.                                         superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  3412.                                        
  3413.                                         Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  3414.                                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3415.                                        
  3416.                                         """
  3417.                                        
  3418.                                        Now we check all neighbors of our current room (destination_room) and for
  3419.                                        each neighbor that has a chest or deku guard in it, we will create a copy
  3420.                                        of our copy of the state, then enter each of them through each possible
  3421.                                        loading plane and then check the chest/guard addresses and see if anything
  3422.                                        lines up
  3423.                                        
  3424.                                        """
  3425.                                        
  3426.                                         for bordering_room in Neighbors(destination_room, Room_List):
  3427.                                            
  3428.                                             if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  3429.                                                
  3430.                                                 for loading_plane in Shared_Transitions(destination_room, bordering_room):
  3431.                                                    
  3432.                                                      # COPY STATE
  3433.                                                     #######################################################
  3434.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  3435.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  3436.                                                    
  3437.                                                     room_copy_dict_2 = {}
  3438.                                                     for room in Room_List_Copy_2:
  3439.                                                         room_copy_dict_2[room.number] = room
  3440.                                                    
  3441.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3442.                                                    
  3443.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  3444.                                                     #######################################################
  3445.                                                    
  3446.                                                     action_list_2 = []
  3447.                                                    
  3448.                                                     loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  3449.                                                    
  3450.                                                     bordering_room_copy = room_copy_dict_2[bordering_room.number]
  3451.                                                    
  3452.                                                     Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  3453.                                                     action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  3454.                                                    
  3455.                                                    
  3456.                                                     ##### Now check for chests/deku guards
  3457.                                        
  3458.                                                     chest_guard_list = []
  3459.                                                    
  3460.                                                     for entry in Heap_Copy_2:
  3461.                                                        
  3462.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3463.                                                             chest_guard_list.append(entry)
  3464.                                                    
  3465.                                                     soln_found = False
  3466.                                                     for entry in chest_guard_list:
  3467.                                                         if (pot.address - entry.address) in Offset_List:
  3468.                                                            
  3469.                                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3470.                                                            
  3471.                                                             if (pot.address - entry.address) == 0x160:
  3472.                                                                 angle_solution_count += 1
  3473.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3474.                                                             elif (pot.address - entry.address) == 0x1F0:
  3475.                                                                 position_solution_count += 1
  3476.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3477.                                
  3478.                                                             soln_found = True
  3479.                                                            
  3480.                                                     if soln_found is True:
  3481.                                                         total_action_list = action_list + action_list_transition + action_list010 + action_list_2
  3482.                                                        
  3483.                                                         # the "a" argument is important so we don't overwrite previous solutions
  3484.                                                         with open(filename, "a") as file:
  3485.                                                            
  3486.                                                             for action in total_action_list:
  3487.                                                                
  3488.                                                                 file.write(action + "\n")
  3489.                                                             file.write("-----\n")
  3490.  
  3491.  
  3492.                                     #### Bomb and Smoke are both unloaded
  3493.                                     elif Grabbable_Dict[pot][0][2] == '1':
  3494.                                        
  3495.                                         action_list001 = []
  3496.                                        
  3497.                                         # COPY STATE
  3498.                                         #######################################################
  3499.                                         Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  3500.                                         Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3501.                                        
  3502.                                         room_copy_dict_SS = {}
  3503.                                         for room in Room_List_Copy_SS:
  3504.                                             room_copy_dict_SS[room.number] = room
  3505.                                        
  3506.                                         Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  3507.                                        
  3508.                                         Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  3509.                                         #######################################################
  3510.                                        
  3511.                                         # Do not allocate anything
  3512.                                         action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  3513.                                        
  3514.                                         # The room we superslide into through the plane corresponding to the given pot
  3515.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3516.                                        
  3517.                                         destination_room_copy = room_copy_dict_SS[destination_room.number]
  3518.                                        
  3519.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  3520.                                         superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  3521.                                        
  3522.                                         Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  3523.                                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3524.                                        
  3525.                                         """
  3526.                                        
  3527.                                        Now we check all neighbors of our current room (destination_room) and for
  3528.                                        each neighbor that has a chest or deku guard in it, we will create a copy
  3529.                                        of our copy of the state, then enter each of them through each possible
  3530.                                        loading plane and then check the chest/guard addresses and see if anything
  3531.                                        lines up
  3532.                                        
  3533.                                        """
  3534.                                        
  3535.                                         for bordering_room in Neighbors(destination_room, Room_List):
  3536.                                            
  3537.                                             if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  3538.                                                
  3539.                                                 for loading_plane in Shared_Transitions(destination_room, bordering_room):
  3540.                                                    
  3541.                                                      # COPY STATE
  3542.                                                     #######################################################
  3543.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  3544.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  3545.                                                    
  3546.                                                     room_copy_dict_2 = {}
  3547.                                                     for room in Room_List_Copy_2:
  3548.                                                         room_copy_dict_2[room.number] = room
  3549.                                                    
  3550.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3551.                                                    
  3552.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  3553.                                                     #######################################################
  3554.                                                    
  3555.                                                     action_list_2 = []
  3556.                                                    
  3557.                                                     loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  3558.                                                    
  3559.                                                     bordering_room_copy = room_copy_dict_2[bordering_room.number]
  3560.                                                    
  3561.                                                     Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  3562.                                                     action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  3563.                                                    
  3564.                                                    
  3565.                                                     ##### Now check for chests/deku guards
  3566.                                        
  3567.                                                     chest_guard_list = []
  3568.                                                    
  3569.                                                     for entry in Heap_Copy_2:
  3570.                                                        
  3571.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3572.                                                             chest_guard_list.append(entry)
  3573.                                                    
  3574.                                                     soln_found = False
  3575.                                                     for entry in chest_guard_list:
  3576.                                                         if (pot.address - entry.address) in Offset_List:
  3577.                                                            
  3578.                                                             action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3579.                                                            
  3580.                                                             if (pot.address - entry.address) == 0x160:
  3581.                                                                 angle_solution_count += 1
  3582.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3583.                                                             elif (pot.address - entry.address) == 0x1F0:
  3584.                                                                 position_solution_count += 1
  3585.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3586.                                
  3587.                                                             soln_found = True
  3588.                                                            
  3589.                                                     if soln_found is True:
  3590.                                                         total_action_list = action_list + action_list_transition + action_list001 + action_list_2
  3591.                                                        
  3592.                                                         # the "a" argument is important so we don't overwrite previous solutions
  3593.                                                         with open(filename, "a") as file:
  3594.                                                            
  3595.                                                             for action in total_action_list:
  3596.                                                                
  3597.                                                                 file.write(action + "\n")
  3598.                                                             file.write("-----\n")                
  3599.  
  3600.                                        
  3601.                                        
  3602.                             # If there isn't a chest/guard, superslide (into chest/guard room by assumption), then exit then reenter it (this case never happens in palace, so this is an okay assumption)
  3603.                             elif Chest_In_Room(neighbor) == False and Deku_Guard_In_Room(neighbor) == False:
  3604.                                
  3605.                                 for pot in valid_pot_list:
  3606.                                    
  3607.                                     # both bomb and smoke loaded on superslide
  3608.                                     if Grabbable_Dict[pot][0][0] == '1':
  3609.                                        
  3610.                                         action_list100 = []
  3611.                                        
  3612.                                         # COPY STATE
  3613.                                         #######################################################
  3614.                                         Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  3615.                                         Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3616.                                        
  3617.                                         room_copy_dict_2 = {}
  3618.                                         for room in Room_List_Copy_2:
  3619.                                             room_copy_dict_2[room.number] = room
  3620.                                        
  3621.                                         Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3622.                                        
  3623.                                         Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  3624.                                         #######################################################
  3625.                                        
  3626.                                         Bomb_And_Smoke_Superslide(Heap_Copy_2, neighbor_copy.number, Overlay_Dict_Copy_2)
  3627.                                         action_list100.append("Superslide with Bomb and Smoke still allocated")
  3628.                                        
  3629.                                         # The room we superslide into through the plane corresponding to the given pot
  3630.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3631.                                        
  3632.                                         destination_room_copy = room_copy_dict_2[destination_room.number]
  3633.                                         neighbor_copy_2 = room_copy_dict_2[neighbor_copy.number]
  3634.                                        
  3635.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  3636.                                         superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  3637.                                        
  3638.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3639.                                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3640.                                        
  3641.                                         # Now exit the chest room
  3642.                                         Load_Room(Heap_Copy_2, neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  3643.                                         action_list100.append("Load Room: Room %d" %(neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3644.                                        
  3645.                                         # Now reenter the chest room
  3646.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3647.                                         action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3648.                                        
  3649.                                         ##### Now check for chests/deku guards
  3650.                                        
  3651.                                         chest_guard_list = []
  3652.                                        
  3653.                                         for entry in Heap_Copy_2:
  3654.                                            
  3655.                                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3656.                                                 chest_guard_list.append(entry)
  3657.                                        
  3658.                                         soln_found = False
  3659.                                         for entry in chest_guard_list:
  3660.                                             if (pot.address - entry.address) in Offset_List:
  3661.                                                
  3662.                                                 action_list100.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3663.                                                
  3664.                                                 if (pot.address - entry.address) == 0x160:
  3665.                                                     angle_solution_count += 1
  3666.                                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3667.                                                 elif (pot.address - entry.address) == 0x1F0:
  3668.                                                     position_solution_count += 1
  3669.                                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3670.                                
  3671.                                                 soln_found = True
  3672.                                                
  3673.                                         if soln_found is True:
  3674.                                             total_action_list = action_list + action_list_transition + action_list100
  3675.                                            
  3676.                                             # the "a" argument is important so we don't overwrite previous solutions
  3677.                                             with open(filename, "a") as file:
  3678.                                                
  3679.                                                 for action in total_action_list:
  3680.                                                    
  3681.                                                     file.write(action + "\n")
  3682.                                                 file.write("-----\n")
  3683.                                    
  3684.                                    
  3685.                                    
  3686.                                     ##### Only smoke is loaded from superslide
  3687.                                     elif Grabbable_Dict[pot][0][1] == '1':
  3688.  
  3689.                                         action_list010 = []
  3690.                                        
  3691.                                         # COPY STATE
  3692.                                         #######################################################
  3693.                                         Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  3694.                                         Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3695.                                        
  3696.                                         room_copy_dict_2 = {}
  3697.                                         for room in Room_List_Copy_2:
  3698.                                             room_copy_dict_2[room.number] = room
  3699.                                        
  3700.                                         Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3701.                                        
  3702.                                         Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  3703.                                         #######################################################
  3704.                                        
  3705.                                         Allocate_Smoke(Heap_Copy_2, neighbor_copy.number, Overlay_Dict_Copy_2)
  3706.                                         action_list010.append("Superslide with Smoke still allocated")
  3707.                                        
  3708.                                         # The room we superslide into through the plane corresponding to the given pot
  3709.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3710.                                        
  3711.                                         destination_room_copy = room_copy_dict_2[destination_room.number]
  3712.                                         neighbor_copy_2 = room_copy_dict_2[neighbor_copy.number]
  3713.                                        
  3714.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  3715.                                         superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  3716.                                        
  3717.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3718.                                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3719.                                        
  3720.                                         # Now exit the chest room
  3721.                                         Load_Room(Heap_Copy_2, neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  3722.                                         action_list010.append("Load Room: Room %d" %(neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3723.                                        
  3724.                                         # Now reenter the chest room
  3725.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3726.                                         action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3727.                                        
  3728.                                         ##### Now check for chests/deku guards
  3729.                                        
  3730.                                         chest_guard_list = []
  3731.                                        
  3732.                                         for entry in Heap_Copy_2:
  3733.                                            
  3734.                                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3735.                                                 chest_guard_list.append(entry)
  3736.                                        
  3737.                                         soln_found = False
  3738.                                         for entry in chest_guard_list:
  3739.                                             if (pot.address - entry.address) in Offset_List:
  3740.                                                
  3741.                                                 action_list010.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3742.                                                
  3743.                                                 if (pot.address - entry.address) == 0x160:
  3744.                                                     angle_solution_count += 1
  3745.                                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3746.                                                 elif (pot.address - entry.address) == 0x1F0:
  3747.                                                     position_solution_count += 1
  3748.                                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3749.                                
  3750.                                                 soln_found = True
  3751.                                                
  3752.                                         if soln_found is True:
  3753.                                             total_action_list = action_list + action_list_transition + action_list010
  3754.                                            
  3755.                                             # the "a" argument is important so we don't overwrite previous solutions
  3756.                                             with open(filename, "a") as file:
  3757.                                                
  3758.                                                 for action in total_action_list:
  3759.                                                    
  3760.                                                     file.write(action + "\n")
  3761.                                                 file.write("-----\n")
  3762.  
  3763.  
  3764.  
  3765.                                     #### Bomb and Smoke are both unloaded
  3766.                                     elif Grabbable_Dict[pot][0][2] == '1':
  3767.  
  3768.                                         action_list001 = []
  3769.                                        
  3770.                                         # COPY STATE
  3771.                                         #######################################################
  3772.                                         Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  3773.                                         Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3774.                                        
  3775.                                         room_copy_dict_2 = {}
  3776.                                         for room in Room_List_Copy_2:
  3777.                                             room_copy_dict_2[room.number] = room
  3778.                                        
  3779.                                         Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3780.                                        
  3781.                                         Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  3782.                                         #######################################################
  3783.                                        
  3784.                                         # Do not allocate anything
  3785.                                         action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  3786.                                        
  3787.                                         # The room we superslide into through the plane corresponding to the given pot
  3788.                                         destination_room = Current_Room([neighbor, Grabbable_Dict[pot][1]], Room_List)
  3789.                                        
  3790.                                         destination_room_copy = room_copy_dict_2[destination_room.number]
  3791.                                         neighbor_copy_2 = room_copy_dict_2[neighbor_copy.number]
  3792.                                        
  3793.                                         pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  3794.                                         superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  3795.                                        
  3796.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3797.                                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3798.                                        
  3799.                                         # Now exit the chest room
  3800.                                         Load_Room(Heap_Copy_2, neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  3801.                                         action_list001.append("Load Room: Room %d" %(neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3802.                                        
  3803.                                         # Now reenter the chest room
  3804.                                         Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  3805.                                         action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3806.                                        
  3807.                                         ##### Now check for chests/deku guards
  3808.                                        
  3809.                                         chest_guard_list = []
  3810.                                        
  3811.                                         for entry in Heap_Copy_2:
  3812.                                            
  3813.                                             if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3814.                                                 chest_guard_list.append(entry)
  3815.                                        
  3816.                                         soln_found = False
  3817.                                         for entry in chest_guard_list:
  3818.                                             if (pot.address - entry.address) in Offset_List:
  3819.                                                
  3820.                                                 action_list001.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3821.                                                
  3822.                                                 if (pot.address - entry.address) == 0x160:
  3823.                                                     angle_solution_count += 1
  3824.                                                     print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3825.                                                 elif (pot.address - entry.address) == 0x1F0:
  3826.                                                     position_solution_count += 1
  3827.                                                     print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3828.                                
  3829.                                                 soln_found = True
  3830.                                                
  3831.                                         if soln_found is True:
  3832.                                             total_action_list = action_list + action_list_transition + action_list001
  3833.                                            
  3834.                                             # the "a" argument is important so we don't overwrite previous solutions
  3835.                                             with open(filename, "a") as file:
  3836.                                                
  3837.                                                 for action in total_action_list:
  3838.                                                    
  3839.                                                     file.write(action + "\n")
  3840.                                                 file.write("-----\n")
  3841.                                        
  3842.  
  3843.                     ##### No valid grabbable actor in neighbor
  3844.                     elif neighbor not in valid_grabbable_actor_room_list:
  3845.                        
  3846.                         for new_neighbor in Neighbors(neighbor, Room_List):
  3847.                            
  3848.                             # if new neighbor has a valid grabbable actor... (Otherwise, we do nothing)
  3849.                             if new_neighbor in valid_grabbable_actor_room_list:
  3850.                                
  3851.                                 ##### Iterate through all pots in this room
  3852.                                
  3853.                                 valid_pot_list = []
  3854.                                 pot_address_list = []
  3855.                                
  3856.                                 for pot in Grabbable_Dict:
  3857.                                    
  3858.                                     if Actor_Is_In_Room(new_neighbor, pot) is True:
  3859.                                         valid_pot_list.append(pot)
  3860.                                         pot_address_list.append(pot.address)
  3861.                                
  3862.                                 for neighbor_transition in Shared_Transitions(current_room, neighbor):
  3863.                                     for new_neighbor_transition in Shared_Transitions(neighbor, new_neighbor):
  3864.                                        
  3865.                                         action_list_transition = []
  3866.                                
  3867.                                         ##### COPY THE STATE
  3868.                                         #######################################################
  3869.                                         Room_List_Copy = Copy_Room_List(Room_List)
  3870.                                         Overlay_Dict_Copy = Copy_Overlay_Dict(Overlay_Dict)
  3871.                                        
  3872.                                         room_copy_dict = {}
  3873.                                         for room in Room_List_Copy:
  3874.                                             room_copy_dict[room.number] = room
  3875.                                        
  3876.                                         Heap_Copy = Copy_Heap(Heap, Room_List_Copy, Overlay_Dict_Copy)
  3877.                                        
  3878.                                         Grabbable_Dict_Copy = Copy_Grabbable_Dict(Grabbable_Dict, Room_List_Copy)
  3879.                                         #######################################################
  3880.                                        
  3881.                                         neighbor_copy = room_copy_dict[neighbor.number]
  3882.                                         neighbor_transition_copy = Find_Actor_Copy(neighbor_transition, Room_List_Copy)
  3883.                                        
  3884.                                         new_neighbor_copy = room_copy_dict[new_neighbor.number]
  3885.                                         new_neighbor_transition_copy = Find_Actor_Copy(new_neighbor_transition, Room_List_Copy)
  3886.                                                                        
  3887.                                         ##### ENTER neighbor
  3888.                                        
  3889.                                         Load_Room(Heap_Copy, neighbor_copy, neighbor_transition_copy, Overlay_Dict_Copy)
  3890.                                         action_list_transition.append("Load Room: Room %d" %(neighbor_copy.number) + " with " + neighbor_transition_copy.name + " %d" %(neighbor_transition_copy.priority))
  3891.                                        
  3892.                                         ##### ENTER new_neighbor
  3893.                                        
  3894.                                         Load_Room(Heap_Copy, new_neighbor_copy, new_neighbor_transition_copy, Overlay_Dict_Copy)
  3895.                                         action_list_transition.append("Load Room: Room %d" %(new_neighbor_copy.number) + " with " + new_neighbor_transition_copy.name + " %d" %(new_neighbor_transition_copy.priority))
  3896.  
  3897.                                            
  3898.                                         # If there is a chest/guard, superslide, then check neighbors for chests/guards and test all (copy state)
  3899.                                         if Chest_In_Room(new_neighbor) == True or Deku_Guard_In_Room(new_neighbor) == True:
  3900.                                            
  3901.                                             for pot in valid_pot_list:
  3902.                                                
  3903.                                                 # both bomb and smoke loaded on superslide
  3904.                                                 if Grabbable_Dict[pot][0][0] == '1':
  3905.                                                    
  3906.                                                     action_list100 = []
  3907.                                                    
  3908.                                                     # COPY STATE
  3909.                                                     #######################################################
  3910.                                                     Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  3911.                                                     Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  3912.                                                    
  3913.                                                     room_copy_dict_SS = {}
  3914.                                                     for room in Room_List_Copy_SS:
  3915.                                                         room_copy_dict_SS[room.number] = room
  3916.                                                    
  3917.                                                     Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  3918.                                                    
  3919.                                                     Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  3920.                                                     #######################################################
  3921.                                                    
  3922.                                                     Bomb_And_Smoke_Superslide(Heap_Copy_SS, new_neighbor.number, Overlay_Dict_Copy_SS)
  3923.                                                     action_list100.append("Superslide with Bomb and Smoke still allocated")
  3924.                                                    
  3925.                                                     # The room we superslide into through the plane corresponding to the given pot
  3926.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  3927.                                                    
  3928.                                                     destination_room_copy = room_copy_dict_SS[destination_room.number]
  3929.                                                    
  3930.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  3931.                                                     superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  3932.                                                    
  3933.                                                     Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  3934.                                                     action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  3935.                                                    
  3936.                                                     """
  3937.                                                    
  3938.                                                    Now we check all neighbors of our current room (destination_room) and for
  3939.                                                    each neighbor that has a chest or deku guard in it, we will create a copy
  3940.                                                    of our copy of the state, then enter each of them through each possible
  3941.                                                    loading plane and then check the chest/guard addresses and see if anything
  3942.                                                    lines up
  3943.                                                    
  3944.                                                    """
  3945.                                                    
  3946.                                                     for bordering_room in Neighbors(destination_room, Room_List):
  3947.                                                        
  3948.                                                         if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  3949.                                                            
  3950.                                                             for loading_plane in Shared_Transitions(destination_room, bordering_room):
  3951.                                                                
  3952.                                                                  # COPY STATE
  3953.                                                                 #######################################################
  3954.                                                                 Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  3955.                                                                 Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  3956.                                                                
  3957.                                                                 room_copy_dict_2 = {}
  3958.                                                                 for room in Room_List_Copy_2:
  3959.                                                                     room_copy_dict_2[room.number] = room
  3960.                                                                
  3961.                                                                 Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  3962.                                                                
  3963.                                                                 Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  3964.                                                                 #######################################################
  3965.                                                                
  3966.                                                                 action_list_2 = []
  3967.                                                                
  3968.                                                                 loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  3969.                                                                
  3970.                                                                 bordering_room_copy = room_copy_dict_2[bordering_room.number]
  3971.                                                                
  3972.                                                                 Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  3973.                                                                 action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  3974.                                                                
  3975.                                                                
  3976.                                                                 ##### Now check for chests/deku guards
  3977.                                                    
  3978.                                                                 chest_guard_list = []
  3979.                                                                
  3980.                                                                 for entry in Heap_Copy_2:
  3981.                                                                    
  3982.                                                                     if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  3983.                                                                         chest_guard_list.append(entry)
  3984.                                                                
  3985.                                                                 soln_found = False
  3986.                                                                 for entry in chest_guard_list:
  3987.                                                                     if (pot.address - entry.address) in Offset_List:
  3988.                                                                        
  3989.                                                                         action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  3990.                                                                        
  3991.                                                                         if (pot.address - entry.address) == 0x160:
  3992.                                                                             angle_solution_count += 1
  3993.                                                                             print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3994.                                                                         elif (pot.address - entry.address) == 0x1F0:
  3995.                                                                             position_solution_count += 1
  3996.                                                                             print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  3997.                                
  3998.                                                                         soln_found = True
  3999.                                                                        
  4000.                                                                 if soln_found is True:
  4001.                                                                     total_action_list = action_list + action_list_transition + action_list100 + action_list_2
  4002.                                                                    
  4003.                                                                     # the "a" argument is important so we don't overwrite previous solutions
  4004.                                                                     with open(filename, "a") as file:
  4005.                                                                        
  4006.                                                                         for action in total_action_list:
  4007.                                                                            
  4008.                                                                             file.write(action + "\n")
  4009.                                                                         file.write("-----\n")
  4010.                                                
  4011.                                                    
  4012.                                                    
  4013.                                                 ##### Only smoke is loaded from superslide
  4014.                                                 elif Grabbable_Dict[pot][0][1] == '1':
  4015.                                                    
  4016.                                                     action_list010 = []
  4017.                                                    
  4018.                                                     # COPY STATE
  4019.                                                     #######################################################
  4020.                                                     Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  4021.                                                     Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  4022.                                                    
  4023.                                                     room_copy_dict_SS = {}
  4024.                                                     for room in Room_List_Copy_SS:
  4025.                                                         room_copy_dict_SS[room.number] = room
  4026.                                                    
  4027.                                                     Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  4028.                                                    
  4029.                                                     Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  4030.                                                     #######################################################
  4031.                                                    
  4032.                                                     Allocate_Smoke(Heap_Copy_SS, new_neighbor.number, Overlay_Dict_Copy_SS)
  4033.                                                     action_list010.append("Superslide with Smoke still allocated")
  4034.                                                    
  4035.                                                     # The room we superslide into through the plane corresponding to the given pot
  4036.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  4037.                                                    
  4038.                                                     destination_room_copy = room_copy_dict_SS[destination_room.number]
  4039.                                                    
  4040.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  4041.                                                     superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  4042.                                                    
  4043.                                                     Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  4044.                                                     action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4045.                                                    
  4046.                                                     """
  4047.                                                    
  4048.                                                    Now we check all neighbors of our current room (destination_room) and for
  4049.                                                    each neighbor that has a chest or deku guard in it, we will create a copy
  4050.                                                    of our copy of the state, then enter each of them through each possible
  4051.                                                    loading plane and then check the chest/guard addresses and see if anything
  4052.                                                    lines up
  4053.                                                    
  4054.                                                    """
  4055.                                                    
  4056.                                                     for bordering_room in Neighbors(destination_room, Room_List):
  4057.                                                        
  4058.                                                         if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  4059.                                                            
  4060.                                                             for loading_plane in Shared_Transitions(destination_room, bordering_room):
  4061.                                                                
  4062.                                                                  # COPY STATE
  4063.                                                                 #######################################################
  4064.                                                                 Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  4065.                                                                 Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  4066.                                                                
  4067.                                                                 room_copy_dict_2 = {}
  4068.                                                                 for room in Room_List_Copy_2:
  4069.                                                                     room_copy_dict_2[room.number] = room
  4070.                                                                
  4071.                                                                 Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  4072.                                                                
  4073.                                                                 Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  4074.                                                                 #######################################################
  4075.                                                                
  4076.                                                                 action_list_2 = []
  4077.                                                                
  4078.                                                                 loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  4079.                                                                
  4080.                                                                 bordering_room_copy = room_copy_dict_2[bordering_room.number]
  4081.                                                                
  4082.                                                                 Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  4083.                                                                 action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  4084.                                                                
  4085.                                                                
  4086.                                                                 ##### Now check for chests/deku guards
  4087.                                                    
  4088.                                                                 chest_guard_list = []
  4089.                                                                
  4090.                                                                 for entry in Heap_Copy_2:
  4091.                                                                    
  4092.                                                                     if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  4093.                                                                         chest_guard_list.append(entry)
  4094.                                                                
  4095.                                                                 soln_found = False
  4096.                                                                 for entry in chest_guard_list:
  4097.                                                                     if (pot.address - entry.address) in Offset_List:
  4098.                                                                        
  4099.                                                                         action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  4100.                                                                        
  4101.                                                                         if (pot.address - entry.address) == 0x160:
  4102.                                                                             angle_solution_count += 1
  4103.                                                                             print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4104.                                                                         elif (pot.address - entry.address) == 0x1F0:
  4105.                                                                             position_solution_count += 1
  4106.                                                                             print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4107.                                
  4108.                                                                         soln_found = True
  4109.                                                                        
  4110.                                                                 if soln_found is True:
  4111.                                                                     total_action_list = action_list + action_list_transition + action_list010 + action_list_2
  4112.                                                                    
  4113.                                                                     # the "a" argument is important so we don't overwrite previous solutions
  4114.                                                                     with open(filename, "a") as file:
  4115.                                                                        
  4116.                                                                         for action in total_action_list:
  4117.                                                                            
  4118.                                                                             file.write(action + "\n")
  4119.                                                                         file.write("-----\n")
  4120.            
  4121.            
  4122.                                                 #### Bomb and Smoke are both unloaded
  4123.                                                 elif Grabbable_Dict[pot][0][2] == '1':
  4124.                                                    
  4125.                                                     action_list001 = []
  4126.                                                    
  4127.                                                     # COPY STATE
  4128.                                                     #######################################################
  4129.                                                     Room_List_Copy_SS = Copy_Room_List(Room_List_Copy)
  4130.                                                     Overlay_Dict_Copy_SS = Copy_Overlay_Dict(Overlay_Dict_Copy)
  4131.                                                    
  4132.                                                     room_copy_dict_SS = {}
  4133.                                                     for room in Room_List_Copy_SS:
  4134.                                                         room_copy_dict_SS[room.number] = room
  4135.                                                    
  4136.                                                     Heap_Copy_SS = Copy_Heap(Heap_Copy, Room_List_Copy_SS, Overlay_Dict_Copy_SS)
  4137.                                                    
  4138.                                                     Grabbable_Dict_Copy_SS = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_SS)
  4139.                                                     #######################################################
  4140.                                                    
  4141.                                                     # Do not allocate anything
  4142.                                                     action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  4143.                                                    
  4144.                                                     # The room we superslide into through the plane corresponding to the given pot
  4145.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  4146.                                                    
  4147.                                                     destination_room_copy = room_copy_dict_SS[destination_room.number]
  4148.                                                    
  4149.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_SS)
  4150.                                                     superslide_transition_copy = Grabbable_Dict_Copy_SS[pot_copy][1]
  4151.                                                    
  4152.                                                     Load_Room(Heap_Copy_SS, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_SS)
  4153.                                                     action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4154.                                                    
  4155.                                                     """
  4156.                                                    
  4157.                                                    Now we check all neighbors of our current room (destination_room) and for
  4158.                                                    each neighbor that has a chest or deku guard in it, we will create a copy
  4159.                                                    of our copy of the state, then enter each of them through each possible
  4160.                                                    loading plane and then check the chest/guard addresses and see if anything
  4161.                                                    lines up
  4162.                                                    
  4163.                                                    """
  4164.                                                    
  4165.                                                     for bordering_room in Neighbors(destination_room, Room_List):
  4166.                                                        
  4167.                                                         if Chest_In_Room(bordering_room) == True or Deku_Guard_In_Room(bordering_room) == True:
  4168.                                                            
  4169.                                                             for loading_plane in Shared_Transitions(destination_room, bordering_room):
  4170.                                                                
  4171.                                                                  # COPY STATE
  4172.                                                                 #######################################################
  4173.                                                                 Room_List_Copy_2 = Copy_Room_List(Room_List_Copy_SS)
  4174.                                                                 Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy_SS)
  4175.                                                                
  4176.                                                                 room_copy_dict_2 = {}
  4177.                                                                 for room in Room_List_Copy_2:
  4178.                                                                     room_copy_dict_2[room.number] = room
  4179.                                                                
  4180.                                                                 Heap_Copy_2 = Copy_Heap(Heap_Copy_SS, Room_List_Copy_2, Overlay_Dict_Copy_2)
  4181.                                                                
  4182.                                                                 Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy_SS, Room_List_Copy_2)
  4183.                                                                 #######################################################
  4184.                                                                
  4185.                                                                 action_list_2 = []
  4186.                                                                
  4187.                                                                 loading_plane_copy = Find_Actor_Copy(loading_plane, Room_List_Copy_2)
  4188.                                                                
  4189.                                                                 bordering_room_copy = room_copy_dict_2[bordering_room.number]
  4190.                                                                
  4191.                                                                 Load_Room(Heap_Copy_2, bordering_room_copy, loading_plane_copy, Overlay_Dict_Copy_2)
  4192.                                                                 action_list_2.append("Load Room: Room %d" %(bordering_room_copy.number) + " with " + loading_plane_copy.name + " %d" %(loading_plane_copy.priority))
  4193.                                                                
  4194.                                                                
  4195.                                                                 ##### Now check for chests/deku guards
  4196.                                                    
  4197.                                                                 chest_guard_list = []
  4198.                                                                
  4199.                                                                 for entry in Heap_Copy_2:
  4200.                                                                    
  4201.                                                                     if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  4202.                                                                         chest_guard_list.append(entry)
  4203.                                                                
  4204.                                                                 soln_found = False
  4205.                                                                 for entry in chest_guard_list:
  4206.                                                                     if (pot.address - entry.address) in Offset_List:
  4207.                                                                        
  4208.                                                                         action_list_2.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  4209.                                                                        
  4210.                                                                         if (pot.address - entry.address) == 0x160:
  4211.                                                                             angle_solution_count += 1
  4212.                                                                             print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4213.                                                                         elif (pot.address - entry.address) == 0x1F0:
  4214.                                                                             position_solution_count += 1
  4215.                                                                             print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4216.                                
  4217.                                                                         soln_found = True
  4218.                                                                        
  4219.                                                                 if soln_found is True:
  4220.                                                                     total_action_list = action_list + action_list_transition + action_list001 + action_list_2
  4221.                                                                    
  4222.                                                                     # the "a" argument is important so we don't overwrite previous solutions
  4223.                                                                     with open(filename, "a") as file:
  4224.                                                                        
  4225.                                                                         for action in total_action_list:
  4226.                                                                            
  4227.                                                                             file.write(action + "\n")
  4228.                                                                         file.write("-----\n")
  4229.                                                
  4230.                                                
  4231.                                                
  4232.                                         # If there isn't a chest/guard, superslide (into chest/guard room by assumption), then exit then reenter it (this case never happens in palace, so this is an okay assumption)
  4233.                                         elif Chest_In_Room(new_neighbor) == False and Deku_Guard_In_Room(new_neighbor) == False:
  4234.                                            
  4235.                                             for pot in valid_pot_list:
  4236.                                                
  4237.                                                 # both bomb and smoke loaded on superslide
  4238.                                                 if Grabbable_Dict[pot][0][0] == '1':
  4239.                                                    
  4240.                                                     action_list100 = []
  4241.                                                    
  4242.                                                     # COPY STATE
  4243.                                                     #######################################################
  4244.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  4245.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  4246.                                                    
  4247.                                                     room_copy_dict_2 = {}
  4248.                                                     for room in Room_List_Copy_2:
  4249.                                                         room_copy_dict_2[room.number] = room
  4250.                                                    
  4251.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  4252.                                                    
  4253.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  4254.                                                     #######################################################
  4255.                                                    
  4256.                                                     Bomb_And_Smoke_Superslide(Heap_Copy_2, new_neighbor_copy.number, Overlay_Dict_Copy_2)
  4257.                                                     action_list100.append("Superslide with Bomb and Smoke still allocated")
  4258.                                                    
  4259.                                                     # The room we superslide into through the plane corresponding to the given pot
  4260.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  4261.                                                    
  4262.                                                     destination_room_copy = room_copy_dict_2[destination_room.number]
  4263.                                                     new_neighbor_copy_2 = room_copy_dict_2[new_neighbor_copy.number]
  4264.                                                    
  4265.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  4266.                                                     superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  4267.                                                    
  4268.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4269.                                                     action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4270.                                                    
  4271.                                                     # Now exit the chest room
  4272.                                                     Load_Room(Heap_Copy_2, new_neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  4273.                                                     action_list100.append("Load Room: Room %d" %(new_neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4274.                                                    
  4275.                                                     # Now reenter the chest room
  4276.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4277.                                                     action_list100.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4278.                                                    
  4279.                                                     ##### Now check for chests/deku guards
  4280.                                                    
  4281.                                                     chest_guard_list = []
  4282.                                                    
  4283.                                                     for entry in Heap_Copy_2:
  4284.                                                        
  4285.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  4286.                                                             chest_guard_list.append(entry)
  4287.                                                    
  4288.                                                     soln_found = False
  4289.                                                     for entry in chest_guard_list:
  4290.                                                         if (pot.address - entry.address) in Offset_List:
  4291.                                                            
  4292.                                                             action_list100.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  4293.                                                            
  4294.                                                             if (pot.address - entry.address) == 0x160:
  4295.                                                                 angle_solution_count += 1
  4296.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4297.                                                             elif (pot.address - entry.address) == 0x1F0:
  4298.                                                                 position_solution_count += 1
  4299.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4300.                                
  4301.                                                             soln_found = True
  4302.                                                            
  4303.                                                     if soln_found is True:
  4304.                                                         total_action_list = action_list + action_list_transition + action_list100
  4305.                                                        
  4306.                                                         # the "a" argument is important so we don't overwrite previous solutions
  4307.                                                         with open(filename, "a") as file:
  4308.                                                            
  4309.                                                             for action in total_action_list:
  4310.                                                                
  4311.                                                                 file.write(action + "\n")
  4312.                                                             file.write("-----\n")
  4313.                                                
  4314.                                                
  4315.                                                
  4316.                                                 ##### Only smoke is loaded from superslide
  4317.                                                 elif Grabbable_Dict[pot][0][1] == '1':
  4318.            
  4319.                                                     action_list010 = []
  4320.                                                    
  4321.                                                     # COPY STATE
  4322.                                                     #######################################################
  4323.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  4324.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  4325.                                                    
  4326.                                                     room_copy_dict_2 = {}
  4327.                                                     for room in Room_List_Copy_2:
  4328.                                                         room_copy_dict_2[room.number] = room
  4329.                                                    
  4330.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  4331.                                                    
  4332.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  4333.                                                     #######################################################
  4334.                                                    
  4335.                                                     Allocate_Smoke(Heap_Copy_2, new_neighbor_copy.number, Overlay_Dict_Copy_2)
  4336.                                                     action_list010.append("Superslide with Smoke still allocated")
  4337.                                                    
  4338.                                                     # The room we superslide into through the plane corresponding to the given pot
  4339.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  4340.                                                    
  4341.                                                     destination_room_copy = room_copy_dict_2[destination_room.number]
  4342.                                                     new_neighbor_copy_2 = room_copy_dict_2[new_neighbor_copy.number]
  4343.                                                    
  4344.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  4345.                                                     superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  4346.                                                    
  4347.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4348.                                                     action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4349.                                                    
  4350.                                                     # Now exit the chest room
  4351.                                                     Load_Room(Heap_Copy_2, new_neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  4352.                                                     action_list010.append("Load Room: Room %d" %(new_neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4353.                                                    
  4354.                                                     # Now reenter the chest room
  4355.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4356.                                                     action_list010.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4357.                                                    
  4358.                                                     ##### Now check for chests/deku guards
  4359.                                                    
  4360.                                                     chest_guard_list = []
  4361.                                                    
  4362.                                                     for entry in Heap_Copy_2:
  4363.                                                        
  4364.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  4365.                                                             chest_guard_list.append(entry)
  4366.                                                    
  4367.                                                     soln_found = False
  4368.                                                     for entry in chest_guard_list:
  4369.                                                         if (pot.address - entry.address) in Offset_List:
  4370.                                                            
  4371.                                                             action_list010.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  4372.                                                            
  4373.                                                             if (pot.address - entry.address) == 0x160:
  4374.                                                                 angle_solution_count += 1
  4375.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4376.                                                             elif (pot.address - entry.address) == 0x1F0:
  4377.                                                                 position_solution_count += 1
  4378.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4379.                                
  4380.                                                             soln_found = True
  4381.                                                            
  4382.                                                     if soln_found is True:
  4383.                                                         total_action_list = action_list + action_list_transition + action_list010
  4384.                                                        
  4385.                                                         # the "a" argument is important so we don't overwrite previous solutions
  4386.                                                         with open(filename, "a") as file:
  4387.                                                            
  4388.                                                             for action in total_action_list:
  4389.                                                                
  4390.                                                                 file.write(action + "\n")
  4391.                                                             file.write("-----\n")
  4392.            
  4393.            
  4394.            
  4395.                                                 #### Bomb and Smoke are both unloaded
  4396.                                                 elif Grabbable_Dict[pot][0][2] == '1':
  4397.            
  4398.                                                     action_list001 = []
  4399.                                                    
  4400.                                                     # COPY STATE
  4401.                                                     #######################################################
  4402.                                                     Room_List_Copy_2 = Copy_Room_List(Room_List_Copy)
  4403.                                                     Overlay_Dict_Copy_2 = Copy_Overlay_Dict(Overlay_Dict_Copy)
  4404.                                                    
  4405.                                                     room_copy_dict_2 = {}
  4406.                                                     for room in Room_List_Copy_2:
  4407.                                                         room_copy_dict_2[room.number] = room
  4408.                                                    
  4409.                                                     Heap_Copy_2 = Copy_Heap(Heap_Copy, Room_List_Copy_2, Overlay_Dict_Copy_2)
  4410.                                                    
  4411.                                                     Grabbable_Dict_Copy_2 = Copy_Grabbable_Dict(Grabbable_Dict_Copy, Room_List_Copy_2)
  4412.                                                     #######################################################
  4413.                                                    
  4414.                                                     # Do not allocate anything
  4415.                                                     action_list001.append("Superslide with Bomb and Smoke unloaded when passing plane")
  4416.                                                    
  4417.                                                     # The room we superslide into through the plane corresponding to the given pot
  4418.                                                     destination_room = Current_Room([new_neighbor, Grabbable_Dict[pot][1]], Room_List)
  4419.                                                    
  4420.                                                     destination_room_copy = room_copy_dict_2[destination_room.number]
  4421.                                                     new_neighbor_copy_2 = room_copy_dict_2[new_neighbor_copy.number]
  4422.                                                    
  4423.                                                     pot_copy = Find_Actor_Copy(pot, Room_List_Copy_2)
  4424.                                                     superslide_transition_copy = Grabbable_Dict_Copy_2[pot_copy][1]
  4425.                                                    
  4426.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4427.                                                     action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4428.                                                    
  4429.                                                     # Now exit the chest room
  4430.                                                     Load_Room(Heap_Copy_2, new_neighbor_copy_2, superslide_transition_copy, Overlay_Dict_Copy_2)
  4431.                                                     action_list001.append("Load Room: Room %d" %(new_neighbor_copy_2.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4432.                                                    
  4433.                                                     # Now reenter the chest room
  4434.                                                     Load_Room(Heap_Copy_2, destination_room_copy, superslide_transition_copy, Overlay_Dict_Copy_2)
  4435.                                                     action_list001.append("Load Room: Room %d" %(destination_room_copy.number) + " with " + superslide_transition_copy.name + " %d" %(superslide_transition_copy.priority))
  4436.                                                    
  4437.                                                     ##### Now check for chests/deku guards
  4438.                                                    
  4439.                                                     chest_guard_list = []
  4440.                                                    
  4441.                                                     for entry in Heap_Copy_2:
  4442.                                                        
  4443.                                                         if type(entry) == Actor and (entry.Id == '0006' or entry.Id == '017A'):
  4444.                                                             chest_guard_list.append(entry)
  4445.                                                    
  4446.                                                     soln_found = False
  4447.                                                     for entry in chest_guard_list:
  4448.                                                         if (pot.address - entry.address) in Offset_List:
  4449.                                                            
  4450.                                                             action_list001.append("SOLUTION: " + pot.name + " (Priority %d)" %(pot.priority) + " from Room %d" %(pot.room_number) + " lines up with " + entry.name + " (Priority %d)" %(entry.priority) + " from Room %d" %(entry.room_number) + " with offset: " + hex(pot.address - entry.address))
  4451.                                                            
  4452.                                                             if (pot.address - entry.address) == 0x160:
  4453.                                                                 angle_solution_count += 1
  4454.                                                                 print("ANGLE SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4455.                                                             elif (pot.address - entry.address) == 0x1F0:
  4456.                                                                 position_solution_count += 1
  4457.                                                                 print("Z POSITION SOLUTION FOUND (CHEST)!!!!!!!!!!!")
  4458.                                
  4459.                                                             soln_found = True
  4460.                                                            
  4461.                                                     if soln_found is True:
  4462.                                                         total_action_list = action_list + action_list_transition + action_list001
  4463.                                                        
  4464.                                                         # the "a" argument is important so we don't overwrite previous solutions
  4465.                                                         with open(filename, "a") as file:
  4466.                                                            
  4467.                                                             for action in total_action_list:
  4468.                                                                
  4469.                                                                 file.write(action + "\n")
  4470.                                                             file.write("-----\n")
  4471.                                    
  4472.  
  4473.  
  4474.  
  4475. ###############################################################################
  4476. ###############################################################################
  4477. ###############################################################################
  4478. ###############################################################################
  4479. ###############################################################################
  4480. ###############################################################################
  4481. ###############################################################################
  4482. ###############################################################################
  4483. ###############################################################################
  4484. ###############################################################################
  4485. ###############################################################################
  4486. ###############################################################################
  4487. ###############################################################################
  4488. ###############################################################################
  4489. ###############################################################################
  4490. ###############################################################################
  4491. ###############################################################################
  4492. ###############################################################################
  4493. ###############################################################################
  4494. ###############################################################################
  4495. ###############################################################################
  4496. ###############################################################################
  4497. ###############################################################################
  4498. ###############################################################################
  4499. ###############################################################################
  4500. ###############################################################################
  4501. ###############################################################################
  4502. ###############################################################################
  4503. ###############################################################################
  4504. ###############################################################################
  4505. ###############################################################################
  4506. ###############################################################################
  4507. ###############################################################################
  4508. ###############################################################################
  4509. ###############################################################################
  4510. ###############################################################################
  4511. ###############################################################################
  4512. ###############################################################################
  4513. ###############################################################################
  4514. ###############################################################################
  4515. ###############################################################################
  4516. ###############################################################################
  4517. ###############################################################################
  4518. ###############################################################################
  4519. ###############################################################################
  4520. ###############################################################################
  4521. ###############################################################################
  4522. ###############################################################################
  4523.  
  4524. Hardcoded_Allocation_List_2 = [
  4525.         'Smoke',
  4526.         'Smoke',
  4527.         'Smoke',
  4528.         'Arrow',
  4529.         'Arrow',
  4530.         'Arrow',
  4531.         'Arrow',
  4532.         'Arrow',
  4533.         'Bomb',
  4534.         'Bomb',
  4535.         'Bomb',
  4536.         'Hookshot',
  4537.         'Charged Spin Attack'
  4538.         ]
  4539.  
  4540.  
  4541.  
  4542. save_path = insert path of: "srm solver test1.txt" here
  4543. name_of_file = "srm solver test1"
  4544. complete_name = save_path + name_of_file + ".txt"  
  4545.  
  4546. Heap = [Node(0x40B140, node_size), Node(0x5FFFFF, node_size)]
  4547.  
  4548. Randomized_Solver(Room0, Room_List, 10, Hardcoded_Allocation_List_2, Grabbable_dict, Overlay_dict, complete_name, [0x160, 0x1F0], Heap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement