diff options
-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). + |