summaryrefslogtreecommitdiff
path: root/agent.prolog
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-29 00:59:36 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-29 00:59:36 +1100
commita682658a67c6b02f0817058b5c5b0ecf1377a17f (patch)
tree0084ab750cc665106571233469b5a9f0ea841634 /agent.prolog
parent6761a99f7e8ed4e73614f304031b136891c5e3b9 (diff)
Added shoot command, winning and game over conditions
Diffstat (limited to 'agent.prolog')
-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).