\end{itemize}
\subsection{Part 2: Implementation}
+\subsubsection{Task 3: Translate Axioms}
+\lstinputlisting[title={domain-task1.pl},language=prolog]{./src/domain-task1.pl}
+
+\subsubsection{Task 4: The Planning Problem in Figure 1}
+\lstinputlisting[title={instance-task1.pl},language=prolog]{./src/instance-task1.pl}
+
+\subsubsection{Task 5: Crates go to Any Goal Location}
+\subsubsection{Task 6: Inverse Problem}
+
+\subsection{Part 3: Extending the domain}
\subsection{Evaluation}
\begin{itemize}
--- /dev/null
+% ------------------------- Domain Definition -------------------------
+% --- Cross-file definitions ------------------------------------------
+:- multifile connected/3, crate/3, agent/2.
+
+% --- Primitive control actions ---------------------------------------
+primitive_action(move(_, _)).
+primitive_action(push(_, _)).
+
+% --- Precondition for primitive actions ------------------------------
+poss(move(From, To), S) :-
+ agent(From, S),
+ connected(From, To, _),
+ not(crate(_, To, S)).
+poss(push(From, Direction), S) :-
+ agent(From, S),
+ connected(From, CrateLocation, Direction),
+ crate(_, CrateLocation, S),
+ connected(CrateLocation, CrateTarget, Direction),
+ not(crate(_, CrateTarget, Direction)).
+
+% --- Successor state axioms ------------------------------------------
+agent(AgentPlek, do(A, S)) :-
+ A = move(_, AgentPlek);
+ A = push(OudeAgentPlek1, Richting), connected(OudeAgentPlek1, AgentPlek, Richting);
+ not(A = move(AgentPlek, _)), not(A = push(AgentPlek, _)), agent(AgentPlek, S).
+
+crate(Krat, Kratplek, do(A, S)) :-
+ A = push(AgentPlek, Richting),
+ connected(AgentPlek, OudeKratPlek, Richting),
+ connected(OudeKratPlek, Kratplek, Richting),
+ crate(Krat, OudeKratPlek, S);
+ not(A = push(AgentPlek2, Richting)), connected(AgentPlek2, Kratplek, Richting), crate(Krat, Kratplek, S).
--- /dev/null
+% ------------------------- Problem Instance --------------------------
+% --- Load domain definitions from an external file -------------------
+:- [domaintask1].
+
+% --- Definition of the initial state ---------------------------------
+connected(loc1-1, loc2-1, north).
+connected(loc1-1, loc1-2, east).
+connected(loc1-2, loc2-2, north).
+connected(loc1-2, loc1-3, east).
+connected(loc1-3, loc2-3, north).
+connected(loc1-3, loc1-4, east).
+connected(loc1-4, loc2-4, north).
+
+connected(loc2-1, loc3-1, north).
+connected(loc2-1, loc2-2, east).
+connected(loc2-2, loc3-2, north).
+connected(loc2-2, loc2-3, east).
+connected(loc2-3, loc3-3, north).
+connected(loc2-3, loc2-4, east).
+
+connected(loc3-1, loc3-2, north).
+connected(loc3-2, loc3-3, north).
+
+connected(X, Y, east) :- connected(Y, X, west).
+connected(X, Y, north) :- connected(Y, X, south).
+
+crate(crate-c, loc2-1, s0).
+crate(crate-b, loc2-2, s0).
+crate(crate-a, loc2-3, s0).
+
+target(crate-a, loc1-1).
+target(crate-b, loc1-3).
+target(crate-c, loc1-2).
+
+agent(loc3-2, s0).
+
+% --- Goal condition that the planner will try to reach ---------------
+goal(S) :- forall(crate(Crate, Loc, S), target(Crate, Loc)).
--- /dev/null
+% -------------= Simple planner for situation calculus =---------------
+%
+% Executes an iterative deepening search, by default limited to a depth
+% of 15 levels
+%
+% plan. will search for a plan of maximum length
+% plan(M). will search for a plan of maximum length up to M
+% plan(N,M). will search for a plan of mimimum length N and maximum
+% length M
+%
+%
+% Checklist for the definition of a domain and problem:
+%
+% - initial state initialize fluents in s0
+%
+% - possibility axioms poss( <action>(...), S ) :- <precond>
+%
+% - successor-state axioms <fluent>( ..., result(A,S) ) :-
+% <some events made it true>; % or
+% <it was true all along>, % and
+% not(<some events made it false>).
+%
+% - goal predicate goal(S) :- <goal conditions>
+%
+
+% --------------------------= High Level =-----------------------------
+
+% default number of iterations (15)
+plan :- plan(0, 15).
+
+% given max number of iterations
+plan(MaxDepth) :- plan(0, MaxDepth).
+
+% given min and max number of iterations
+plan(MinDepth, MaxDepth) :-
+ M is MaxDepth+1, write('Trying plans of length: '),
+ plan(Plan, MinDepth, M), nl, nl, writePlan(Plan).
+
+
+
+% same as above, to be called from shell; include additional output
+% messages and halt to quit pl
+planner :- planner(0, 15).
+planner(MaxDepth) :- planner(0, MaxDepth).
+planner(MinDepth, MaxDepth) :-
+ nl, plan(MinDepth, MaxDepth), nl, halt;
+ write('\n\nNo plan has been found!'), nl, nl, halt.
+
+
+
+% ---------------------------= Low Level =-----------------------------
+
+% start from depth N, up to M
+
+plan(P, N, M) :-
+ N < M,
+ debugoutput(write('\n\nPlans of length ')),
+ writef('%w %f',[N]),
+ seqplan(P, N, s0), !.
+
+plan(P, N, M) :- N < M, O is N+1, plan(P, O, M).
+
+seqplan( [], N, S ) :- N = 0, debugoutput(writeSituation(S)), goal(S).
+seqplan( [A|L], N, S) :- N > 0, M is N-1, result(A,S,S1), seqplan(L, M, S1).
+
+result(E,S,result(E,S)) :- primitive_action(E), poss(E,S).
+
+% -----------------------= Support Function =--------------------------
+
+% debugoutput will be printed only if debug(on) is defined in the KB
+:- dynamic debug/1.
+:- multifile debug/1.
+
+debug(on).
+debugoutput(A) :- debug(on), A, !; true.
+
+
+% prints a situation as a sequence of actions, starting from s0
+writeSituation(s0) :- write('\n s0').
+writeSituation(result(A,S)) :- writeSituation(S), writef(" > %w", [A]).
+
+% prints a plan as a list of actions, numbered
+
+writePlan(List) :-
+ debugoutput(write('\nA plan has been found:\n\n')),
+ writePlan(List,1).
+
+writePlan([],_) :-
+ nl.
+
+writePlan([Action|List], Counter) :-
+ writef('%3R %w\n',[Counter,Action]),
+ Next is Counter+1,
+ writePlan(List,Next).
+
+
+% hides some (unimportant) warnings from the pl interpreter
+:- style_check([-discontiguous, -singleton]).
+
+
+
+% ---------------------------------------------------------------------
+% ---------------------------------------------------------------------