void Astar::starseach(int fid) { int col = ((AstarItem *)close->objectAtIndex(fid))->getcol(); int row = ((AstarItem *)close->objectAtIndex(fid))->getrow(); //搜索目前点的上下左右四个方向 int mycol = col; int myrow = row - 1; if(myrow >= 0 && checkmap(mycol,myrow)){ if(checkOpen(mycol,myrow,fid) && checkclose(mycol,myrow)){ addtoopen(mycol,myrow,fid); } } mycol = col - 1; myrow = row; if(mycol >= 0 && checkmap(mycol,myrow)){ if(checkOpen(mycol,myrow,fid) && checkclose(mycol,myrow)){ addtoopen(mycol,myrow,fid); } } mycol = col; myrow = row + 1; if(myrow < map->getMapSize().width && checkmap(mycol,myrow)){ if(checkOpen(mycol,myrow,fid) && checkclose(mycol,myrow)){ addtoopen(mycol,myrow,fid); } } mycol = col + 1; myrow = row; if(mycol < map->getMapSize().height && checkmap(mycol,myrow)){ if(checkOpen(mycol,myrow,fid) && checkclose(mycol,myrow)){ addtoopen(mycol,myrow,fid); } } }
void insertopen() { int aa; int flag=0; int p1[3][3]; int i,j; long int t=0; int ret=0; int checkclose(long int); for(i=0;i<3;i++) for(j=0;j<3;j++) p1[i][j]=mat[i][j]; if(a!=0) //up { aa=mat[a][b]; p1[a][b]=mat[a-1][b]; p1[a-1][b]=aa; flag=1; } if(flag==1) { t=0; for(i=0;i<3;i++) for(j=0;j<3;j++) t=(t*10)+p1[i][j]; ret=checkclose(t); if(ret==0) insertnode(p1); for(i=0;i<3;i++) for(j=0;j<3;j++) p1[i][j]=mat[i][j]; flag=0; } if(a!=2) //down { aa=mat[a][b]; p1[a][b]=mat[a+1][b]; p1[a+1][b]=aa; flag=1; } if(flag==1) { t=0; for(i=0;i<3;i++) for(j=0;j<3;j++) t=(t*10)+p1[i][j]; ret=checkclose(t); if(ret==0) insertnode(p1); t=0; for(i=0;i<3;i++) for(j=0;j<3;j++) p1[i][j]=mat[i][j]; flag=0; } if(b!=0) //left { aa=mat[a][b]; p1[a][b]=mat[a][b-1]; p1[a][b-1]=aa; flag=1; } if(flag==1) { t=0; for(i=0;i<3;i++) for(j=0;j<3;j++) t=(t*10)+p1[i][j]; ret=checkclose(t); if(ret==0) insertnode(p1); for(i=0;i<3;i++) for(j=0;j<3;j++) p1[i][j]=mat[i][j]; flag=0; } if(b!=2) //right { aa=mat[a][b]; p1[a][b]=mat[a][b+1]; p1[a][b+1]=aa; flag=1; } if(flag==1) { t=0; for(i=0;i<3;i++) for(j=0;j<3;j++) t=(t*10)+p1[i][j]; ret=checkclose(t); if(ret==0) insertnode(p1); for(i=0;i<3;i++) for(j=0;j<3;j++) p1[i][j]=mat[i][j]; flag=0; } }