:- module(agent, [init, look/0, move/1, take/1]). :- consult('parser.prolog'). :- consult('map.prolog'). % initialisation init :- initPos, initPits, initWumpus, initGold, initBats, !. initPos :- roomList(R), random_member(X,R), retractall(here(_)), not(somethingAt(X)), asserta(here(X)). initPits :- true. initWumpus :- roomList(R), random_member(X,R), retractall(wumpusAt(_)), not(somethingAt(X)), asserta(wumpusAt(X)). initGold :- true. initBats :- true. % 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(_) :- not(current_predicate(goldAt/1)). glitter(L) :- goldAt(L), write('You see a glitter along the sandy floor of the cave.\n'). breeze(_) :- not(current_predicate(pitAt/1)). breeze(L) :- connects(L,X,_), pitAt(X), write('A cold breeze blows through the room, making you shiver slightly.\n'). bats(_) :- not(current_predicate(batsAt/1)). bats(L) :- connects(L,X,_), batsAt(X), write('All available surfaces are covered in guano. How unsanitary.\n'). stench(_) :- not(current_predicate(wumpusAt/1)). 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). % miscellaneous clauses somethingAt(X) :- current_predicate(here/1), here(X). somethingAt(X) :- current_predicate(wumpusAt/1), wumpusAt(X). somethingAt(X) :- current_predicate(pitAt/1), pitAt(X). somethingAt(X) :- current_predicate(goldAt/1), goldAt(X). somethingAt(X) :- current_predicate(batsAt/1), batsAt(X). intercalate(I,S,O) :- O is I.