public static int numNeighbours(Element element, World world) {
    if (element.xdim() > 4 || element.xdim() != element.ydim()) {
      I.complain("This method is intended only for small, regular elements.") ;
    }
    final int size = element.xdim() - 1 ;
    int numNeighbours = 0 ;
    final Element near[] = NEAR_ARRAYS[size] ;
    final Tile perim[] = (size == 0) ?
      element.origin().allAdjacent(PERIM_ARRAYS[0]) :
      Spacing.perimeter(element.area(tA), world) ;
    
    for (Tile t : perim) if (t != null) {
      final Element o = t.owner() ;
      if (o != null && o.flaggedWith() == null) {
        near[numNeighbours++] = o ;
        o.flagWith(element) ;
      }
    }
    
    for (int i = numNeighbours ; i-- > 0 ;) near[i].flagWith(null) ;
    return numNeighbours ;
  }