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

RE: computer-go: Sharing Go modules



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


Except that there is usually a test inside the loop anyway:

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

Where <WHATEVER> is OPEN, or color, or (WHITE|BLACK).  In this case (which is
most cases for me), having the possibility of a boardspace being and edge costs
nothing.