COS4851
Assignment 4
Unique No: 813039
DUE: 30 November 2025
, DUE DATE: 30 November 2025
SUBMISSION PROCEDURE: Written
TOTAL MARKS: 50
UNIQUE NUMBER: 813039
STUDY MATERIAL: Bratko
Question 1: Depth-Limited AND/OR Search and Tower of Hanoi 1
Implementation of Depth-Limited, Depth-First Search for AND/OR Graphs
The following Prolog code implements a depth-limited search (DLS) for solving problems
represented as AND/OR graphs. The main predicate solve(Problem, MaxDepth) is
defined, using the helper solve_dls(Problem, CurrentDepth, MaxDepth) for the
recursive search.
Prolog
% solve(Problem, MaxDepth) :- The problem is solvable within
MaxDepth.
solve(P, MaxD) :-
solve_dls(P, 0, MaxD).
% solve_dls(Problem, CurrentDepth, MaxDepth)
% 1. BASE CASE: Success if the problem is solved (is a
fact/primitive problem)
% and the current depth is within the limit.
solve_dls(P, _, _) :-
primitive(P).
% 2. BASE CASE: Failure if the maximum depth is exceeded.
solve_dls(_, D, MaxD) :-
D > MaxD,
Assignment 4
Unique No: 813039
DUE: 30 November 2025
, DUE DATE: 30 November 2025
SUBMISSION PROCEDURE: Written
TOTAL MARKS: 50
UNIQUE NUMBER: 813039
STUDY MATERIAL: Bratko
Question 1: Depth-Limited AND/OR Search and Tower of Hanoi 1
Implementation of Depth-Limited, Depth-First Search for AND/OR Graphs
The following Prolog code implements a depth-limited search (DLS) for solving problems
represented as AND/OR graphs. The main predicate solve(Problem, MaxDepth) is
defined, using the helper solve_dls(Problem, CurrentDepth, MaxDepth) for the
recursive search.
Prolog
% solve(Problem, MaxDepth) :- The problem is solvable within
MaxDepth.
solve(P, MaxD) :-
solve_dls(P, 0, MaxD).
% solve_dls(Problem, CurrentDepth, MaxDepth)
% 1. BASE CASE: Success if the problem is solved (is a
fact/primitive problem)
% and the current depth is within the limit.
solve_dls(P, _, _) :-
primitive(P).
% 2. BASE CASE: Failure if the maximum depth is exceeded.
solve_dls(_, D, MaxD) :-
D > MaxD,