[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: computer-go: Sharing Go modules



At 12:56 PM 5/17/2001 +0200, you wrote:

I also have an array with the distance to the edge of each point in it. But
my program has a lot of code that does something like:

 if (board[left(xy)] == board[xy])
        doSomething(left(xy));
One more follow-up. I checked, and my code has 825 uses of the edge[] array, and
268 of them compare the value to 1. But I imagine in your case that there are
times when you check if(left(xy) == OFF_EDGE).

What does your code look like for iterating the neighbors of a point? I imagine
something like:

int ofs[4] = { -1, 1, 20, -20 };

int xy; /* center point */
int nbr; /* adjacent point */
for(int i = 0; i < 4; ++i){
nbr = xy + ofs[i];
if(board[nbr] == OFF_EDGE)continue;
/* do something */
}

I have a larger offset array, with 52 entries, and an array with 361 entries that gives
the starting offset index for each point, and an array of 52 entries that gives the ending index (+1)
for each starting index, so my loop is:

int ldtmp;
int i = fdir[xy];
for(ldtmp = ldir[i]; i < ldtmp; ++i){ /* look at neighbors */
nbr = xy + ofs[i];
/* do something */
}

This avoids the test for off-board inside the loop at the cost of two array lookups outside the loop, and is
probably faster.

David