line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Games::Worms; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
require 5; |
5
|
3
|
|
|
3
|
|
27687
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
155
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
3
|
|
|
3
|
|
153
|
use vars qw(%Options $VERSION $Debug @ISA @EXPORT @EXPORT_OK); |
|
3
|
|
|
|
|
28
|
|
|
3
|
|
|
|
|
312
|
|
8
|
3
|
|
|
3
|
|
12501
|
use Getopt::Std; |
|
3
|
|
|
|
|
858
|
|
|
3
|
|
|
|
|
335
|
|
9
|
3
|
|
|
3
|
|
2536
|
use Games::Worms::Board; # for _try_use |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
1397
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = "0.65"; |
12
|
|
|
|
|
|
|
$Debug = 0; |
13
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
@EXPORT = qw(worms); |
15
|
|
|
|
|
|
|
@EXPORT_OK = qw(worms); |
16
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Games::Worms -- alife simulator for Conway/Patterson/Beeler worms, etc. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tPS |
25
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tPS / / / / > foo1.ps |
26
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tTk |
27
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tTek4010 / / / Games::Worms::Random2 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 BUGS, WARNINGS, AND CAVEATS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This is an alpha release. The documentation is incomplete, and the |
32
|
|
|
|
|
|
|
interface is not yet finalized. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Occasionally I've seen Perl 5.004_02 for MSWin segfault at global |
35
|
|
|
|
|
|
|
destruction time. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The Tk part, I've only tested under pTk. This's my first hack at Tk, |
38
|
|
|
|
|
|
|
so lets hope all the code I wrote is portable. Suggestions welcome! |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
I've tested the PostScript part only under GhostScript. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
I've tested the Tek interface under MSKermit. I hear xterm has a Tek |
43
|
|
|
|
|
|
|
emulator in it -- I'd be interested to hear if it works well with |
44
|
|
|
|
|
|
|
Worms's Tek interface. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
[elaborate] |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Worms is an implementation of an artificial-life game. It can output |
51
|
|
|
|
|
|
|
via Perl-Tk, Tek4010, and PostScript. It is a game not in the sense |
52
|
|
|
|
|
|
|
of checkers, but in the sense of Conway's Life. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
In a Worms universe, worms crawl around an isometric grid of |
55
|
|
|
|
|
|
|
triangles, leaving trails behind them, and turning in accordance to |
56
|
|
|
|
|
|
|
simple rules that are based upon which way they can move at a each |
57
|
|
|
|
|
|
|
junction. From the simple rules emerges surprising complexity. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 TO DO |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Allow board-size specifications on the command line. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Better docs. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Maybe a GIF output mode? |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
More interactive interface in pTk mode? |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Currently the interface is pretty much: specify things on the command |
70
|
|
|
|
|
|
|
line, then sit back and watch the worms go, until they all die. |
71
|
|
|
|
|
|
|
Hopefully I (or someone ambitious who knows Tk better than I do) may |
72
|
|
|
|
|
|
|
add more interactivity to the interface. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 INVOCATION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Start it up by making a Perl program called C, with the content: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
!/usr/bin/perl |
79
|
|
|
|
|
|
|
use Games::Worms; |
80
|
|
|
|
|
|
|
worms; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Then start up with the C<-t> switch specifying which interface to use: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
worms -tTk |
85
|
|
|
|
|
|
|
...for Tk mode |
86
|
|
|
|
|
|
|
worms -tPS |
87
|
|
|
|
|
|
|
...for PostScript mode |
88
|
|
|
|
|
|
|
worms -tTek4010 |
89
|
|
|
|
|
|
|
...for Tektronics mode |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Command line arguments thereafter are interpreted as the names of |
92
|
|
|
|
|
|
|
classes worms should come from. (Currently, three are provided in |
93
|
|
|
|
|
|
|
this distribution: L, L, |
94
|
|
|
|
|
|
|
and L.) If no arguments are provided, Worms |
95
|
|
|
|
|
|
|
uses two Random2s and two Beelers. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
For each name you specify, if it contains a slash, the rest of that |
98
|
|
|
|
|
|
|
name is passed to the worm as an expression of its rules. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Example specifications: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Games::Worms::Beeler |
103
|
|
|
|
|
|
|
Games::Worms::Random |
104
|
|
|
|
|
|
|
Games::Worms::Random2 |
105
|
|
|
|
|
|
|
Games::Worms::Beeler/1a2d3caaa4b |
106
|
|
|
|
|
|
|
Games::Worms::Beeler/1A2B3ACAC4B |
107
|
|
|
|
|
|
|
Games::Worms::Beeler/1B2B3AAAB4A |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
(A Beeler worm with no rules specified makes up a random rule set when |
110
|
|
|
|
|
|
|
it starts. A Random worm obeys no rules. A Random2 worm is random |
111
|
|
|
|
|
|
|
but consistent.) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
If you specify a name starting with '/', it's interpreted as short for |
114
|
|
|
|
|
|
|
'Games::Worms::Beeler/'. In other words, |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
/1a2d3caaa4b equals Games::Worms::Beeler/1a2d3caaa4b |
117
|
|
|
|
|
|
|
/1A2B3ACAC4B equals Games::Worms::Beeler/1A2B3ACAC4B |
118
|
|
|
|
|
|
|
/1B2B3AAAB4A equals Games::Worms::Beeler/1B2B3AAAB4A |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
See the I article on Beeler worms for the meaning |
121
|
|
|
|
|
|
|
of these Beeler worm rule specifications. I don't have the citation |
122
|
|
|
|
|
|
|
for the first run of the article, but it's reproduced with nice |
123
|
|
|
|
|
|
|
addenda in the book cited below. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
If you don't want to bother making that little script called "worms", |
126
|
|
|
|
|
|
|
you can just as well invoke Worms via: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tTk |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tPS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tTek4010 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
perl -MGames::Worms -e worms -- -tTek4010 |
135
|
|
|
|
|
|
|
Games::Worms::Random Games::Worms::Random2 |
136
|
|
|
|
|
|
|
/1a2d3caaa4b /1A2B3ACAC4B /1B2B3AAAB4A |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 CONCEPTS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
[to be written] |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 REFERENCES |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
"Worm Paths", chapter 17 in: Martin Gardner, 1986, I
|
145
|
|
|
|
|
|
|
and Other Mathematical Entertainments>, W. H. Freeman and Company. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
"Patterson's Worm", M. Beeler, MIT AI Memo #290. (early 1970s?) |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
"Worms?" [sic], David Maynard, Electronic Arts, 1983. (A game for the |
150
|
|
|
|
|
|
|
Atari 400 (or 800?), the Commodore 64, and maybe other machines. |
151
|
|
|
|
|
|
|
Games::Worms isn't based on EOA "Worms?", but "Worms?" is the best |
152
|
|
|
|
|
|
|
known implementation of Beeler worms. It uses them as the basis for |
153
|
|
|
|
|
|
|
a very interesting and abstract interactive game.) |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 GUTS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Read the source. It's OOPilicious! |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Copyright 1999-2006, Sean M. Burke C, all rights |
162
|
|
|
|
|
|
|
reserved. This program is free software; you can redistribute it |
163
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Current maintainer Avi Finkel C; Original author Sean M. Burke C |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
%Options = (); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub worms { |
176
|
0
|
|
|
0
|
0
|
|
getopts('t:vh', \%Options); |
177
|
0
|
0
|
|
|
|
|
if($Options{'v'}) { |
178
|
0
|
|
|
|
|
|
print "Worms v$VERSION\n"; |
179
|
0
|
|
|
|
|
|
exit; |
180
|
|
|
|
|
|
|
} |
181
|
0
|
0
|
|
|
|
|
if($Options{'h'}) { |
182
|
0
|
|
|
|
|
|
print <<"EOHELP"; exit; |
|
0
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Worms v$VERSION |
184
|
|
|
|
|
|
|
Switches: |
185
|
|
|
|
|
|
|
-t[Interface] -- set the interface |
186
|
|
|
|
|
|
|
examples: -tTk -tPS -tTek4010 |
187
|
|
|
|
|
|
|
-h -- print this help message |
188
|
|
|
|
|
|
|
-v -- print the version number |
189
|
|
|
|
|
|
|
EOHELP |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
die "What interface?" unless $Options{'t'} =~ /\w/; |
194
|
0
|
|
|
|
|
|
my $interface = "Games::Worms:\:$Options{'t'}" ; |
195
|
0
|
0
|
|
|
|
|
die "Can't use interface $interface: $Games::Worms::Board::Use_Error\n" |
196
|
|
|
|
|
|
|
unless &Games::Worms::Board::_try_use($interface); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# add further %Options logic here. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# Now do it. |
201
|
0
|
0
|
|
|
|
|
die "Can't start up interface $interface!\n" unless $interface->can('main'); |
202
|
0
|
|
|
|
|
|
return $interface->main; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |