old-www/LDP/LG/issue33/ayers2.html

162 lines
7.5 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>A New Python-Based Solitaire Game LG #33</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<h1><font color="maroon">Pysol: Python-Powered Solitaire</font></h1>
<h4>By <a href="mailto: layers@marktwain.net">Larry Ayers</a></h4>
</center>
<P> <HR> <P>
<center><h3>Introduction</h3></center>
<p>Playing solitaire card games on a computer became popular when Microsoft
bundled a Klondike game with Windows 3.1. Since then such programs have
proliferated on nearly every platform which possesses a windowing interface.
There is a certain appeal to dragging miniature representations of playing
cards around the screen. A side benefit is that such games usually can keep
track of scores, provide hints, and sometimes auto-play in demo mode.
<p>There have been many solitaire games released for Linux. One of the older
ones is xpat2, which has some of the nicest design-work of any of these games.
Xpat2 shows its age due to the lack of card-dragging, which contributes
greatly to the feel of a computer card-game. Clicking on a card instantly
moves it to a legal destination; when there is more than one possible
move, the one xpat2 chooses may not be the one you had in mind. Otherwise
it's a fine game, with several solitaire variants to choose from and well-done
on-line help.
<p>Users of the GNOME and KDE desktop environments each have native solitaire
games, both of which are quality applications. If you aren't a user of one of
these desktop systems it's hardly worthwhile to keep the bulky shared
libraries around just to play a simple game.
<p>Recently I was browsing the incoming directory at the Sunsite FTP site; I
happened across a small file which, according to its accompanying *.lsm file,
purported to be an implementation of solitaire called Pysol written in the
Python programming language. I was a little dubious of this claim. Python is
a versatile and powerful interpreted programming language, but is it possible
to write a card-game using Python which is as usable and pleasing to the eye
as one written in C or C++?
<p>It evidently is possible if the <i>tkinter</i> module is used to provide
the graphical interface. <i>Tkinter</i> (which I assume stands for "interface
to Tk") lets a Python script use John Ousterhout's versatile Tk toolkit to
provide the windowing interface. Tk is normally used with the Tcl command
language, but Tcl has several limitations. These have been sufficient to
provide motivation for several replacements; <i>Tkinter</i> is widely used,
but there are others. <i>Perltk</i> uses Larry Wall's Perl language as the
command language; another is <i>Stk</i>, which uses Scheme as its scripting
language. The Xxl spreadsheet is the first major project I've seen which uses
this Tk/Scheme hybrid. (Perhaps I'll review Xxl one of these months).
<p>Pysol was written by <a href="mailto:
markus.oberhumer@jk.uni-linz.ac.at">Markus F.X.J. Oberhumer</a> and he has
released it under the GNU license. The game is an extensive reworking and
enhancement of a simple Python solitaire demo written by Guido van Rossum
(creator and maintainer of the Python language) which is included as an
example in the Python distribution.
<center><h3>Features and Game-Play</h3></center>
<p>Here is a list of
Pysol's features, adapted from the README file in the distribution:
<ul>
<li>It's based upon an extensible solitaire engine
<li>A very nice look and feel
<li>Unlimited undo & redo
<li>Pysol can load & save games
<li>Player statistics are available
<li>Hints for possible next moves
<li>Demo games
<li>HTML-based help browser
<li>Playable under all platforms which TK and Python support, including
MacOS, Windows, and of course X11
</ul>
<p>Nine games can be played: Gypsy, Picture Gallery, Irmgard, 8X8, Freecell,
Seahaven,Braid, Spider, and Forty Thieves. The rules and documentation are
supplied in HTML format and are displayed in a separate window using a Python
HTML extension. Card-dealing at the onset of a game is nicely animated, and
the mouse-dragging of cards works smoothly.
<p>If you have ever spent much time playing solitaire on a computer you
probably have noticed that after a certain point in a game the outcome seems
obvious. This intuition isn't always accurate when you suspect the game is
lost, but sometimes it's obvious that several more card-moves will win the
game. Pysol binds the <i>a</i> key so that, when pressed, it will
automatically cycle through those moves and bring the game to completion.
When you strongly suspect that the game can't be won, the menu-item
<i>Demo</i> (in the <i>Game</i> menu) will ask if you want to abandon the
current game; pressing the "Yes" button will start the demo mode and either
finish the game or find that it can't be completed. I've found that about
one-quarter of the times I resort to demo mode my intuition was wrong and the
game could have been won. If a game is hopeless a pop-up window appears
informing you that "This won't come out".
<p>Pysol's help key is <i>h</i>; when it's pressed a black arrow appears extending
from a card to a recommended destination. The same arrows appear when Demo
mode is initiated, though in this case the cards are actually moved.
<p>Here is a screenshot of a Pysol Klondike game:<br>
<p><center><img alt="Pysol Window" src="./gx/ayers/pysol.gif"></center>
<hr>
<center><h3>Installing Pysol</h3></center>
<p>Pysol won't work at all if you don't have a current Python installation,
including the <i>tkinter</i> module. A current Linux distribution will
include all the Python stuff you would ever want, it's just a matter of
installing it. As far as that goes, Python is one of those high-quality
applications which is very likely to compile well from source, assuming you
have the basic Linux development packages installed, such as gcc, make, etc.
<p>Pysol is just a 75-kilobyte executable Python script; running <kbd>make
install</kbd> will copy the script to <kbd>/usr/games</kbd> and the necessary
data-files to <kbd>/usr/share/pysol</kbd>, after which the game is ready to
run.
<p>I'm impressed by this game's quality and playability. It <em>does</em>
take several seconds to start up, probably due to the necessity of loading the
Python interpreter and the Tkinter module into memory.
<hr>
<p>
<!-- hhmts start -->
Last modified: Mon 28 Sep 1998
<!-- hhmts end -->
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, Larry Ayers <BR>
Published in Issue 33 of <i>Linux Gazette</i>, October 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./ayers1.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./ayers3.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->