-1, 1, -1, 0, 1];

        for (let i = 0; i < 8; i++) {
          const nx = x + dx[i];
          const ny = y + dy[i];

          if (nx >= 0 && nx < rows && ny >= 0 && ny < cols) {
            count += grid[nx][ny] ? 1 : 0;
          }
        }

        return count;
      }

      function updateGrid() {
        const newGrid = createEmptyGrid();

        for (let i = 0; i < rows; i++) {
          for (let j = 0; j < cols; j++) {
            const neighbors = countNeighbors(i, j);

