赛车AI山地寻路


 寻路基本算法选择A*启发式搜索,但由于山地路不平,无法直接用平面网格,用unity自带的网格导航固然可以,但是还有一个选择,就是自己布点。将寻路网格当成双向有向图,采用有向图邻接表的数据结构存储路网。A*启发函数选择马哈顿距离(d = dx + dy)。代码如下:



//Use Graph to describe availue path for players or non-players

	//Graph Edge
	//Use index in array as id ,so there is no need to store start point
	public class AStarPathEdge {
		public AStarPoint2f endPoint; // End point
		public float distance;      // Distance between start point end end point,
									//which means this value stands for edge distance
		public override string ToString ()
		{
			return "endPointIndex:  " + endPoint.index + "  distane:  " + distance + "    ";
		}
	}
	
	public class AStarPoint2f {
		public float x;
		public float y;
		private IList edges = new ArrayList();  //All edges that start from this point
		public int index = 0;         //Index in array
		public float h = float.MaxValue;    //Distance between this point and end point
		public float g = float.MaxValue;    //Distance between this point and start point
		public float f = float.MaxValue;
		public AStarPoint2f father;//Record A Star path
		//Caculate Manhattan Distance
		public void caculateDestDistance(AStarPoint2f destPoint) {
			if(destPoint == this)
				h = 0;
			else 
				h = ManhattanDistance(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值