Skip to content

Instantly share code, notes, and snippets.

@Chris--B
Created January 5, 2014 04:18
Show Gist options
  • Save Chris--B/8264275 to your computer and use it in GitHub Desktop.
Save Chris--B/8264275 to your computer and use it in GitHub Desktop.
int Board::countLivingNeighbors(const Cell& cell) const {
auto living = 0;
if (isAlive(Cell(cell.x - 1, cell.y))) { ++living; }
if (isAlive(Cell(cell.x - 1, cell.y - 1))) { ++living; }
if (isAlive(Cell(cell.x - 1, cell.y + 1))) { ++living; }
if (isAlive(Cell(cell.x, cell.y - 1))) { ++living; }
if (isAlive(Cell(cell.x, cell.y + 1))) { ++living; }
if (isAlive(Cell(cell.x + 1, cell.y))) { ++living; }
if (isAlive(Cell(cell.x + 1, cell.y - 1))) { ++living; }
if (isAlive(Cell(cell.x + 1, cell.y + 1))) { ++living; }
return living;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment