<commit_before>module ZombieEpidemic
  class World
    def initialize(population_size = 10, map_klass = Map, agent_klass = Agent, stm_klass = StateTransitionMachine)
      @map = map_klass.new(10, 10)
      @stm = StateTransitionMachine.new
      @agents = []
      population_size.times { @agents << Agent.new(@map, @stm) }
      @time = 0
    end

    def run(steps = 24 * 3600 * 2 * 10)
      steps.times do
        @time += 1
        puts "Time: #{@time}"
        @agents.each_with_index do |agent, index|
          # puts "Agent #{index}: act"
          agent.act
          # puts "Agent #{index}: age"
          agent.age
        end
        @agents.each_with_index do |agent, index|
          # puts "Agent #{index}: commit"
          agent.commit
        end
        # puts "Delete dead agent"
        deads = @agents.delete_if { |agent| agent.state.name == :dead }
        # puts "Remove them from the map"
        deads.each { |dead| dead.position.contents = nil }
      end
    end
  end
end<commit_msg>Fix and Improvement of World Simulator<commit_after>module ZombieEpidemic
  class World
    def initialize(population_size = 10, map_klass = Map, agent_klass = Agent, stm_klass = StateTransitionMachine)
      @map = map_klass.new(10, 10)
      @stm = StateTransitionMachine.new
      @agents = []
      population_size.times { @agents << Agent.new(@map, @stm) }
      @time = 0
    end

    def run(steps = 24 * 3600 * 2 * 10)
      dirname = "zombie_epidemic_#{Time.now.utc.to_i}"
      Dir.mkdir(dirname)

      digits = steps.to_s.length

      render(dirname, digits)

      steps.times do
        @time += 1
        puts "Time: #{@time}"
        @agents.each_with_index do |agent, index|
          agent.act
          agent.age
        end
        @agents.each_with_index do |agent, index|
          agent.commit
        end
        render(dirname, digits)
        deads = @agents.select{ |agent| agent.state.name == :dead }
        @agents.reject!{ |agent| agent.state.name == :dead }
        if deads
          deads.each do |dead|
            if dead.position
              dead.position.contents = nil
              dead.position = nil
            end
          end if deads
          deads.clear
        end
      end
    end

    private
    def render(directory, digits, dpi = 10)
      map_presenter = MapPresenter.new
      file = File.join(directory, "step_%0#{digits}d.png" % @time)
      
      w = @map.width
      h = @map.height
      map_presenter
        .render(@map)
        .resize(w * dpi, h * dpi)
        .save(file, :fast_rgb)
    end
  end
end
{'fraction_non_alphanumeric': 0.1090065713181291, 'fraction_numerical': 0.014302280633938926, 'mean_word_length': 1.9111361079865017, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7561269', 'n_tokens_mistral': 866, 'n_tokens_neox': 820, 'n_words': 207}