def move_pawn(p1)
      col = get_col_from_index(p1)
      valid = []

      # Piece color defines direction of travel. Enemy presence defines
      # the validity of diagonal movements
      if Move.color == :red
        valid << (p1 - 8) if unoccupied?(p1 - 8)
        valid << (p1 - 7) if piece_color(p1 - 7) == Move.enemy_color && col < 8
        valid << (p1 - 9) if piece_color(p1 - 9) == Move.enemy_color && col > 1
        # Only if the pieces is unmoved, can it move forward two rows
        valid << (p1 - 16) if !Move.pieces[p1][:moved] && unoccupied?(p1 - 8) && unoccupied?(p1 - 16)

      elsif Move.color == :black

        valid << (p1 + 8) if unoccupied?(p1 + 8)
        valid << (p1 + 7) if piece_color(p1 + 7) == Move.enemy_color && col > 1
        valid << (p1 + 9) if piece_color(p1 + 9) == Move.enemy_color && col < 8
        valid << (p1 + 16) if !Move.pieces[p1][:moved] && unoccupied?(p1 + 8) && unoccupied?(p1 + 16)
      end

      valid
    end
def move_pawn(p1)
      col = get_col_from_index(p1)
      valid = []

      # Piece color defines direction of travel. Enemy presence defines
      # the validity of diagonal movements
      if Move.color == :red
        valid << (p1 - 8) if unoccupied?(p1 - 8)
        valid << (p1 - 7) if piece_color(p1 - 7) == Move.enemy_color && col < 8
        valid << (p1 - 9) if piece_color(p1 - 9) == Move.enemy_color && col > 1
        # Only if the pieces is unmoved, can it move forward two rows
        valid << (p1 - 16) if !Move.pieces[p1][:moved] && unoccupied?(p1 - 8) && unoccupied?(p1 - 16)

      elsif Move.color == :black

        valid << (p1 + 8) if unoccupied?(p1 + 8)
        valid << (p1 + 7) if piece_color(p1 + 7) == Move.enemy_color && col > 1
        valid << (p1 + 9) if piece_color(p1 + 9) == Move.enemy_color && col < 8
        valid << (p1 + 16) if !Move.pieces[p1][:moved] && unoccupied?(p1 + 8) && unoccupied?(p1 + 16)
      end

      valid
    end
Returns all valid positions a pawn at index p1 can move to