package testPackage;
import java.util.ArrayList;
public class Astar
{
public final static int WIDTH = 8; //地图长度,即行数
public final static int LENGTH = 8; //地图长度,即列数
public final static int STARTPOINTX = 2; //起点横坐标
public final static int STARTPOINTY = 1; //起点纵坐标
public final static int ENDPOINTX = 6; //终点横坐标
public final static int ENDPOINTY = 6; //终点纵坐标
public final static int OBSTACLEAMOUNT = 30; //障碍物数量,随机产生障碍物
public static void main(String[] args)
{
PointInfo[][] point = new PointInfo[WIDTH][LENGTH]; //声明对象数组/地图上的点
for(int i = 0;i < WIDTH;i++) //并为对象数组分配地址
{
for(int j = 0;j < LENGTH;j++)
{
point[i][j]=new PointInfo();
}
}
pointInit(point); //点初始化
setMap(point); //设置地图属性
if(astarAlgorithm(point)) //A-star算法求最短路径
{
System.out.println("路线总代价为:"+point[ENDPOINTX][ENDPOINTY].f);
System.out.println("路线为(从下向上看):");
pointPrint(point);
}
else
{
System.out.println("未找到路径");
pointPrint(point);
}
}
/**********设置地图属性,起点,终点,障碍物***********/
public static void setMap(PointInfo[][] point)
{
/***设置起点和终点的标记为true****/
point[STARTPOINTX][STARTPOINTY].isStartPoint = true;
point[ENDPOINTX][ENDPOINTY].isEndPoint = true;
/************************/
/******自己设定障碍物**************
point[1][5].isObstacle = true;
point[2][5].isObstacle = true;
point[3][5].isObstacle = true;
point[1][6].isObstacle = true;
point[3][6].isObstacle = true;
point[1][7].isObstacle = true;
point[2][7].isObstacle = true;
point[3][7].isObstacle = true;
/****************************/