PySweeper: Getting Started 5

Posted by tottinger Fri, 09 Feb 2007 21:35:00 GMT

It’s time for me to do a little code cleaning. I keep talking about open source, but lately it’s been all hat and no cattle (well, other than an unreleased FitNesse change I helped with). I looked for something fun involving Python. I figure I will learn pygame and eclipse PyDev and see what I can learn and teach from the experience.

I have chosen a simple little game called PySweeper. PySweeper is a minesweeper-like game copyright 2002 by Brett Smith. It is very much like the famous MineSweeper game one might find on a Windows computer (remember Windows?).

I confess to never having played minesweeper, so I actually learned the rules by reading the code. If you play minesweeper, feel free to skip the next paragraph.

The playing field is a grid of squares. Under some squares there are hidden mines (one per square) and under others there are not. The idea is that you click on a square on the grid. If you click on a mine, you are blown up and the game is over. If the square does not have a mine, but is adjacent to one or more cells that have mines, it will open up to show a count of mines present in the surrounding cells. The cell does not indicate the direction of the mine. These counts are the only clues you get as to the location of the mines. If the cell you choose is not adjacent to any mines, it will show up blank and will open all its adjacent cells. The adjacent cells act as if they are clicked on, and either show a count of mines nearby or else show a blank and open their neighbors. Sometimes one click can show you quite a lot of clues. If you believe you know where a mine is, you can mark it with a flag by right-clicking. If you correctly guess all the positions of all the mines, then you win.

Since Mr. Smith put PySweeper under the GPL I have permission to change it, publish it, and use it for whatever purposes I choose provided I pass on the same freedoms to the people who use my version of the code, and provided I make the source available when i distribute its executables. This just another way in which the GPL is a good idea. I couldn’t do this without accessing, modifying, and publishing the code, so I am most grateful to B.Smith for providing me with a solid starting point.

I am an XUbuntu (Edgy Eft) user right now, so I installed my Eclipse PyDev plugin via the wonderful Debian Advanced Packaging Tools (APT). I don’t know people live without APT. It’s the best way I’ve ever seen for managing the software on my computers. With APT, I don’t have to go looking for software to install. I don’t have any dependency problems (“dll hell” in windows parlance. I can install and uninstall all the software I want and it doesn’t make my computer slow down or get sick or die. I can very easily get upgrades (security as well as feature releases) to everything I’m running all through the same system with a single command. I have a vast catalog of software available to me for free. It’s glorious. Thanks to the Debian project for the wonderful work. Someday I must look into the code for that.

I download a compressed tar archive (.tgz) of the PySweeper-1.0 source code. I start by unzipping the code into my project directory and then I fire up up Eclipse and Pydev. Poor Pydev doesn’t know if I want to use the C python implementation, Jython (java), or something else entirely. I take a moment to configure it. It’s not hard or confusing. Now I fire up Eclipse again to see if it understands my python code. Well, it almost does. The main file of pysweeper is called “pysweeper”, with no ”.py” extension. Surely, if eclipse used the Linux file command, it would know that it’s looking at a Python program, but apparently it does not. There is no syntax highlighting at all. I sigh. Just to start the ball rolling, I rename the file “pysweeper.py” and load it up. Much better.

The default Python syntax highlighting feature is pleasing to me. Comments are a pale gray on a white background so it is easy to skip them. Mr. Smith spent some time writing comments to explain his code, but I want the code to talk to me. I might delete all but the licensing and authorship docs.

Next installment, I’ll play with the environment and get a start on cleaning some code.

Trackbacks

Use the following link to trackback from your own site:
http://blog.objectmentor.com/articles/trackback/157

Comments

Leave a response

  1. Avatar
    Tenant Screening over 4 years later:

    I have a vast catalog of software available to me for free. It’s glorious. Thanks to the Debian project for the wonderful work. Someday I must look into the code for that.

  2. Avatar
    polo cheap over 4 years later:

    polo cheap

    sale polo shirts

  3. Avatar
    okey oyunu oyna over 4 years later:

    heyy nice post…

    Dünyan?n en büyük online okey oyunu bu sitede sizleri bekliyor. Gerçek ki?ilerle sohbet ederek Okey Oyunu Oyna ve internette online oyun oynaman?n zevkini ç?kar

  4. Avatar
    sac longchamp over 4 years later:

    Il n’est pas un rêve de posséder un sac longchamp, il vous faire plus de beauté, peut-être vous êtes maintenant wating pour cette journée, et un sac de grande qualité, parfois vous faire sentir à l’aise, si vous sortez avec un escompte longchamp pas cher, vous serez amusant tout de suite, ce n’est pas un rêve, les sacs longchamp pas cher vente peut faire venir vrai!

    sac longchamp est une marque célèbre dans le monde, beaucoup de filles toujours changer leurs sacs sans aucune réflexion, mais un prix élevé des sacs de mode peut être une question pour eux. Ne vous inquiétez pas! longchamp sac à vendre fournir des produits bon marché avec tout le monde de haute qualité, c’est une bonne chance, les sacs longchamp pas cher vous donnera un moment mémorable.

    Bienvenue à Sac Longchamp Pas Cher, il ya beaucoup de produits, les gensaiment toujours à choisir Sac Longchamp Solde de haute qualité et bas prix ainsi queun bon aper u. Un sac de marque mondialement connue sac a main longchamp peut être votre premier choix. Ils peuvent vous être plus de confiance et que vous vous sentiez à l’aise.

  5. Avatar
    beats by dr dre studio over 5 years later:

    Designed with unique features that you won’t find on ordinary beats by dr dre pro detox with the Beats by Dr. Dre Studio headphones you not only get incredible sound, but advanced, useful function to make your listening experience the best it can be. With advanced speaker design, powered amplification, and active noise canceling, the headphones delivers all the power, clarity and deep bass today’s top artists and producers want you to hear.

Comments