diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-04-03 21:07:06 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-04-03 21:07:06 +1100 |
commit | 0b65dd864a804a6b96ca1b8aeacd947eeb361538 (patch) | |
tree | 288974d3d6f9b9ddf6d1cd7f03c0a8215f4069e4 /map.prolog | |
parent | 133d71983ea4e39e6e971ca052b2eb0bf7437cc6 (diff) |
Moving some clauses around to more appropriate modules
Diffstat (limited to 'map.prolog')
-rw-r--r-- | map.prolog | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -1,5 +1,10 @@ -:- module(map, [roomList/1, connects/3]). +:- module(map, [roomList/1, isConnected/1, connects/3]). + + +:- consult('misc.prolog'). + + % map has 20 rooms, labelled a through t @@ -11,6 +16,24 @@ roomList(X) :- X = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t]. +isConnected([]) :- true. +isConnected(X) :- + head(Y,X), + tail(Z,X), + connectTail([Y],Z). + +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). + + % loop around the middle connects(a,b,northeast). |