Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Ways to maintain state in a CGI based card game

by vroom (His Eminence)
on Aug 31, 2001 at 17:00 UTC ( [id://109371]=perlquestion: print w/replies, xml ) Need Help??

vroom has asked for the wisdom of the Perl Monks concerning the following question:

For whatever reason I've decided to develop an online version of the game called Sets which I was introduced to last night.

The game goes something like this: cards are layed down in a 4x4 grid face up. Each card has four attributes: number of items on it (1,2,3), shape, color, and shading type. The goal is to find sets. A set consists of three cards which foreach of the four attributes have either:

  • a) all of a given attribute in common,
    (or)
  • b) unique/different values for a given attribute for all three cards

    An example set:
    Blue
    3 Circles
    Solid fill
    Green
    3 Triangles
    Empty Fill
    Red
    3 Squares
    Hash Fill

    Explanation: this is a set because all of the colors are different, all of the shapes are different, all of the shading/fill types are different, and all of the numbers are the same.

    Eventually I'd probably like to come up with a TK version and add lots of stats to keep track of what types of sets a given player tends to find first out of all the possible sets they could find at a given point of the game. This would possibly shed some light on the quickest/easiest type(s) of pattern matching for a given player.

    I'm looking for different ways of maintaining the game state. Storable/DB_Files seem like the obvious solution but I am also curious as to what some other alternatives might be.

    vroom | Tim Vroom | vroom@blockstackers.com

    • Comment on Ways to maintain state in a CGI based card game
  • Replies are listed 'Best First'.
    Re: Ways to maintain state in a CGI based card game
    by tachyon (Chancellor) on Aug 31, 2001 at 17:24 UTC

      All the usual suspects - hidden fields, hidden frames, cookies, session ID and serverside files or even store the data in the query string of the form action (like link parsing on a tiny scale)....

      In my opinion games are better handled in JavaScript or as a Java applet than using CGI because of the time delay and ugly refresh inherent in the CGI process.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Agreed. JavaScript or Java would be better suited for handling the game more quickly and in a more graphically pleasing fashion. I guess the stats I want to collect and my preference for Perl led me to a CGI solution. I could store information the game history in a JavaScript array or variable and then pass that along on game completion to a server side script for permanent storage and later analysis.

        vroom | Tim Vroom | vroom@blockstackers.com

          Yes the question is often not "Could I do this in Perl?" but "Should I do this in Perl?" You can always do it in Perl! And you know once it is done you don't have hours of cross browser testing, tweaking, more testing, more tweaking, more testing..... to go :-)

          cheers

          tachyon

          s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

    Re: Ways to maintain state in a CGI based card game
    by dragonchild (Archbishop) on Aug 31, 2001 at 17:21 UTC
      A really easy way would be to assign 2 bits to each attribute, giving you an 8-bit number for each card. Just like you do right now for PM, you could just pass around 16 numbers back and forth in the URL. That would maintain the state of the board.

      Having not played the game (heard about it, though!), I don't know what else you would need to maintain knowledge of ....

      ------
      We are the carpenters and bricklayers of the Information Age.

      Vote paco for President!

    Re (tilly) 1: Ways to maintain state in a CGI based card game
    by tilly (Archbishop) on Aug 31, 2001 at 19:00 UTC
      You might want to take a look at japhy's Set, online. (He did it client-side though, not server-side.)
        As tachyon was saying, about the perils of client side programming, this client side version of Set does not work in my copy IE 5.0.
        Javascript error

        -Lee

        "To be civilized is to deny one's nature."
    Re: Ways to maintain state in a CGI based card game
    by princepawn (Parson) on Aug 31, 2001 at 18:34 UTC
      well, the title says "CGI-base", but the post says "eventually Tk as well"... and this bringsup an fascinating point.

      How to make portable sessioning code? because if you were in mod_perl, I'd say Apache::Session, but then outside of mod_perl, well I dont really know. The Stein/maceachern book on mod_perl lists a total of 6 ways of doing this, but I can't imagine any of them appplying to Tk... as state is usually resident within the single process that a Tk program runs in.

    Re: Ways to maintain state in a CGI based card game
    by perrin (Chancellor) on Aug 31, 2001 at 18:49 UTC
      Storable/DB_Files are not only obvious - they're a good solution! However, you might want to try using MLDBM::Sync, which will take care of locking issues for you. You could also use one of the Cache::Cache modules. The one that uses a tree of files for storage is especially good for applications with many simultaneous users since it does separate locks for each entry. (Row-level locking!)

      If this were a big commercial site, you would naturally want to use a RDBMS for reliability and scaling, but these simpler methods are easier and faster for a personal project site.

    Re: Ways to maintain state in a CGI based card game
    by suaveant (Parson) on Aug 31, 2001 at 18:16 UTC
      Hehe, yeah, that is a cool game.

      But you should make it PerlSet... and use Camels, Llamas and Penguins for your shapes... :)

                      - Ant
                      - Some of my best work - Fish Dinner

    Re: Ways to maintain state in a CGI based card game
    by synapse0 (Pilgrim) on Sep 01, 2001 at 02:58 UTC
      Just another suggestion..
      One thing you could possibly try is make the game itself in Java (and TK for a non-web based version) and have the game connect to a Perl server somewhere that does all the stats gathering/analysis. That way you can have both an online and offline version. The offline version could store the stats until it can connect and hand them over to the analysis server.
      Anyways..
      -Syn0
    Re: Ways to maintain state in a CGI based card game
    by a (Friar) on Sep 02, 2001 at 08:37 UTC
      Just to give a link:
      http://dev.scriptics.com/software/plugin/match.html
      is the tcl version (I believe) from long ago. Don't go there unless you've got time, it is a maddeningly addictive game and the tcl version is a thing of beautiful simplicity. Oh, you'll need the tcl plugin for your browser though. ;->

      a

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlquestion [id://109371]
    Approved by root
    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-19 13:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found