This is a brief survey of the free Perl games and game utilities available on CPAN and elsewhere on the net. It’s hard to find games in Perl, in part because the module-oriented philosophy of Perl makes people more likely to distribute utilities than the standalone applications that players want. And people distributing standalone apps don’t typically advertise the language they wrote their program in, nor do they provide source code.
Most Perl games are simple affairs, either ASCII games or graphical games developed with Perl/Tk. (http://ptktools.sourceforge.net/ has a collection of Perl/Tk tools, including some card games and Tetris variants not listed here.)
If you’re a budding game designer and would like to distribute your game as a standalone application on Windows so that players don’t need to install Perl or Perl/Tk, I recommend the Perl2Exe utility at http://www.indigostar.com/perl2exe.htm.
A list of Perl utilities for strategy games follows:
There are several chess resources available for Perl programmers. On CPAN, there’s the Games::Chess module for representing chess positions and games, and Games::Chess::Referee, which uses Games::Chess to track piece movements—the start of a system that could one day be used to create chess bots.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Games/Chess/ lists three chess programs: BeholderBoard, which lets others play chess on your server, KewlChess, a two-player real-time chess game, and CGI Chess, a full-featured chess application for non-real–time games.
There’s a mailing list for Perl developers to discuss chess programs: [email protected].
Now that computers can play chess better than any human, it’s time for them to tackle Go. Two unpolished utilities on the CPAN might help: Games::Go::GMP, which speaks the Go modem protocol, and Games::Go::SGF, which manipulates Smart Go Format files.
A Perl CGI application for Concentration-style memory games: http://www.tiger-marmalade.com/~james/concentration/.
Games::AIBots is a Perl clone of the commercial game A.I. Wars, in which players build AI insects that compete with one another.
A Perl/Tk game called Kugel, a strategy game in which you arrange objects into lines, can be found at http://www.vlptel.com/~vlatko/kugel/kugel.html.
An educational game for ages 4–6: http://www.perltk.org/ex/.
In Computer Science and Perl Programming: Best of the Perl Journal, Sean Burke discussed tree data structures, and showed how they were used to create computer players for certain types of games. He demonstrated using trees for a simple strategy game called Alak, and you can see the result of his efforts in the Games::Alak CPAN module.
Games::NIM is a basic CPAN module for playing NIM (in which players alternate removing pegs, trying to be the last to do so).
You can find a Perl implementation of Conway’s game of Life at http://archive.develooper.com/[email protected]/msg00646.html.
You can find a four-line PDL version in Chapter 48.
Greg Bacon describes his Perl/Tk solitaire game in Chapter 30, but if you’re interested in utilities to create your own card games, I recommend the Games-Cards distribution on CPAN. The sample code from the documentation shows what the package lets you do:
use Games::Cards; my $Rummy = new Games::Cards::Game; # Create the correct deck for a game of Rummy. my $Deck = new Games::Cards::Deck ($Rummy, "Deck"); # Shuffle the deck and create the discard pile $Deck->shuffle; my $Discard = new Games::Cards::Queue "Discard Pile"; # Deal out the hands foreach my $i (1 .. 3) { my $hand = new Games::Cards::Hand "Player $i" ; $Deck->give_cards($hand, 7); $hand->sort_by_value; push @Hands, $hand; } # Print hands (e.g. "Player 1: AS 2C 3C 3H 10D QS KH") foreach (@Hands) { print ($_->print("short"), " ") } $Hands[1]->give_a_card ($Discard, "8D"); # Discard 8 of diamonds
The distribution also includes the Games::Cards::Tk module, which allows you to create Perl/Tk versions of card games.
There are two dice packages on CPAN: Games::Dice and Games::Die. To be
honest, I wouldn’t recommend either—not because I have any opinions
about the quality of the code, but because dice rolling is simple
enough that the overhead of subroutine calls makes it preferable to
just inline the code using rand
.
Just remember to seed the random number generator using srand
, and remember that rand(6)
returns a random floating-point
number in the range from 0 to 6. To simulate a conventional die, you’d
use this:
$die_roll = int(rand(6)) + 1;
In general, to generate a random integer between x
and y
,
use this:
$random = int(rand(y
-x
+ 1)) +x
;
A list of Perl utilities for word games follows:
There are two Perl-based cryptogram solvers: the Games::Cryptoquote module on CPAN, and cryptosolve.pl, available at http://thayer.dartmouth.edu/~rjk/perlwords/.
Various utilities for creating or accessing MUDs (Multi-User Dungeons) are at http://www.linux.org/apps/all/Entertainment/MUD.html.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Games/Crossword_Puzzles/ contains two utilities for building your own web-based crossword puzzles.
The Games::Dissociate module implements a Dissociated Press algorithm, which garbles text in amusing ways.
Games::WordFind generates Word finds from a list of words. A sample from the module’s documentation:
Words to Find: -------------- CAMEL GREAT LINUX LLAMA PERL W Z J I Q X D L R M O K Z C S T E A O I C Z V Z A M P Y I M D Y P E A M D N I C W R R C T T V L F J A G W E L L R E P O F M A W L I N U X I A S A H Q R Q D U O S G R L F O U C G N V B Y B L K U F W I
To googlewhack is to find a pair of words that has exactly one hit when searched for on Google. Some googlewhacks from http://www.googlewhack.com:
ambidextrous scallywags illuminatus ombudsman squirreling dervishes assonant octosyllable fetishized armadillo panfish interrogation
Whether these also constitute good names for rock bands is a matter of interpretation.
WebLibs is a web-based version of the “Mad Libs” party game, in which people provide adjectives, nouns, and verbs for insertion into a canned story, with humorous results (for some definition of “humor”). It’s available at http://awsd.com/scripts/weblibs/index.shtml.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Games/Hangman/ has two web-based Hangman games, in which you try to guess the identity of a word with as few letters revealed as possible. The Games::GuessWord module, available on CPAN, also provides a simple text-based Hangman game.
The Games::Jumble module creates and solves Jumble word puzzles.
Games::QuizTaker is a CPAN module for creating and taking online quizzes.
http://www.frozen-bubble.org/ is a Perl-based version of the arcade game sometimes named “Puzzle Bobble” and sometimes named “Bust-a-Move.” It’s pictured in Figure 27-1.
http://sourceforge.net/projects/davidsperlgames/ has a few ASCII-style arcade games: PerlBlaster, PerlRacer, and PerlArena.
Games::Worms is a Perl/Tk implementation of the classic Worms game, in which you’re a worm that races around trying to eat food and avoid running into yourself. Not zoologically accurate, but fun anyway.
Also on CPAN is the Games::Quake::Log module, which allows you to access the information held in a Quake logfile.
One of the original twitch computer games was SpaceWar, which ran on a venerable computer called the PDP-1. You can play it on a PDP1 assembler implemented in Perl and running under a Java emulator at http://lcs.www.media.mit.edu/groups/el/projects/spacewar/.