|Don't ask to ask, just ask|
Easy Text Adventures in Perlby Ovid (Cardinal)
|on Feb 13, 2005 at 23:14 UTC||Need Help??|
There always seems to be a bit of interest in games with programmers. japhy writes about CRPGs, Perl, Gtk2, and my vision, Tiefling picked up quite a few ++ votes and tons of responses for Daft text adventure project and dragonchild writes about Zork (but not much about Perl) in Testing Zork-style game. Well, while continuing to try to inspire interest in logic programming, I've bundled a very tiny (7 room) adventure game with the latest AI::Prolog. AI::Prolog, if you've not heard of it, is a pure Perl Prolog compiler. I've written about this at Bringing Logic Programming to Perl.
First, you have to use the aiprolog shell that now comes with the distribution. The game spider.pro is also included in the distribution in the data/ directory. The aiprolog shell can be installed automatically when you install AI::Prolog or you can choose to run it separately, if you prefer. You will find it in the bin/ dir.Assuming that "spider.pro" is in the current directory, the beginning of a simple session might look something like this ("?- " is the command prompt):
Shell commands in the aiprolog shell start with a percent sign '%' (which isn't too surprising as this is how you begin comments in Prolog.) The first command, % no more, tells the shell to not issue the More? (y/N) command after you issue queries. Usually you would want those, but when you're playing the game, it's quite annoying.
The second command, start., is a Prolog predicate defined in the program spider.pro. The commands that you issue to play the game are actually simple Prolog statements. You're learning logic programming and playing a game at the same time! Playing around with the shell, reading the docs and working through an easy guide to Prolog should be enough to get you started learning Prolog, though you really don't have to know it to play the game.
Just to give you an idea of how easy this is, here's the code to pick up (take) an object:
The only thing that might be mysterious about that is "nl" and that's just a command to print a newline.
If you want to write your own games (or other sample programs), feel free to send them to me and they might make it into the next distribution. Also, patches, suggestions and requests welcome! I expect to do a lot more with AI::Prolog in the future and the more involvement, the merrier.