summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-30 04:01:27 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-30 04:01:27 +1100
commitdddc09e4d4aa6157240827630d8f5fdb0ab9f07e (patch)
tree9bbfbe60e39c1ed959305513e5e1ad429aeb8633
parent4a4da37573d5d2b246c1ab874554cec119e45035 (diff)
Added gold init and the ability to take it
-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) :-