Java Reference
In-Depth Information
destinationBoard[row][col] = true;
if (numberOfNeighbors < 2)
destinationBoard[row][col] = false;
if (numberOfNeighbors > 3)
destinationBoard[row][col] = false;
} else {
destinationBoard[row][col]
= false;
if (numberOfNeighbors == 3)
destinationBoard[row][col] = true;
}
}
}
}
private int getNumberOfNeighbors(int row, int
col) {
int neighborCount = 0;
for (int leftIndex = -1; leftIndex < 2;
leftIndex++) {
for (int topIndex = -1; topIndex < 2;
topIndex++) {
if ((leftIndex == 0) && (topIndex ==
0)) continue; // skip own
int neighbourRowIndex = row
+ leftIndex;
int neighbourColIndex = col
+ topIndex;
if (neighbourRowIndex<0)
neighbourRowIndex = originalBoard.length +
neighbourRowIndex;
if (neighbourColIndex<0)
neighbourColIndex = originalBoard[0].length +
neighbourColIndex ;
boolean neighbour
= originalBoard[neighbourRowIndex
% originalBoard.length][neighbourColIndex
% originalBoard[0].length];
Search WWH ::




Custom Search