לבסוף שיפרתי את האלגוריתם שלי ועכשיו אני אפרסם למעוניינים...
רציתי לבקש ממך אם אתה יכול בבקשה לפרסם את האלגוריתם A* שבנית למערך תאים.
להלן הקוד המתוקן שלי :
public boolean check_wallsb (int mat[][],int x, int y, int m)
{
int win=9,i,j;
/* for (i=0;i<19;i++)
{
for (j=0;j<18;j++)
System.out.print(mat[i][j]);
System.out.println(mat[i][j]);
}*/
//JOptionPane.showMessageDialog(null,x);
//JOptionPane.showMessageDialog(null,y);
// JOptionPane.showMessageDialog(null,"->");
// currentB.setData(x*50+8,y*50+8,25,25);
// repaint();
if (m==0)
{
// JOptionPane.showMessageDialog(null,"check1");
return false;
}
else
{
if ((y+1==win) && (mat[y*2][x*2-1]==2))
return true;
if ((mat[y*2][x*2-1]==2) && (mat[y*2-2][x*2-1]==2))
{
mat[y*2-2][x*2-1]=0;
mat[y*2][x*2-1]=0;
mat[y*2-1][x*2]=0;
mat[y*2-1][x*2-2]=0;
if (check_wallsb(mat,x,y-1,m-1) || check_wallsb(mat,x,y+1,m-1))
return true;
}
else
if (mat[y*2][x*2-1]==2)
{
if (check_wallsb(mat,x,y+1,m-1))
return true;
}
else
if ((mat[y*2-1][x*2]==2) && (mat[y*2-1][x*2-2]==2))
{
mat[y*2-2][x*2-1]=0;
mat[y*2][x*2-1]=0;
mat[y*2-1][x*2]=0;
mat[y*2-1][x*2-2]=0;
if (check_wallsb(mat,x+1,y,m-1) || check_wallsb(mat,x-1,y,m-1))
return true;
}
else
//
if ((mat[y*2-1][x*2]==2) && (mat[y*2-2][x*2-1]==2))
{
//JOptionPane.showMessageDialog(null,"right");
mat[y*2-2][x*2-1]=0;
mat[y*2][x*2-1]=0;
mat[y*2-1][x*2]=0;
mat[y*2-1][x*2-2]=0;
if (check_wallsb(mat,x+1,y,m-1) || check_wallsb(mat,x,y-1,m-1))
return true;
}
else
if ((mat[y*2-1][x*2-2]==2) && (mat[y*2-2][x*2-1]==2))
{
//JOptionPane.showMessageDialog(null,"left");
mat[y*2-2][x*2-1]=0;
mat[y*2][x*2-1]=0;
mat[y*2-1][x*2]=0;
mat[y*2-1][x*2-2]=0;
if (check_wallsb(mat,x-1,y,m-1) || check_wallsb(mat,x,y-1,m-1))
return true;
}
else
//
if (mat[y*2-1][x*2]==2)
{
if (check_wallsb(mat,x+1,y,m-1))
return true;
}
else
if (mat[y*2-1][x*2-2]==2)
{
if (check_wallsb(mat,x-1,y,m-1))
return true;
}
else
if (mat[y*2-2][x*2-1]==2)
{
mat[y*2-2][x*2-1]=0;
mat[y*2][x*2-1]=0;
mat[y*2-1][x*2]=0;
mat[y*2-1][x*2-2]=0;
if (check_wallsb(mat,x,y-1,m-1))
return true;
}
// JOptionPane.showMessageDialog(null,"check2");
return false;
}
}