From dddc09e4d4aa6157240827630d8f5fdb0ab9f07e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 30 Mar 2014 04:01:27 +1100 Subject: Added gold init and the ability to take it --- agent.prolog | 35 ++++++++++++++++++++++++++++------- 1 file 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) :- -- cgit