summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--agent.prolog19
1 files changed, 18 insertions, 1 deletions
diff --git a/agent.prolog b/agent.prolog
index 11502ac..6e51283 100644
--- a/agent.prolog
+++ b/agent.prolog
@@ -22,6 +22,8 @@ init :-
initPos :-
+ retractall(moves(_)),
+ asserta(moves(0)),
retractall(here(_)),
roomList(Rooms),
filter(Rooms, somethingAt, Emptyrooms),
@@ -84,6 +86,7 @@ move(Direction) :-
join(['You move to the ',Direction,' .\n\n'],W),
write(W),
checkHazards,
+ incrementMoves,
look, !.
@@ -95,7 +98,8 @@ take(gold) :-
Gx is G + 1,
retract(haveGold(G)),
asserta(haveGold(Gx)),
- write('You find some gold. Lucky you.\n\n'), !.
+ write('You find some gold. Lucky you.\n\n'),
+ incrementMoves, !.
take(_) :-
@@ -108,6 +112,7 @@ shoot(Direction) :-
wumpusAt(Target),
write('You hear an unearthly scream.\n\n'),
retract(wumpusAt(Target)),
+ incrementMoves,
win.
@@ -116,6 +121,7 @@ shoot(Direction) :-
connects(Location, Target, Direction),
not(wumpusAt(Target)),
write('Thunk. Missed.\n\n'),
+ incrementMoves,
moveWumpus.
@@ -220,8 +226,19 @@ checkPit :- true.
% winning, losing, and otherwise
+incrementMoves :-
+ moves(N),
+ retractall(moves(_)),
+ Nx is N + 1,
+ asserta(moves(Nx)).
+
+
win :-
write('*** YOU WIN ***\n'),
+ moves(M),
+ haveGold(G),
+ join(['\nWin accomplished in ',M,' moves with ',G,' gold found\n'],W),
+ write(W),
halt(0).