next up previous
Next: Implementation Up: Pre-Processing Strategies Previous: Edge Matching

Pixellated Fitting

The pixellation strategy is a way to simplify the problem by reducing a cookie from an object in a continuous space to a discrete object. The pixels can then be manipulated according to a simple algorithm to try to fit shapes together in an intelligent way. There is of course some overhead in doing this, since the pixellated representation of the cookie is generally bigger than the cookie itself. However, as the number of pixels in the pixellation increases, the amount of overhead decreases (in the limit, using an infinite number of pixels would produce zero overhead).

This strategy works by first determining the number of pixels to use to represent the cookie. In our player, we use a 250x250 square of pixels, since this affords low overhead while still being computationally reasonable.

Once the pixel size is determined, a pixellated representation of the shape is formed. Each pixel is a square, and if any of the boundary lines of the shape intersects any of the boundary lines of the square, this pixel is said to be on the border of this shape, and is set to on. Any pixel that is not set by this process is off.

Here is an example of a shape and its pixellation:

Figure 1: Group 1 cookie
\includegraphics[scale=0.3]{puzzle.eps}
Figure 2: Group 1 cookie pixellated
\includegraphics[scale=0.3]{pix.eps}

Now, the job of matching up two cookies is reduced to the job of overlaying the pixellated representation of the cookie in many positions to determine which is best. For simplicity, we look only at the simple case of overlaying two cookies; a more advanced approach would endeavor to overlay many cookies in many different arrangements to try to find the best solution.

When overlaying two cookies, we hold the first cookie's pixellation fixed, and move the second pixellation over it. Specifically, we overlay the pixellations identically and then sweep once downward and once rightward, comparing each overlaid row until we found that all the rows fit into one another (to fit into one another, each pixel comprising the first cookie must not overlap any pixel comprising the second). We also perform a 180-degree rotation and repeated the process, so that we find cases where the cookie is approximately a mirror images of itself.

In the above example, we begin by taking two copies and overlaying them. They necessarily do not match. So we hold one pixellation fixed and slide the second downward one row at a time until we find that all the rows fit into one another. In this case, all the rows fit when row 0 overlays row 75. Thus we know that we can offset the second shape by 75 times the height of one pixel, and the shapes will fit together, since the pixellation represents a sort of bounding box for the shape.

When we had two cookies overlayed in an intelligent way, we create a CookieGroup with the two cookies in the arrangement that we found. We then pass this CookieGroup to a placer to arrange. This strategy works well because often, the cookies are regular enough that if one finds a strong arrangement of two cookies, it's easy to find a strong overall placement.

The pixellating process could be improved by looking at a variety of rotations of the cookie and matching them against one another. For example, 360 different cookies, one for each degree of rotation, might be pixellated and then all compared against one another. Separately, translations involving both an $ x$ and $ y$ offset might be considered; this would handle the case of the spiral, where an $ x$ and $ y$ offset combined will produce overlap, but separate $ x$ and $ y$ offsets will not. An exhaustive search of all these possibilities would be more computationally intensive, and perhaps a random sampling of the possible pairings could achieve similar results.


next up previous
Next: Implementation Up: Pre-Processing Strategies Previous: Edge Matching
2003-10-14