src/GameOfLife/Scenes/Game/gameoflife.cpp
// we have maximum 8 neighbors, minimum 3:
//  1 2 3
//  4 x 5   or   x 5
//  6 7 8        7 8
we have maximum 8 neighbors, minimum 3:
1 2 3
4 x 5   or   x 5
6 7 8        7 8
we have maximum 8 neighbors minimum 3 : 1 2 3 4 x 5 or x 5 6 7 8 7 8
uint32_t GameOfLife::getAliveNeighbors(uint16_t x, uint16_t y) const noexcept {
  uint32_t alive = 0;
  if(x > 0 && y > 0 && cells[rowAndColToIndex(x - 1, y - 1)] == CellState::on) alive++;
  if(y > 0 && cells[rowAndColToIndex(x, y - 1)] == CellState::on) alive++;
  if(x < GameOfLife::WIDTH - 1 && y > 0 && cells[rowAndColToIndex(x + 1, y - 1)] == CellState::on) alive++;
  if(x > 0 && cells[rowAndColToIndex(x - 1, y)] == CellState::on) alive++;
  if(x < GameOfLife::WIDTH - 1 && cells[rowAndColToIndex(x + 1, y)] == CellState::on) alive++;
  if(x > 0 && y < GameOfLife::HEGHT - 1 && cells[rowAndColToIndex(x - 1, y + 1)] == CellState::on) alive++;
  if(y < GameOfLife::HEGHT - 1 && cells[rowAndColToIndex(x, y + 1)] == CellState::on) alive++;
  if(x < GameOfLife::WIDTH - 1 && y < GameOfLife::HEGHT && cells[rowAndColToIndex(x + 1, y + 1)] == CellState::on) alive++;
  return alive;
}
uint32_t GameOfLife :: getAliveNeighbors ( uint16_t x , uint16_t y ) const noexcept { uint32_t alive = 0 ; if ( x > 0 && y > 0 && cells [ rowAndColToIndex ( x - 1 , y - 1 ) ] == CellState :: on ) alive ++ ; if ( y > 0 && cells [ rowAndColToIndex ( x , y - 1 ) ] == CellState :: on ) alive ++ ; if ( x < GameOfLife :: WIDTH - 1 && y > 0 && cells [ rowAndColToIndex ( x + 1 , y - 1 ) ] == CellState :: on ) alive ++ ; if ( x > 0 && cells [ rowAndColToIndex ( x - 1 , y ) ] == CellState :: on ) alive ++ ; if ( x < GameOfLife :: WIDTH - 1 && cells [ rowAndColToIndex ( x + 1 , y ) ] == CellState :: on ) alive ++ ; if ( x > 0 && y < GameOfLife :: HEGHT - 1 && cells [ rowAndColToIndex ( x - 1 , y + 1 ) ] == CellState :: on ) alive ++ ; if ( y < GameOfLife :: HEGHT - 1 && cells [ rowAndColToIndex ( x , y + 1 ) ] == CellState :: on ) alive ++ ; if ( x < GameOfLife :: WIDTH - 1 && y < GameOfLife :: HEGHT && cells [ rowAndColToIndex ( x + 1 , y + 1 ) ] == CellState :: on ) alive ++ ; return alive ; }
we have maximum 8 neighbors, minimum 3:
1 2 3
4 x 5   or   x 5
6 7 8        7 8
we have maximum 8 neighbors minimum 3 : 1 2 3 4 x 5 or x 5 6 7 8 7 8
// 1 // 2 // 3 // 4 // 5 // 6 // 7 // 8