The Descent of the Centipede, Part 1

In my first article on Atari’s Centipede, I did a qualitative overview of the characters and how they impact the gameplay.  Here, I want to take a more quantitative look at the game, with a particular focus on one key aspect: the descent of the centipede.

In every stage of the game, the centipede’s descent acts as a sort of ticking clock.  Whatever you might want to do, whether it be clearing out mushrooms or knocking off spiders for points, you’ll want to get it done before the centipede reaches the bottom.  Otherwise, you’ll be left to manage a flurry of fast-moving centipede heads.

The rules of the descent itself are fairly simple.  In this article, part 1, I’ll lay out these rules for the primary centipede, and then consider the effects of the spider and the flea.  In part 2, I’ll talk about the scorpion, the secondary centipedes, and the ways that the player can manipulate a centipede’s descent time.

 The Rules of the Descent

The game of Centipede is played on a 256 pixel x 240 pixel bitmap, but most of the game logic is determined within a grid with square cells, 8 pixels on a side. 

Animation showing the grid on which mushrooms are placed in the game of Centipede.

The top row of the bitmap is reserved for the player’s score/lives and the bottom row is empty, so the remaining pixels make up the 30 x 30 playing field.  When the centipede is in open space and away from the edges, it moves at a constant horizontal speed of either 15 grid cells per second (odd stages and stage 9+) or 7.5 grid cells per second (even stages up to 8).  The centipede starts its descent in the middle of the top row.

Animation showing where the centipede enters at the beginning of a level.

If it’s going left, the centipede starts in column 16 and if it’s going right, it starts in column 15.  The starting direction/cell appears to be generated randomly.

If a centipede’s horizontal motion is impeded by a mushroom or by the edge of the screen, it will descend by one row and then continue moving horizontally, opposite its original direction of motion.

Animation showing a centipede hitting a mushroom and then changing direction.

Note that centipedes will ignore any object they encounter while in the process of descending or ascending.  This means that if they hit a mushroom or the edge of the screen, they will pass through mushrooms that are immediately below them.

Animation showing a centipede passing through a mushroom when descending a row.

With these rules in hand, I have what I need to simulate a simple descent.  I started with a single centipede descending a randomly generated field of 100 mushrooms.

Simulated example of a centipede's descent using sprites from the original Atari arcade game.

The animation doesn’t match the game exactly, but the logic of the descent is the same.  How long does it take the centipede to reach the bottom?  In this particular case, it takes 904 frames, or 15.07 seconds at the arcade frame rate of 60 frames per second.  This won’t apply to all 100-mushroom fields, of course -- the answer will depend on exactly how the mushrooms are placed.  So, for the general case, it’s more interesting to look at the average descent time over many such simulations.

The animation below shows the results of running simulated centipede descents for fields with 0 to 600 randomly placed mushrooms, with 1000 simulations for each; that is, 1000 1-mushroom fields, 1000 2-mushroom fields, etc.

Animated plot showing how the centipede's descent time changes as the number of randomly placed mushrooms increases.

In the plot, “steps” are the number of grid cells that the centipede has passed through.  This can be converted to a time using the aforementioned centipede speeds.  As you would expect, the more mushrooms that are in the field, the more quickly the centipede will descend (on average).  However, as the number of mushrooms increases, the effect of adding more mushrooms decreases.  One way to think about it is to consider how much of the screen the centipede explores.  In a dense mushroom field, it will only explore a small portion of the screen, so if you add a new mushroom at a random location, the chances that it will land in the parts of the screen the centipede explores are small.

For large numbers of mushrooms, you can estimate the average number of steps without using a simulation.  For example, if there are 180 mushrooms randomly arranged in a 30x30 grid, there is a 1 in 5 (180 in 900) chance of the centipede hitting a mushroom on any given step.  It has to hit 29 mushrooms to descend the grid, so the average number of steps should be about 5 x 29 = 145.  The simulations give a slightly smaller number, about 135 steps, because they also account for collisions with the edge of the screen.

The Descent with Spiders

Now that we have a simple centipede descent working, let’s start looking at the effects of the game’s other characters.  The most visible character, aside from the centipede, is the spider.  Spiders spend a lot of time exploring the bottom of the playing field, but do they affect the centipede’s descent?

Slow-motion animation showing how the spider interacts with centipedes.

The spider does bounce off of centipede segments from time to time, but I don’t see any evidence that centipedes respond to the spider.  As such, there’s no need to worry about spider-centipede collisions when determining descent times.  

However, the spider has another role in the game: mushroom cleaner.  This might seem like a minor contribution at first, but look at what happens to the playing field when you let it evolve for 20 minutes without any intervention from the player.

Demonstration of how the mushroom field evolves in the game of Centipede if the player doesn't interact with it.

It’s clear that the spider acts to keep down the number of mushrooms in the bottom 12 rows of the playing field.  As such, this portion of the field is unlikely to ever get very dense.  To account for this effect, I added a hard cap of 12 mushrooms to the bottom 12 rows.  This limit acts to increase the descent time when the number of mushrooms is large:

Animated plot showing how the centipede's descent time changes as the number of randomly placed mushrooms increases, leaving the bottom 12 rows mostly clear.

Depending on your score, the spider’s range of influence can decrease to as little as 6 rows, which means that the amount of the playing field that’s kept clean will decrease as well.  If you don’t act to clear it out yourself, this will of course speed up the centipede’s descent.

The Descent with Spiders and Fleas

After the initial population of the mushroom field, the primary source of additional mushrooms is the action of the flea.  The flea intermittently falls across the playing field on a vertical trajectory, dropping mushrooms in its wake.

Animation showing fleas dropping mushrooms in rapid succession, from the Atari version of Centipede.

As such, when simulating high-density mushroom fields, it’s better to distribute them along columns rather than in purely random positions.  

Not all mushrooms are added by fleas, so in the top 18 rows, I combine a fixed number of randomly distributed mushrooms (30, roughly the amount appearing there in the first stage) with an increasing number of mushrooms added in columns.  The bottom 12 rows retain their previous cap of 12 mushrooms.  Here are the adjusted results.


As it turns out, distributing the mushrooms in columns doesn’t change the average descent times very much compared to the random case.  For 100 mushrooms, there’s only about a 5% difference between distributing them in columns versus randomly distributing them, with the columns taking slightly longer for the centipede to descend.  

Animation demonstrating the descent of the centipede in a field of mushrooms that were placed in columns, as done by the flea.

If the fleas were crossing in rows instead of columns, the results would be quite different.  The 100-mushroom case, for example, takes 25% longer when I put mushrooms in rows instead of columns.

In part 2, I’ll continue my look at centipede descent times, adding in the effects of the scorpion’s poisoned mushrooms, as well as look at the interactions between centipedes when there are several descending at once.

Comments

  1. Great article. Very interesting break down of one of the best arcade mechanics ever made.

    ReplyDelete

Post a Comment