AI-Prolog
view release on metacpan or search on metacpan
data/sleepy.pro view on Meta::CPAN
/* "Sleepy" -- a sample adventure game, by David Matuszek. */
% http://www.csc.vill.edu/~dmatusze/resources/prolog/sleepy.html
/* In standard Prolog, all predicates are "dynamic": they
can be changed during execution. SWI-Prolog requires such
predicates to be specially marked. */
% :- dynamic at/2, i_am_at/1, i_am_holding/1, alive/1,
% lit/1, visible_object/1.
/* This routine is purely for debugging purposes. */
%dump :- listing(at), listing(i_am_at), listing(i_am_holding),
% listing(alive), listing(lit), listing(visible_object).
/* This defines my current location. */
i_am_at(bedroom).
i_am_holding(nothing).
/* These facts describe how the rooms are connected. */
path(bedroom, n, den) :- lit(bedroom).
path(bedroom, n, den) :-
print('You trip over something in the dark.'), nl,
!, fail.
path(den, s, bedroom).
path(bedroom, d, bed).
path(bed, u, bedroom).
% These facts tell where the various objects in the game
% are located.
at(flyswatter, den).
at(fly, bedroom).
at('light switch', den).
at('light switch', bedroom).
/* These facts specify some game-specific information. */
alive(fly).
lit(bedroom).
lit(den).
visible_object('light switch').
/* These rules describe how to pick up an object. */
take(fly) :-
print('It is too fast for you!'), nl,
!, fail.
take('light switch') :-
take(switch).
take(switch) :-
print('It is firmly embedded in the wall!'), nl,
!, fail.
take(X) :-
( run in 2.583 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )