<commit_before>module StackWars
  class Battlefield
    SIZE = 9
    WHITE_BASELINE = 0
    BLACK_BASELINE = SIZE - 1

    def self.from_json(json_file)
      territory_data = JSON.parse(File.read(json_file))

      territories = territory_data.map.with_index do |row, y|
        row.map.with_index do |t, x|
          occupant, strength = t
          if occupant == "unclaimed"
            Territory.new([x,y])
          else
            Territory.new([x,y], :occupant      => occupant, 
                                 :army_strength => strength)
          end
        end
      end
      
      new(territories)
    end

    def initialize(territories)
      @territories = territories
    end

    def to_a
      Marshal.load(Marshal.dump(@territories))
    end

    def adjacent?(pos1, pos2)
      (pos1.row == pos2.row && (pos1.column - pos2.column).abs == 1) ||<commit_msg>Make it possible to initialize battlefield without JSON data<commit_after>module StackWars
  class Battlefield
    SIZE = 9
    WHITE_BASELINE = 0
    BLACK_BASELINE = SIZE - 1

    def self.from_json(json_file)
      territory_data = JSON.parse(File.read(json_file))

      territories = territory_data.map.with_index do |row, y|
        row.map.with_index do |t, x|
          occupant, strength = t
          if occupant == "unclaimed"
            Territory.new([x,y])
          else
            Territory.new([x,y], :occupant      => occupant, 
                                 :army_strength => strength)
          end
        end
      end
      
      new(territories)
    end

    def initialize(territories=nil)
      if territories
        @territories = territories
      else
        @territories = 
          SIZE.times.map { |y| SIZE.times.map { |x| Territory.new([x,y]) } }   
      end
    end

    def to_a
      Marshal.load(Marshal.dump(@territories))
    end

    def adjacent?(pos1, pos2)
      (pos1.row == pos2.row && (pos1.column - pos2.column).abs == 1) ||
{'fraction_non_alphanumeric': 0.10147883732789394, 'fraction_numerical': 0.010198878123406425, 'mean_word_length': 1.8642335766423357, 'pattern_counts': {'":': 0, '<': 3, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4797296', 'n_tokens_mistral': 643, 'n_tokens_neox': 612, 'n_words': 136}