There is an array

private int[][]inColor=new int[6][6]; 

For convenience, I use only internal cells (that is, I do not fill the external cells with data). example

 0 0 0 0 0 0 1 2 3 0 0 2 1 1 0 0 3 2 1 0 0 0 0 0 0 

The method for the search takes the address of the selected element and must assign to zero neighboring elements with the same values ​​(as in bubble breaker).

Search method

  private void serch(int x,int y){ int cik=inColor[x][y]; if (x>0&x<6){ if (y>0&y<6){ if (inColor[x-1][y]==cik){ Log.d("oolo", "ravni " + inColor[x - 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; serch(x - 1, y); } if (inColor[x+1][y]==cik){ Log.d("oolo", "ravni " + inColor[x + 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; serch(x + 1, y); } if (inColor[x][y-1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y-1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; serch(x , y-1); } if (inColor[x][y+1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y+1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; serch(x , y+1); } } } print(); } 

UPD problem solved:

  private void serch(int x,int y,int cik){ if (x>0&x<6){ if (y>0&y<6){ if (inColor[x-1][y]==cik){ Log.d("oolo", "ravni " + inColor[x - 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x-1][y]=0; serch(x - 1, y,cik); } if (inColor[x+1][y]==cik){ Log.d("oolo", "ravni " + inColor[x + 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x+1][y]=0; serch(x + 1, y,cik); } if (inColor[x][y-1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y-1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x][y-1]=0; serch(x , y-1,cik); } if (inColor[x][y+1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y+1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x][y+1]=0; serch(x , y+1,cik); } } } print(); } 
  • The task is not clear. Describe it, what is specifically given, and what you need to get. - Vlad from Moscow
  • You bypass the same cells again and again. It is necessary to check whether this cell has already been processed or not. - Pavel Parshin
  • corrected, made a variable with the argument of argument, passed assigned 0, did not help ( - Max.
  • @ Maxim, if the problem is solved, then add the answer to your own question, you will get a sign - dirkgntly

1 answer 1

 private void serch(int x,int y,int cik){ if (x>0&x<6){ if (y>0&y<6){ if (inColor[x-1][y]==cik){ Log.d("oolo", "ravni " + inColor[x - 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x-1][y]=0; serch(x - 1, y,cik); } if (inColor[x+1][y]==cik){ Log.d("oolo", "ravni " + inColor[x + 1][y]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x+1][y]=0; serch(x + 1, y,cik); } if (inColor[x][y-1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y-1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x][y-1]=0; serch(x , y-1,cik); } if (inColor[x][y+1]==cik){ Log.d("oolo", "ravni " + inColor[x ][y+1]); Log.d("oolo", "ravni " + inColor[x][y]); inColor[x][y]=0; inColor[x][y+1]=0; serch(x , y+1,cik); } } } print(); }