Index: data/ai/lua/stdlib.lua
===================================================================
--- data/ai/lua/stdlib.lua	(revision 42208)
+++ data/ai/lua/stdlib.lua	(working copy)
@@ -11,6 +11,23 @@
        wesnoth.message(string.format("Hello from Lua AI which controls side %d! It's turn %d.", ai.side, wesnoth.current.turn))
 end
 
+
+--! returns the enemy units that are within the given range surrounding ai_unit
+function ai.close_enemies(ai_unit, range)
+	local helper = wesnoth.require "lua/helper.lua"	
+	local enemy_sides = helper.get_enemy_sides(ai.side)
+	local enemy_sides_string = helper.list_to_string(enemy_sides)
+       local units = wesnoth.get_units({
+					side = enemy_sides_string,
+					{"filter_location", {x= ai_unit.x, y= ai_unit.y, radius = range }}
+					})
+        return units
+end
+
+
 --! ===========================
 end
 }
Index: data/lua/helper.lua
===================================================================
--- data/lua/helper.lua	(revision 42047)
+++ data/lua/helper.lua	(working copy)
@@ -271,4 +271,49 @@
 	return math.max(hdist, vdist + math.floor(hdist / 2))
 end
 
+--! Returns the location, which is nearest to the input_loc from the list
+function helper.nearest_unit(input_unit,list_of_units)
+        local output_unit = list_of_units[1];
+        local dist = helper.distance_between(  input_unit.x, input_unit.y, output_unit.x, output_unit.y)
+        local temp_dist
+
+        for i = 2, #list_of_units do
+                temp_dist = helper.distance_between(input_unit.x, input_unit.y,list_of_units[i].x,list_of_units[i].y)
+                if( temp_dist < dist) then
+                        output_unit = list_of_units[i]
+                        dist = temp_dist
+                end
+        end
+        return output_unit
+end
+
+--! Returns the list of enemies of input_side
+
+function helper.get_enemy_sides(input_side)
+	
+	local side_count = wesnoth.get_side_count()
+       local enemy_sides ={}
+       local index = 1
+       for i = 1,side_count do
+       	if wesnoth.is_enemy(i, input_side) == false then
+               	enemy_sides[index] = i
+                       index = index + 1
+               end
+       end
+	return enemy_sides
+end
+
+--! Retruns a string consist of each unit of given list
+
+function helper.list_to_string(input_list)
+
+	local output = ""
+	for i =1, #input_list do
+		output = output .. "" .. tostring(input_list[i]) .. ","
+	end
+	
+	output = string.sub(output,1,-2)
+	return output
+end
+
 return helper
