Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Adventures in Perl 6

by nferraz (Monk)
on May 07, 2007 at 16:33 UTC ( [id://613974]=perlmeditation: print w/replies, xml ) Need Help??

Dear Monks,

Since I started using computers, many years ago, I've always been fascinated with the idea of writing my own games.

The problem is that I didn't have a team to help me with fancy images and sounds; so I started writing simple text adventures, and have done so in most languages I have learnt so far.

This meditation is about the writing of an adventure in Perl 6.

According to the Wikipedia, interactive fiction (which is another name for "adventure") describes software simulating environments in which players use text commands to control characters and influence the environment. Works in this form can be understood as literary narratives and as computer games. In common usage, the word refers to text adventures, a type of adventure game with text-based input and output.

A typical adventure session could go like this (an extract from the classic Colossal Cave):

You are standing at the end of a road before a small brick building. Around you is a forest. A small stream flows out of the building and down a gully. > SOUTH You are in a valley in the forest beside a stream tumbling along a rocky bed. > SOUTH At your feet all the water of the stream splashes into a 2-inch slit in the rock. Downstream the streambed is bare rock. > DRINK WATER You have taken a drink from the stream. The water tastes strongly of minerals, but is not unpleasant. It is extremely cold.

One of the interesting things of writing adventures, is that they require some knowledge of a programming language, but are not that difficult to write (once you know a few basic concepts); and since creating is actually as fun as playing, it's an interesting way to learn a new language.

So I decided I would test my knowledge against the current implementations of Perl 6, and the result was this presentation to the Nordic Perl Workshop (and a couple of days later for the guys of Oslo.pm).

I hope you'll enjoy!

Replies are listed 'Best First'.
Re: Adventures in Perl 6
by dewey (Pilgrim) on May 07, 2007 at 17:46 UTC
    Nice work! Good to see a hand-rolled IF parser using an honest-to-goodness grammar instead of a collection of hacks.

    Incidentally, have you seen Inform 7? A very interesting language...

    ~dewey

      That's a really interesting approach to interactive fiction!

      According to the manual, the world is defined with assertions like these:

      The wood-slatted crate is in the Gazebo. The crate is a container. Mr Jones wears a top hat. The crate contains a croquet mallet.

      The manual also explains that "the world described by these assertions is the starting condition of the game: what happens when play begins is another matter. If somebody picks up the crate and walks off with it, then it will no longer be in the Gazebo. Mr Jones may remove his hat".

      Really really interesting.

Re: Adventures in Perl 6
by ady (Deacon) on May 07, 2007 at 18:26 UTC
    ++ Nice demo of P6 grammars Nelson
    (&& I enjoyed your presentation at the NPW!)

    You are standing at the end of a road...
    ...reminds me of days gone by,
    twinkling nights at monochrome VDUs, and
    The Soul of a New Machine

    allan

      Thanks! I'm glad to know that you enjoyed the presentation! Let me know if you have any ideas to improve it! : )

Re: Adventures in Perl 6
by Jenda (Abbot) on May 07, 2007 at 21:57 UTC

    Adventures? Boring to play, boring to write. If you do understand those "basic concepts" nferraz speaks of, you end up spending very little time writing the engine and then endless hours describing the map and the items and allowed actions and whatnot as either a datastructure or in a special format you design. If you don't ... as most people I've seen writing this type of game ... you end up spending hours and hours writing and trying to debug an insance maze of ifs and else ifs and gotos describing what can happen on what place of the map and where can you go from there.

    Though this could be a good test. Give someone a description of an adventure game world and see how they go about it. If they encode the world in the code, you don't need to know more and can part with them happily.

Re: Adventures in Perl 6
by chexmix (Hermit) on May 07, 2007 at 21:06 UTC
    Really interesting - and inspiring! I have not looked much into 6 since I'm still toiling over the fires of 5, but this gives me a nice sense of some of the things to come.
      Really interesting - and inspiring! I have not looked much into 6 since I'm still toiling over the fires of 5, but this gives me a nice sense of some of the things to come.

      About "6-now" be also sure to read Audrey's talk which I mentioned... let me see... here! Otherwise... you can ask KR! :-)

        KR ... brrrrrrrrrrrrr. I don't know, those 22 years of experience are really intimidating! :D
Re: Adventures in Perl 6
by gaal (Parson) on May 09, 2007 at 18:40 UTC
    Could you /msg me your email address? I'd like to send you a pugs commit bit so you can put your source code up in the examples area :-)
      Thanks! I have the commit bit, and copied the files to there. :-)
        Nelson++ :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://613974]
Approved by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found