Wednesday, July 20, 2005

PyroWorm Game

Most programmers write software for other people to use. But as an engineer, most of the programs I wrote were customized tools for me to use. (But some tools were more general-purpose, and I made these available to others to use.) I thought of the computer as a mental lever, or as a robot that would do all the hard work. But sometimes, at home, I used programming for fun and games.

Once I got the idea to combine two simple games that others had created. One of them, John Conway's Game of Life (See here and here) is not really a game, although it has rules, and pieces on a board that come and go according to the rules. The board is like a chess board, but with many more rows and columns, and the rules are much simpler than chess. If you program a computer to play this 'Game of Life', you can populate the board with pieces any way that you like, then watch the computer 'play the game' according to the rules, and see what happens. If you haven't seen it, that may sound boring -- but it really is fascinating, because in spite of the fact that the rules are so simple, the moving patterns are surprisingly life-like -- hence the name. Ragged asymmetrical patterns grow into beautifully symmetric objects. Patterns glide across the board, collide with other patterns, and are either destroyed, or morph into new patterns. It is more a spectator sport than a real game.

I wrote a program to do this, and it was fun to watch, but always, after an interval of interesting activity, the 'game' would end with a mixture of static, unmoving patterns and moving patterns that would repeat the same motions over and over again. It seemed to me that it needed some kind of spark that could rekindle the interesting activity whenever it died down.

As I began to experiment with this rekindling idea, it seemed that the moving patterns were like a wild-fire. When the patterns expanded, it was like fire spreading; and when the patterns drifted sideways, it was like wind was moving the fire. I modified the program so that when a piece on the board was not there in the previous change-cycle, it would be colored bright red; but if it had been there in the previous change-cycle, it would be colored a dull red, nearly brown. Thus, an active 'fire' was flashing bright red, but a static pattern of 'ashes' was the brownish dull red.

I recalled a simple game that was available on the Unix computers, called 'worm' (similar to this). It, too, was played on a board with many rows and columns. The worm was a string of pieces, like a string of pearls, made of the letter 'o', with a capital 'O' for the head, like this: ooooooO. The computer could make the worm move by adding a piece at the 'head' end and removing a piece at the 'tail' end. What you had to do was to steer the worm's motion, using the arrow keys of the computer's keyboard. A numeral from 1 to 9 would appear at a random location on the board; and if you could steer the worm to 'eat' the numeral, then the worm would grow longer by that amount. The computer could make the worm grow by adding pieces at the 'head' end without removing pieces at the 'tail' end. So the length of the worm was your score.

Now, if the worm bumped into itself or the walls (the edges of the board), the game was over. And as the worm grew longer, that was harder to do -- you had to learn strategies of winding up in the crowded space without making any fatal collisions. But in a more forgiving version of the game, collisions were not fatal. Instead, the penalty for collisions was that the worm would shrink. The computer could make the worm shrink by not adding pieces at the 'head' end while removing pieces at the 'tail' end. The only way this form of the worm game could end was for the worm to shrink down to nothing.

So I thought, why not use the worm to rekindle the fire? And to make the game more dramatic, the worm would need to avoid collisions with the fire, that is, getting burned. The worm would shrink if it touched a bright-red 'fire' piece, but would grow if it touched a dull-red 'ashes' piece, igniting it. But since the worm's head would always touch a piece first, and then the rest of its body would be dragged over that spot, it had to be that the 'ashes' would be ignited when the tail touches (or moves off) the ashes, not the head. I wanted the worm to play with danger, not be suicidal. It's hard enough staying away from the fire, so I removed the penalties for the worm bumping into himself or the edges of the board. In a way, there are no edges, because if you try moving off the right edge, you 'wrap around' and show up at the left edge; and likewise, the top and bottom edges are joined.

I made the worm a light green against a darker green background (grass: wwww). His head was a sunny yellow smiley-face, but when burned, the burned part of the body would turn black and the face turned red.

It turns out that these simple, but crazy rules make a very exiting game. To get a high score, you have to make the worm grow, and to do that, your worm has to start fires -- then run away from them. If you get too greedy, and start too many fires, there may be too little safe ground left and your worm will be fatally trapped. The worm is obviously a pyromaniac, so I named the new game PyroWorm.

You can download my game for free. Just click on PyroWorm Game and read about it, and scroll down to the Download section.

No comments: