AI Newsletter and playing games with Prolog

Ovid on 2005-02-08T17:34:41

Adrian turned me onto Dr. Dobb's AI Newsletter. It's great reading. For a bit of fun and to see how useful Prolog can be (and something that will eventually be in the examples/ directory of AI::Prolog), check out Adventure in Prolog (you'll have to scroll down past the Fortran and Inform sections.)

When writing a game, how easy is it to write code to let your character eat something in Prolog?

eat(Thing):-
   have(Thing),
   eat2(Thing).
eat(Thing):-
   respond(['You don''t have the ',Thing]).
   
eat2(Thing):-
   edible(Thing),
   retract(have(Thing)),
   respond(['That ',Thing,' was good']).
eat2(Thing):-
   tastes_yuchy(Thing),
   respond(['Three year olds don''t eat ',Thing]).
eat2(Thing):-
   respond(['You can''t eat a ',Thing]).

Not only is it easy, it even reads naturally. You see, Prolog is well suited for interactive fiction (IF) because it naturally deals with the relations between things and IF is all about the relations between things.