Monday, February 13, 2006

Space Properties

I've indicated that a cell is the basic unit of space. For very small spaces, this is appropriate terminology, but as the size of the space, or number of cells increases, individual cells behave more and more like geometric points, so I may also refer to points in space. It's not possible, given a finite number of points, to fully represent geometric continuity, which includes among other principles that between any two points there is another. But it is possible to come close.

It's often appropriate to give each point of space some kind of property. One example might be a checkerboard space, and each point has the property "Red" or "Black" which has the properties "red" or "black". Physical spaces may have properties such as "electric field" or "magnetic field". Any number of variants can be considered, but the most common pair of properties is "empty" and "occupied".

A space may be completely empty, but thse aren't usually very interesting. Spaces with objects are more interesting. But before I go into these, I want to consider how to set up a space.

In Object-Oriented Programming, the universe, or space, can be represented by a class. In C++, an appropriate declaration for the universe I have so far described might be:

const int EMPTY = 0;

class Space
{
private:
int cell [Y_MAX][X_MAX];
public:
int x, y;

Space();
void display();
};

This defines the space to be an array of integers. I've chosen to make the array itself inaccessible from outside the class, but the coordinates of a given cell are accessible. There are two member functions, the constructor, which sets up the space, and a display function.

These functions would implimented as:

Space::Space()
{
for (y=0; y <= Y_MAX; 1)
{for (x=0; x <= X_MAX; 1)
{cell = EMPTY;}
}
}

The display function would be as described earlier; but containing a line something like:
if (cell[x][y]== EMPTY)
[print (" ")];
or whatever function you are using for display, and however you want to represent empty space.

So, now going back to the program mentioned earlier, in the initialization where time is set to 0, you would include the line:

Space game();

At this point in the program the constructor is called and the space set up as empty. This is the only time the constructor is called. Then, in the time loop, where I have [other stuff], it's now possible to say:
game.display();
and now, the program repeatedly shows empty space.

I may have omitted a few technical details, but these depend on the particular compiler and operating system that are being used. Next time, I'll discuss putting something in space.

0 Comments:

Post a Comment

<< Home