summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--agent.prolog61
1 files changed, 59 insertions, 2 deletions
diff --git a/agent.prolog b/agent.prolog
index ba59a43..a0c4289 100644
--- a/agent.prolog
+++ b/agent.prolog
@@ -1,5 +1,5 @@
-:- module(agent, [init, look/0, move/1, take/1]).
+:- module(agent, [init, look/0, move/1, take/1, shoot/1]).
:- consult('parser.prolog').
@@ -59,7 +59,8 @@ move(Direction) :-
retract(here(Location)),
asserta(here(New)),
join(['You move to the ',Direction,' .\n\n'],W),
- write(W), !.
+ write(W),
+ checkHazards, !.
take(Item) :-
@@ -71,6 +72,23 @@ take(Item) :-
write('Taken.\n\n'), !.
+shoot(Direction) :-
+ here(Location),
+ connects(Location, Target, Direction),
+ wumpusAt(Target),
+ write('You hear an unearthly scream.\n\n'),
+ retract(wumpusAt(Target)),
+ win.
+
+
+shoot(Direction) :-
+ here(Location),
+ connects(Location, Target, Direction),
+ not(wumpusAt(Target)),
+ write('Thunk. Missed.\n\n'),
+ moveWumpus.
+
+
% letting the player know what's going on
@@ -122,6 +140,45 @@ writeExits(Location) :-
+% modifying things and checking the ramifications
+
+moveWumpus :-
+ wumpusAt(Old),
+ findall(X, connects(Old,X,_), PossibleNews),
+ random_member(New, PossibleNews),
+ retract(wumpusAt(Old)),
+ asserta(wumpusAt(New)),
+ checkWumpus.
+
+
+checkHazards :-
+ checkWumpus.
+
+
+checkWumpus :-
+ here(Location),
+ wumpusAt(Location),
+ lose(eaten).
+checkWumpus :- true.
+
+
+
+
+% winning, losing, and otherwise
+
+win :-
+ write('*** YOU WIN ***\n'),
+ halt(0).
+
+
+lose(eaten) :-
+ write('You have been eaten by the wumpus.\n'),
+ write('*** GAME OVER ***\n'),
+ halt(0).
+
+
+
+
% miscellaneous clauses
somethingAt(X) :- current_predicate(here/1), here(X).