Nibbles
Com S 476/576 FINAL PROJECT - Spring 2000

Randy Heit and Sarah Kabala


Project Description

In the game of Nibbles a "worm" is controlled by a player who steers it around obstacles to some goal location where it eats a fruit or some such reward. Then the length of the worm increases as the player must go after another randomly located "fruit" while avoiding obstacles in the environment. The worm moves at a constant forward speed of one worm segment per time unit. It is the user's job to change the worm's direction so that it does not plow into an obstacle or into itself. When the worm eats a fruit its length increases.

We sought to create a motion strategy for a computer player of Nibbles. Classically, the world of the problem is discretized and the worm can only move north, south, east, or west. However, we expanded the definition of our 2D configuration space to allow 360-degree vector (of length one worm segment) translation of the head and polygonal obstacles. This made the use of an RRT advantageous over a PRM because the world (and conficguration) space was no longer discretized.

The Extend() function of the RRT had to be modified to prevent the worm from colliding with itself. Trailing segments are positioned such that the i-th segment from the head is in the same configuration as the head was i time units ago. (It moves like a snake.) This meant that worm_length-1 segments located at the nodes in the RRT on the path from the current new_node back to the initial node (and if necessary back into the worm's initial configuration state) must be added to the obstacle region when the configuration of new_node is tested for collision. That was the challenge of this problem, making stopping the worm from hitting itself while using an RRT (for the head) to find a path to the goal state.

When the worm gets long and it is in a cramped space it sometimes cannot find a path to the goal state. The worm can get trapped. However, by "following" the walls of the obstacle region the number of failures is greatly reduced because trailing segments are less likely to get in the way when the worm needs to move back in the same way that it came.


Computed Examples

We tried to create an animated gif of our program, however it contained many (over 200) frames and the pstogif command would not work. So we took snapshots of its operation at important moments during the worm's solution of a particular obstacle level.

As you can see, the worm avoids its tail while following a path to the next green fruit. The head of the worm is red. After consuming nine fruits and growing nine times, the worm would advance to the next level.

Implementation Files

We are sorry that it is not convenient for this HTML file to be in the same directory as the program files. All project files other than this report can be found in the directory http://www.cs.iastate.edu/~rheit/worm/

Source Code:

Input Data Files: