% ========================================================================== % $Id: adventure.pl,v 1.1 2014/02/04 03:57:03 jlang Exp $ % CSI2120 example Code for lecture 8 % ========================================================================== % (C)opyright: % % Jochen Lang % EECS, University of Ottawa % 800 King Edward Ave. % Ottawa, On., K1N 6N5 % Canada. % http://www.eecs.uottawa.ca/~jlang % % Creator: jlang (Jochen Lang) based on notes by R. Laganiere % Email: jlang@eecs.uottawa.ca % ========================================================================== % $Log: adventure.pl,v $ % Revision 1.1 2014/02/04 03:57:03 jlang % Added initial example for database manipulations. % % ========================================================================== :-dynamic here/1. here(kitchen). room(kitchen). room(office). room(hall). room('dining room'). room(cellar). location(desk, office). location(apple, kitchen). location(flashlight, desk). location('washing machine', cellar). location(nani, 'washing machine'). location(broccoli, kitchen). location(crackers, kitchen). location(computer, office). door(office, hall). door(kitchen, office). door(hall, 'dining room'). door(kitchen, cellar). door('dining room', kitchen). connect(X,Y) :- door(X,Y). connect(X,Y) :- door(Y,X). can_go(Place):- here(X), connect(X, Place). goto(Place):- can_go(Place), move(Place), look. move(Place):- retract(here(X)), asserta(here(Place)). look :- here(Place), write('You are in the '), write(Place), nl, write('You can see:'), nl, list_things(Place), write('You can go to:'), nl, list_connections(Place). list_connections(Place) :- findall(X,connect(Place, X),B), tab(2), write(B), nl. list_things(Place) :- findall(X,location(X, Place),B), tab(2), write(B), nl.