<commit_before>
module DoorRandomizer
  def randomize_transition_doors
    @transition_rooms = game.get_transition_rooms()
    @transition_rooms.reject! do |room|
      FAKE_TRANSITION_ROOMS.include?(room.room_metadata_ram_pointer)
    end
    
    queued_door_changes = Hash.new{|h, k| h[k] = {}}
    
    game.areas.each do |area|
      all_area_transition_rooms = @transition_rooms.select do |transition_room|
        transition_room.area_index == area.area_index
      end
      
      if all_area_transition_rooms.size <= 2
        # Not enough transition rooms in this area to properly randomize it. Need at least 3.
        next
      end
      
      all_area_subsectors = []
      area.sectors.each do |sector|
        all_area_subsectors += get_subsectors(sector, include_transitions: true)
      end
      
      remaining_transitions = {
        left: [],
        right: [],
      }
      
      other_transitions_in_same_subsector = {}
      accessible_unused_transitions = []
      transition_doors_by_subsector = Array.new(all_area_subsectors.size){ [] }
      
      starting_transition = nil
      
      # First we make a list of the transition doors, specifically the left door in a transition room, and the right door that leads into that transition room.
      all_area_transition_rooms.each do |transition_room|
        if transition_room.room_str == "00-0A-00"
          # The transition room connecting the Library to the blocked off entrance of Final Approach.
          # Don't randomize this connection, since it could result in progression being impossible.
          next
        end
        transition_door = transition_room.doors.find{|door| door.direction == :left}
        dest_door = transition_door.destination_door
        remaining_transitions[transition_door.direction] << transition_door
        remaining_transitions[dest_door.direction] << dest_door
      end
      
      # Then we go through each transition door and keep track of what subsector it's located in.
      remaining_transitions.values.flatten.each do |transition_door|
        if transition_door.direction == :right
          # The door leading right into a transition room.
          # This is part of the sector proper, so we just use this room itself to detect the proper subsector.
          room_in_desired_subsector = transition_door.room
        else
          # The door leading left out of the transition room.
          # We want the subsector to the right. But since this is in the transition room, we have no idea what subsector the transition room itself is in.
          # So follow the right door out of the transition room, and use the room there to detect the proper subsector.
          room_in_desired_subsector = transition_door.room.doors.find{|d| d.direction == :right}.destination_room
        end
        all_area_subsectors.each_with_index do |subsector_rooms, subsector_index|<commit_msg>Area rando: Don't touch any of the final approach connections<commit_after>
module DoorRandomizer
  def randomize_transition_doors
    @transition_rooms = game.get_transition_rooms()
    @transition_rooms.reject! do |room|
      FAKE_TRANSITION_ROOMS.include?(room.room_metadata_ram_pointer)
    end
    
    queued_door_changes = Hash.new{|h, k| h[k] = {}}
    
    game.areas.each do |area|
      all_area_transition_rooms = @transition_rooms.select do |transition_room|
        transition_room.area_index == area.area_index
      end
      
      if all_area_transition_rooms.size <= 2
        # Not enough transition rooms in this area to properly randomize it. Need at least 3.
        next
      end
      
      all_area_subsectors = []
      area.sectors.each do |sector|
        all_area_subsectors += get_subsectors(sector, include_transitions: true)
      end
      
      remaining_transitions = {
        left: [],
        right: [],
      }
      
      other_transitions_in_same_subsector = {}
      accessible_unused_transitions = []
      transition_doors_by_subsector = Array.new(all_area_subsectors.size){ [] }
      
      starting_transition = nil
      
      # First we make a list of the transition doors, specifically the left door in a transition room, and the right door that leads into that transition room.
      all_area_transition_rooms.each do |transition_room|
        if ["00-0A-00", "00-0A-07", "00-0A-13"].include?(transition_room.room_str)
          # The transition rooms in the Final Approach.
          # Don't randomize these connections, since it could result in progression being impossible.
          next
        end
        transition_door = transition_room.doors.find{|door| door.direction == :left}
        dest_door = transition_door.destination_door
        remaining_transitions[transition_door.direction] << transition_door
        remaining_transitions[dest_door.direction] << dest_door
      end
      
      # Then we go through each transition door and keep track of what subsector it's located in.
      remaining_transitions.values.flatten.each do |transition_door|
        if transition_door.direction == :right
          # The door leading right into a transition room.
          # This is part of the sector proper, so we just use this room itself to detect the proper subsector.
          room_in_desired_subsector = transition_door.room
        else
          # The door leading left out of the transition room.
          # We want the subsector to the right. But since this is in the transition room, we have no idea what subsector the transition room itself is in.
          # So follow the right door out of the transition room, and use the room there to detect the proper subsector.
          room_in_desired_subsector = transition_door.room.doors.find{|d| d.direction == :right}.destination_room
        end
        all_area_subsectors.each_with_index do |subsector_rooms, subsector_index|
{'fraction_non_alphanumeric': 0.06295729113493279, 'fraction_numerical': 0.00408371618172537, 'mean_word_length': 2.8168831168831168, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1185126', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1587, 'n_words': 508}