summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-04-02 19:40:00 +1100
committerJed Barber <jjbarber@y7mail.com>2014-04-02 19:40:00 +1100
commit8dcbe15a59014e32b7e32d5466e23bbfbbe0ccc8 (patch)
tree3a1d3e276e9b4de0d95bd6cd38b200f8d55fec8d
parent6a143f613747fed15132f1db63695f4d7a9f2eb1 (diff)
Game now keeps track of moves made and gold found
-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).