summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--agent.prolog35
1 files changed, 28 insertions, 7 deletions
diff --git a/agent.prolog b/agent.prolog
index b2704a5..a575b2f 100644
--- a/agent.prolog
+++ b/agent.prolog
@@ -37,7 +37,22 @@ initWumpus :-
asserta(wumpusAt(X)).
-initGold :- true.
+initGold :-
+ retractall(goldAt(_)),
+ retractall(haveGold(_)),
+ insertGold(3),
+ asserta(haveGold(0)).
+
+
+insertGold(N) :-
+ N > 0,
+ Nx is N - 1,
+ insertGold(Nx),
+ roomList(Rooms),
+ filter(Rooms, somethingAt, Emptyrooms),
+ random_member(X,Emptyrooms),
+ asserta(goldAt(X)).
+insertGold(0) :- true.
initBats :- true.
@@ -63,13 +78,19 @@ move(Direction) :-
checkHazards, !.
-take(Item) :-
+take(gold) :-
here(Location),
- itemAt(Item,Location),
- canTake(Item),
- retract(itemAt(Item,Location)),
- asserta(holding(Item)),
- write('Taken.\n\n'), !.
+ goldAt(Location),
+ retract(goldAt(Location)),
+ haveGold(G),
+ Gx is G + 1,
+ retract(haveGold(G)),
+ asserta(haveGold(Gx)),
+ write('You find some gold. Lucky you.\n\n'), !.
+
+
+take(_) :-
+ write('You cannot take that.\n\n').
shoot(Direction) :-