From 8dcbe15a59014e32b7e32d5466e23bbfbbe0ccc8 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 2 Apr 2014 19:40:00 +1100 Subject: Game now keeps track of moves made and gold found --- agent.prolog | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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). -- cgit