From 52cc6731410d9862105b987bd0fa6ae819bab363 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 28 Mar 2014 19:27:21 +1100 Subject: More initialisation work --- agent.prolog | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/agent.prolog b/agent.prolog index 37ebd3c..3a189bb 100644 --- a/agent.prolog +++ b/agent.prolog @@ -11,8 +11,36 @@ % initialisation init :- + initPos, + initPits, + initWumpus, + initGold, + initBats, !. + + +initPos :- + roomList(R), + random_member(X,R), retractall(here(_)), - asserta(here(a)), !. + 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. @@ -54,23 +82,27 @@ writeSenses(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), @@ -83,3 +115,17 @@ writeExits(L) :- 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. + -- cgit