<commit_before>class World

  def initialize(generator, feature_factory)
    raise 'Cannot create world when generator is nil' unless generator

    @world = Hash.new
    @entities = Array.new
    @width = generator.width
    @height = generator.height

    total_desks = 25

    generator.generate do |x, y, height|
      @world[key_for(x.floor, y.floor)] = tile_for_height(height)

      add_entity(feature_factory.door(x.floor, y.floor)) if height.floor == 2

      add_desk = total_desks > 0 && height.floor == 0 && rand > 0.99
      if add_desk
        add_entity(feature_factory.desk(x.floor, y.floor))
        total_desks -= 1
      end
    end
  end

  def at(x, y)
    key = key_for(x, y)
    # This is super inefficient
    found = @entities.select { |e| e.get(:position).x == x and e.get(:position).y == y }
    entity = found.first
    if entity
      return entity
    else
      return @world[key_for(x, y)]
    end
  end

  def entities
    @entities
  end

  def add_entity(entity)
    raise 'Cannot add entity that doesnt have a position' unless entity.has? :position
    @entities << entity
  end

  def width
    @width
  end

  def height
    @height
  end

  def free(x, y)
    tile = at(x, y)
    if tile.respond_to?(:has?)
      return(tile.has?(:walkable) and tile.get(:walkable).walkable)
    else
      return tile[:walkable]
    end
  end

  private
  def key_for(x, y)
    <KEY>
  end

  def tile_for_height(height)
    v = (height).floor
    t = '.'
    t = '#' if v == 1

    c = :white

    { char: t, color: c, walkable: (t == '.') }
  end

end<commit_msg>Better random placement of desks<commit_after>class World

  def initialize(generator, feature_factory)
    raise 'Cannot create world when generator is nil' unless generator

    @world = Hash.new
    @entities = Array.new
    @width = generator.width
    @height = generator.height

    total_desks = 10

    generator.generate do |x, y, height|
      @world[key_for(x.floor, y.floor)] = tile_for_height(height)

      add_entity(feature_factory.door(x.floor, y.floor)) if height.floor == 2
    end

    (0..total_desks - 1).each do |i|
      loc = random_free_location
      add_entity(feature_factory.desk(loc[:x], loc[:y]))
    end
  end

  def at(x, y)
    key = key_for(x, y)
    # This is super inefficient
    found = @entities.select { |e| e.get(:position).x == x and e.get(:position).y == y }
    entity = found.first
    if entity
      return entity
    else
      return @world[key_for(x, y)]
    end
  end

  def entities
    @entities
  end

  def add_entity(entity)
    raise 'Cannot add entity that doesnt have a position' unless entity.has? :position
    @entities << entity
  end

  def width
    @width
  end

  def height
    @height
  end

  def free(x, y)
    tile = at(x, y)
    if tile.respond_to?(:has?)
      return(tile.has?(:walkable) and tile.get(:walkable).walkable)
    else
      return tile[:walkable]
    end
  end

  private
  def key_for(x, y)
    <KEY>
  end

  def tile_for_height(height)
    v = (height).floor
    t = '.'
    t = '#' if v == 1

    c = :white

    { char: t, color: c, walkable: (t == '.') }
  end

  def random_free_location
    rx = (rand * @width).floor
    ry = (rand * @height).floor

    while !free(rx, ry)
      rx = (rand * @width).floor
      ry = (rand * @height).floor
    end

    { x: rx, y: ry }
  end


end
{'fraction_non_alphanumeric': 0.11902641733452063, 'fraction_numerical': 0.004749183734045711, 'mean_word_length': 2.4213197969543145, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '2312357', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1158, 'n_words': 333}