diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-04-01 22:11:00 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-04-01 22:11:00 +1100 |
commit | 320e9630c3ecff0105ea97fd3e09836619b54b62 (patch) | |
tree | bd8994c995fa88ee38790c7e8930ae46ec9941c4 /agent.prolog | |
parent | 0a87a1b949aa6de597dd31fa2ee414afa57627db (diff) |
Added clause to test whether a subset of rooms is connected
Diffstat (limited to 'agent.prolog')
-rw-r--r-- | agent.prolog | 28 |
1 files changed, 28 insertions, 0 deletions
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). + |