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
|
:- module(agent, [init, look/0, move/1, take/1]).
:- consult('parser.prolog').
:- consult('map.prolog').
% initialisation
init :-
retractall(here(_)),
asserta(here(a)), !.
% command functions
look :-
here(L),
writeSenses(L),
writeExits(L).
move(D) :-
here(L),
connects(L,N,D),
retract(here(L)),
asserta(here(N)),
join(['You move to the ',D,' .\n\n'],M),
write(M), !.
take(T) :-
here(L),
itemAt(T,L),
canTake(T),
retract(itemAt(T,L)),
asserta(holding(T)),
write('Taken.\n\n'), !.
% letting the player know what's going on
writeSenses(L) :-
glitter(L),
breeze(L),
bats(L),
stench(L).
glitter(L) :-
goldAt(L),
write('You see a glitter along the sandy floor of the cave.\n').
breeze(L) :-
connects(L,X,_),
pitAt(X),
write('A cold breeze blows through the room, making you shiver slightly.\n').
bats(L) :-
connects(L,X,_),
batsAt(X),
write('All available surfaces are covered in guano. How unsanitary.\n').
stench(L) :-
connects(L,X,_),
wumpusAt(X),
write('An overpowering stench fills your nose.\n').
writeExits(L) :-
findall(X, connects(L,_,X), E),
intercalate(E, ', ', O),
join(['There are exits to the ',O,'.\n'],W),
write(W).
|