public class AStar
{
private List
private List
private int startX,startY,endX,endY;
public AStar(){
openList=new ArrayList
closeList=new ArrayList
}
public static void main(String[] args) {
int[][] map = new int[][] {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 }
};
Astar astar=new Astar();
astar.search(0,0, 5, 9);
}
public int search(int startX,int startY,int endX,int endY){
if((index=contain(openList,end.x,end.y))!=-1){//如果不等于-1就到终点
int count=-1;
Node nowNode=openList.get(index);
Node getNode=nowNode;//不太明白之处
while(getNode.father!=null)
{
getNode=getNode.father;
count++;
}
}
private int contain(List
Node node=null;
for(int i=0;i
node=nodes.get(i);
if(node.x==x&&node.y==y)
return i;
}
return -1;
}
public Node(int x,int y,Node father){
this.x=x;
this.y=y;
this.father=father;
}
}



