diff options
-rw-r--r-- | agent.prolog | 15 | ||||
-rw-r--r-- | item.prolog | 22 | ||||
-rw-r--r-- | main.prolog | 10 | ||||
-rw-r--r-- | map.prolog | 10 |
4 files changed, 54 insertions, 3 deletions
diff --git a/agent.prolog b/agent.prolog index 338b3f2..994b77d 100644 --- a/agent.prolog +++ b/agent.prolog @@ -1,9 +1,11 @@ -:- module(agent, [look/0, move/1]). +:- module(agent, [look/0, move/1, take/1]). look :- - write('looking\n'). + here(L), + writeItemsAt(L), + writeExits(L). move(D) :- @@ -12,3 +14,12 @@ move(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.'), !. + diff --git a/item.prolog b/item.prolog new file mode 100644 index 0000000..11e469c --- /dev/null +++ b/item.prolog @@ -0,0 +1,22 @@ + +:- module(item, [itemAt/2, writeItemsAt/1, canTake/1, description/2]). + + +itemAt(ladder,a). + + +writeItemsAt(L) :- + itemAt(X,L), + description(X,D), + write(D), + fail. +writeItemsAt(_) :- true. + + +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'). + diff --git a/main.prolog b/main.prolog index 5204ef7..ddf7baa 100644 --- a/main.prolog +++ b/main.prolog @@ -3,9 +3,17 @@ :- consult('map.prolog'). :- consult('agent.prolog'). :- consult('read.prolog'). +:- consult('item.prolog'). init :- - retractall(here(X)), + retractall(here(_)), asserta(here(a)), !. + +join([X|Y],R) :- + join(Y,Rx), + atom_concat(X,Rx,R). +join([X],R) :- + R = X. + @@ -1,4 +1,14 @@ +:- module(map, [connects/3, writeExits/1]). + + +writeExits(L) :- + connects(L,_,D), + join(['You see an exit to the ',D,'.\n'],M), + write(M), + fail. +writeExits(_) :- true. + % map has 20 rooms, labelled a through t % connections between rooms inscribe a dodecahedron, with the rooms |