private int getAliveNeighbours(int x, int y)
  {
    int startX = x > 0 ? (x - 1) : 0,
        startY = y > 0 ? (y - 1) : 0,
        maxX = (x + 1) < width ? (x + 1) : width - 1,
        maxY = (y + 1) < height ? (y + 1) : height - 1,
        neighbours = 0;

    for (int i = startY; i <= maxY; i++)
    {
      for (int j = startX; j <= maxX; j++)
      {
        if (grid[i][j])
        {
          if (i != y || j != x)
            neighbours++;
        }
      }
    }

    return neighbours;
  }