summaryrefslogtreecommitdiff
path: root/agent.prolog
blob: 0c1d4457a7c6cefa47de294fe3a1cfb796690b30 (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

:- 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),
    writeItemsAt(L),
    writeExits(L).


move(D) :-
    here(L),
    connects(L,N,D),
    retract(here(L)),
    asserta(here(N)), !.


take(T) :-
    here(L),
    itemAt(T,L),
    canTake(T),
    retract(itemAt(T,L)),
    asserta(holding(T)),
    write('Taken.'), !.




% letting the player know what's going on

writeItemsAt(L) :-
    itemAt(X,L),
    description(X,D),
    write(D),
    fail.
writeItemsAt(_) :- true.


writeExits(L) :-
    connects(L,_,D),
    join(['You see an exit to the ',D,'.\n'],M),
    write(M),
    fail.
writeExits(_) :- true.




% basic facts about the maze

itemAt(ladder,a).


canTake(gold).
canTake(deadWumpus).


description(ladder, 'There is a rope ladder hanging from the ceiling here.\n').
description(gold, 'You see a glitter along the sandy floor of the cave.\n').