summaryrefslogtreecommitdiff
path: root/src/map.prolog
blob: f5bb863770ff0fd9187e8cb88dc58544bcf52bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

:- module(map, [roomList/1, isConnected/1, connects/3]).


:- consult('misc.prolog').




% map has 20 rooms, labelled a through t
% connections between rooms inscribe a dodecahedron, with the rooms
% corresponding to the vertices and the connections between them to
% the edges


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).
connects(b,c,southeast).
connects(c,d,northeast).
connects(d,e,southeast).
connects(e,f,northeast).
connects(f,g,southeast).
connects(g,h,northeast).
connects(h,i,southeast).
connects(i,j,northeast).
connects(j,a,southeast).


% loop in the other direction around the middle

connects(a,j,northwest).
connects(j,i,southwest).
connects(i,h,northwest).
connects(h,g,southwest).
connects(g,f,northwest).
connects(f,e,southwest).
connects(e,d,northwest).
connects(d,c,southwest).
connects(c,b,northwest).
connects(b,a,southwest).


% connections from the middle loop up to the top pentagon

connects(b,k,north).
connects(d,l,north).
connects(f,m,north).
connects(h,n,north).
connects(j,o,north).


% connections from the top pentagon down to the middle loop

connects(k,b,south).
connects(l,d,south).
connects(m,f,south).
connects(n,h,south).
connects(o,j,south).


% connections around the top pentagon

connects(k,l,east).
connects(l,m,east).
connects(m,n,east).
connects(n,o,east).
connects(o,k,east).


% connections around the top pentagon in the other direction

connects(l,k,west).
connects(m,l,west).
connects(n,m,west).
connects(o,n,west).
connects(k,o,west).


% connections from the middle loop to the bottom pentagon

connects(a,p,south).
connects(c,q,south).
connects(e,r,south).
connects(g,s,south).
connects(i,t,south).


% connections from the bottom pentagon up to the middle loop

connects(p,a,north).
connects(q,c,north).
connects(r,e,north).
connects(s,g,north).
connects(t,i,north).


% connections around the bottom pentagon

connects(p,q,east).
connects(q,r,east).
connects(r,s,east).
connects(s,t,east).
connects(t,p,east).


% connections around the bottom pentagon in the other direction

connects(q,p,west).
connects(r,q,west).
connects(s,r,west).
connects(t,s,west).
connects(p,t,west).