<commit_before>require_relative 'piece'

class Pawn < Piece

  AVATARS = { white: "WP", black: "BP"}
  
  MOVE_MAPPINGS = { white: { up_verticals:           '[ 0, x]' },
                    black: { down_verticals:         '[ 0,-x]' } }

  SPECIAL_MAPPINGS = { white: { up_left_diagonals:      '[-x, x]', 
                                up_right_diagonals:     '[ x, x]' },
                       black: { down_left_diagonals:    '[-x,-x]', 
                                down_right_diagonals:   '[ x,-x]' } }

  def initialize(board:, color:, start_pos:)
    super
    self.class.define_movement_methods(self.class::MOVE_MAPPINGS[color])
    self.class.define_movement_methods(self.class::SPECIAL_MAPPINGS[color])
  end

  def available_moves
    moves = self.class::MOVE_MAPPINGS[color].keys.inject([]) do |memo, method|
      m = all_possible_moves(eval("self.class.#{method}(2)"))
      memo += remove_occupied(m)
      toggle_first_move(memo)
    end
  end

  def special_moves
    moves = self.class::SPECIAL_MAPPINGS[color].keys.inject([]) do |memo, method|
      m = all_possible_moves(eval("self.class.#{method}(1)"))
      memo += remove_occupied(m)
    end
  end

  def toggle_first_move(moves)
    locations = reorient_locations(moves)
    locations.pop if move_count > 0 && locations.count > 1
    locations
  end

end<commit_msg>Refactor pawn to remove self.class reference for constants<commit_after>require_relative 'piece'

class Pawn < Piece

  AVATARS = { white: "WP", black: "BP"}
  
  MOVE_MAPPINGS = { white: { up_verticals:           '[ 0, x]' },
                    black: { down_verticals:         '[ 0,-x]' } }

  SPECIAL_MAPPINGS = { white: { up_left_diagonals:      '[-x, x]', 
                                up_right_diagonals:     '[ x, x]' },
                       black: { down_left_diagonals:    '[-x,-x]', 
                                down_right_diagonals:   '[ x,-x]' } }

  def initialize(board:, color:, start_pos:)
    super
    self.class.define_movement_methods(MOVE_MAPPINGS[color])
    self.class.define_movement_methods(SPECIAL_MAPPINGS[color])
  end

  def available_moves
    moves = MOVE_MAPPINGS[color].keys.inject([]) do |memo, method|
      m = all_possible_moves(eval("self.class.#{method}(2)"))
      memo += remove_occupied(m)
      toggle_first_move(memo)
    end
  end

  def special_moves
    moves = SPECIAL_MAPPINGS[color].keys.inject([]) do |memo, method|
      m = all_possible_moves(eval("self.class.#{method}(1)"))
      memo += remove_occupied(m)
    end
  end

  def toggle_first_move(moves)
    locations = reorient_locations(moves)
    locations.pop if move_count > 0 && locations.count > 1
    locations
  end

end
{'fraction_non_alphanumeric': 0.1320193380438825, 'fraction_numerical': 0.004462625511342506, 'mean_word_length': 2.5535006605019817, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3454769', 'n_tokens_mistral': 953, 'n_tokens_neox': 923, 'n_words': 164}