John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

A working version of Skunk is found at http://www.dlugosz.com/Skunk1.zip.

This plays the game properly, and defines a framework for adding statagy ("player") modules.

I'd love to hear feedback about the overall design and the extension mechanism. The idea emplyed here is to return a meta-object structure (hash) as the return from require, that contains items for doing things rather than member function in the usual way, so you don't need two different classes (one for the meta object, one for the real player) or obfuscating things by putting all the members in one class. I figure the usual meta-object will be a copy/paste from the sample with filling in the NAME etc.

Based on any feedback (and sleeping on it), I'll finalize the interfaces and write some proper documentation.

—John

Replies are listed 'Best First'.
Re: Skunk Game - first cut
by hydo (Monk) on Jun 21, 2003 at 11:24 UTC
    That's really really cool. I especially like the constant "COWS_CAME_HOME".

    Anyway, with reguards to the meta objects, I should really pull my head up out of the sand once in a while because I've never seen extensions approached this way. I have a medium sized application that I have been working on for some time and I admit it uses nothing this elegant when it comes to it's extensions.

    Thanks!

      Thanks. Speaking of Cows, the first time playing after tracking down some real skunk dice, I was playing with my little nephew and my dad. When he had to leave for a moment, I switched one of the skunk dice for a cow die. Daniel could barely conceal his excitement at the joke, and sure enough, dad rolled a Cow on his next turn, and played it up nicely.

      Seriously, I'm glad you like the extension mechanism. I'm not convinced that it's "elegant" in a large software engineering sence -- it should use normal Perl objects. But I think this is handy in reducing the amount of work that needs to be done, and avoiding the need to put more than one package in a file. So it's "elegant" in some other sence of the word, like a perl -e line that lets you replace a whole program with a one-liner.

Re: Skunk Game - first cut
by particle (Vicar) on Jun 22, 2003 at 14:03 UTC

    i haven't had much time to look this code over, but i noticed that you're forcing 5.008. i know that constant has extended syntax in that release, so you can do something like:

    use constant { ANTE => 5, DOUBLE_SKUNK_PENALTY => 5, POINTS_TO_WIN => 100, # as long as I'm making it flexible... COWS_CAME_HOME => 10000, # protect against all players getting into + a state where they always roll until skunked. };

    which i think is somewhat cleaner than the old syntax.

    ~Particle *accelerates*

      Many thanks. I wished I could do that, and tried to do that in the past, but didn't realize that it was enhanced now.

      —John