summaryrefslogtreecommitdiff
path: root/map.prolog
diff options
context:
space:
mode:
Diffstat (limited to 'map.prolog')
-rw-r--r--map.prolog25
1 files changed, 24 insertions, 1 deletions
diff --git a/map.prolog b/map.prolog
index 84ec8c4..f5bb863 100644
--- a/map.prolog
+++ b/map.prolog
@@ -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).