:- 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').