protected int lines(int i, int j){
      int c=(values[i][j] & LEFT)==LEFT?1:0;
      c+=(values[i][j] & TOP)==TOP?1:0;
      c+=(values[i][j] & RIGHT)==RIGHT?1:0;
      c+=(values[i][j] & BOTTOM)==BOTTOM?1:0;
      return c;
    }