From 320e9630c3ecff0105ea97fd3e09836619b54b62 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Tue, 1 Apr 2014 22:11:00 +1100 Subject: Added clause to test whether a subset of rooms is connected --- agent.prolog | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'agent.prolog') diff --git a/agent.prolog b/agent.prolog index 0fa24a2..fb49cde 100644 --- a/agent.prolog +++ b/agent.prolog @@ -73,6 +73,9 @@ insertBats(0) :- true. + + + % command functions look :- @@ -264,3 +267,28 @@ filter(List, Predicate, Result) :- findall(X, Test, No), subtract(List, No, Result). + +head(X,[Y]) :- X = Y. +head(X,[Y|_]) :- X = Y. + + +tail(X,[]) :- X = []. +tail(X,[_]) :- X = []. +tail(X,[_|Y]) :- X = Y. + + +isConnected([]) :- true. +isConnected([_]) :- true. +isConnected([X|Y]) :- connectTail([X],Y). + +connectTail(_,[]) :- true. +connectTail([],_) :- false. +connectTail(Open,G) :- + head(X,Open), + tail(Y,Open), + findall(N, connects(X,N,_), Ns), + subtract(G,Ns,Gx), + subtract(G,Gx,Nx), + append(Y,Nx,Yx), + connectTail(Yx,Gx). + -- cgit