AI-Prolog
view release on metacpan or search on metacpan
data/spider.pro view on Meta::CPAN
%"Spider" -- A Sample Adventure Game in Prolog
% David Matuszek, Villanova University
% http://www.csc.vill.edu/~dmatusze/resources/prolog/spider.html
% This defines my current location
i_am_at(meadow).
% These facts describe how the rooms are connected.
path(spider, d, cave).
path(cave, u, spider).
path(cave, w, cave_entrance).
path(cave_entrance, e, cave).
path(cave_entrance, s, meadow).
path(meadow, n, cave_entrance) :- at(flashlight, in_hand).
path(meadow, n, cave_entrance) :-
print('Go into that dark cave without a light? Are you crazy?'), nl,
fail.
path(meadow, s, building).
path(building, n, meadow).
path(building, w, cage).
path(cage, e, building).
path(closet, w, building).
path(building, e, closet) :- at(key, in_hand).
path(building, e, closet) :-
print('The door appears to be locked.'), nl,
fail.
% These facts tell where the various objects in the game are located.
at(ruby, spider).
at(key, cave_entrance).
at(flashlight, building).
at(sword, closet).
% This fact specifies that the spider is alive.
alive(spider).
% These rules describe how to pick up an object.
take(X) :-
at(X, in_hand),
print('You are already holding it!'),
nl.
take(X) :-
i_am_at(Place),
at(X, Place),
retract(at(X, Place)),
assert(at(X, in_hand)),
print('OK.'),
nl.
take(_) :-
print('I do not see it here.'),
nl.
( run in 0.778 second using v1.01-cache-2.11-cpan-39bf76dae61 )