Remember that this is described by knowledge base DD, which contains three kinds of fact:
Supplement 2 described what these mean.
Assume that the knowledge base also contains a clause for each player
giving their score: score(fred,500)
. In Supplement 7, we saw how this
might be updated as a player kills more of his enemies.
Write a predicate which has no arguments called check
. When check
is called, it examines the score: if it is greater than 2000, it
writes a message saying ``You have won'', otherwise it does nothing.
When you have done that, enter some is_worth
facts defining the
values of the enemies, as suggested in Supplement 5:
is_worth(dragon,500)
and so on.
Then write a predicate called kill(P,A)
.
Here P is a player (e.g.
fred
) and A is an animal (e.g. dragon
). What kill
should do is to
assume that P has just killed A, and to remove the old score
fact,
replacing it by a new one in which the worth of A has been added to P's
score. You can do this with gain
, as described in Supplement 7.
Because A is now dead, kill
should also replace the old worth
fact
for A by one giving it a worth of 0.
You can build on this and the other cave world exercises to write a
complete Adventure game. Its players could be human, or they could be
automatic like the traders in Traveller. In the former case, the program
would ask what action the player wanted to take. This could involve some
natural language analysis: it would be nice if a player could type Throw firebomb at Wumpus, Eat packed lunch or Run South-West
to the blasted tree. In the latter case, the behaviour of the players
would be dictated by predicates, defined perhaps like will_be
in
Supplement 2, but more complicated. The file DDMOVE, which you can
showlib
, is just a start in this direction.