AI-Prolog

 view release on metacpan or  search on metacpan

data/sleepy.pro  view on Meta::CPAN

        nl.

take(_) :-
        print('I do not see it here.'),
        nl.


/* These rules describe how to put down an object. */

drop(X) :-
        i_am_holding(X),
        i_am_at(Place),
        retract(i_am_holding(X)),
        assert(at(X, Place)),
        print('OK.'),
        nl.

drop(_) :-
        print('You are not holding it!'),
        nl.


/* These rules define the six direction letters as calls to go/1. */

n :- go(n).

s :- go(s).

e :- go(e).

w :- go(w).

u :- go(u).

d :- go(d).


/* This rule tells how to move in a given direction. */

go(Direction) :-
        i_am_at(Here),
        path(Here, Direction, There),
        retract(i_am_at(Here)),
        assert(i_am_at(There)),
        look.

go(_) :-
        print('You can not go that way.'), nl.


/* This rule tells how to look about you. */

look :-
        i_am_at(Place),
        describe(Place),
        nl,
        notice_objects_at(Place),
        nl.


/* These rules set up a loop to mention all the objects in your vicinity. */

notice_objects_at(Place) :-
    lit(Place),
        at(X, Place),
    visible_object(X),
        print('There is a '), print(X), print(' here.'), nl,
        fail.

notice_objects_at(_).


/* These rules are specific to this particular game. */

use(flyswatter) :-
    swat(fly).

use(bed) :-
    i_am_at(bedroom),
    d.

use(bed) :-
    print('It is in the bedroom!'), nl,
    !, fail.

use(switch) :-
    i_am_at(Place),
    lit(Place),
    off.

use(switch) :-
    on.

on :-
    i_am_at(bed),
    print('You can not reach the light switch from here.'), nl,
    !, fail.

on :-
    i_am_at(Place),
    lit(Place),
    print('The lights are already on.'), nl.

on :-
    i_am_at(Place),
    assert(lit(Place)),
    print('The room lights come on.'), nl,
    optional_buzz_off,
    look.

off :-
    i_am_at(bed),
    print('You can not reach the light switch from here.'), nl,
    !, fail.

off :-
    i_am_at(Place),
    retract(lit(Place)),
    optional_buzz_off,
    print('It is now dark in here.'), nl.



( run in 0.589 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )