solve_task (Task,Cost) :-
my_agent (A), get_agent_position(A, P), solve_task_dfs(Task, [P], [P|Path]), !, agent_do_moves(A,Path), length(Path, Cost).
solve_task_dfs(Task, [P|Ps],Path) : –
achieved(Task,P), reverse ([P|Ps],Path)
map_adjacent(P, Q,empty), \+ member (O,Ps), solve_task_dfs(Task, [Q, P|Ps], Path).
achieved (Task ‚Pos) : –
Task=find(Obj), map_adjacent (Pos ,_,Obj)
Task=go(Pos).
You will need to replace the above solve_task_dfs/3 by a new predicate (with your choice of name and arity) that implements an appropriate A’ search strategy. The easiest way to do this is by the following three consecutive steps:
• First substitute solve_task_dfs/3 by a breadth-first search predicate which can be
easily adapted from the search_bf/2 of Lab Search by simply: adding an extra argument to store the Task; and calling achieved/2 instead of complete/1.
• Then convert your predicate into an A’ search that sorts the agenda using a score obtained by summing the distance of a node from the start with its Manhattan distance to the target (if its location is known) or with the constant o (if it’s not).
• Finally you’ll need to adapt your code to take into account the agent’s available energy and also gives it the ability to refuel at charging stations along the way, if necessary.