private int neighborCount(int x, int y) {
    int count = 0;
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {

        int currentY = y + i;
        int currentX = x + j;

        if (currentX != x || currentY != y) {

          if (currentX >= 0 && currentX < field[0].length && currentY >= 0 && currentY < field.length) {
            if (field[currentY][currentX]) {
              count++;
            }
          }
        }
      }
    }
    return count;
  }